pylibfdt: Proper handling of bytes/unicode strings and octal literals

Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Message-Id: <20190218164856.23861-1-frenzy@frenzy.cz>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Lumir Balhar
2019-02-18 17:48:52 +01:00
committed by David Gibson
parent 78e113e81c
commit 4b68c6b360
2 changed files with 21 additions and 13 deletions

View File

@@ -669,7 +669,7 @@ class Fdt(FdtRo):
Raises:
FdtException if no parent found or other error occurs
"""
val = val.encode('utf-8') + '\0'
val = val.encode('utf-8') + b'\0'
return check_err(fdt_setprop(self._fdt, nodeoffset, prop_name,
val, len(val)), quiet)
@@ -1074,12 +1074,20 @@ typedef uint32_t fdt32_t;
if (!$1)
$result = Py_None;
else
$result = Py_BuildValue("s#", $1, *arg4);
%#if PY_VERSION_HEX >= 0x03000000
$result = Py_BuildValue("y#", $1, *arg4);
%#else
$result = Py_BuildValue("s#", $1, *arg4);
%#endif
}
/* typemap used for fdt_setprop() */
%typemap(in) (const void *val) {
$1 = PyString_AsString($input); /* char *str */
%#if PY_VERSION_HEX >= 0x03000000
$1 = PyBytes_AsString($input);
%#else
$1 = PyString_AsString($input); /* char *str */
%#endif
}
/* typemaps used for fdt_next_node() */