Commit 7060250b authored by Martin Szulecki's avatar Martin Szulecki

cython: Fix broken String plist handling in Python

parent d01bdae2
...@@ -283,8 +283,8 @@ cdef class String(Node): ...@@ -283,8 +283,8 @@ cdef class String(Node):
if isinstance(value, unicode): if isinstance(value, unicode):
utf8_data = value.encode('utf-8') utf8_data = value.encode('utf-8')
elif (PY_MAJOR_VERSION < 3) and isinstance(value, str): elif (PY_MAJOR_VERSION < 3) and isinstance(value, str):
value.decode('ascii') # trial decode value.encode('ascii') # trial decode
utf8_data = value.decode('ascii') utf8_data = value.encode('ascii')
else: else:
raise ValueError("Requires unicode input, got %s" % type(value)) raise ValueError("Requires unicode input, got %s" % type(value))
c_utf8_data = utf8_data c_utf8_data = utf8_data
...@@ -319,8 +319,8 @@ cdef class String(Node): ...@@ -319,8 +319,8 @@ cdef class String(Node):
if isinstance(value, unicode): if isinstance(value, unicode):
utf8_data = value.encode('utf-8') utf8_data = value.encode('utf-8')
elif (PY_MAJOR_VERSION < 3) and isinstance(value, str): elif (PY_MAJOR_VERSION < 3) and isinstance(value, str):
value.decode('ascii') # trial decode value.encode('ascii') # trial decode
utf8_data = value.decode('ascii') utf8_data = value.encode('ascii')
else: else:
raise ValueError("Requires unicode input, got %s" % type(value)) raise ValueError("Requires unicode input, got %s" % type(value))
c_utf8_data = utf8_data c_utf8_data = utf8_data
...@@ -331,7 +331,7 @@ cdef class String(Node): ...@@ -331,7 +331,7 @@ cdef class String(Node):
char* c_value = NULL char* c_value = NULL
plist_get_string_val(self._c_node, &c_value) plist_get_string_val(self._c_node, &c_value)
try: try:
return cpython.PyUnicode_DecodeUTF8(c_value, libc.stdlib.strlen(c_value), 'strict') return cpython.PyUnicode_DecodeUTF8(c_value, len(c_value), 'strict')
finally: finally:
libc.stdlib.free(c_value) libc.stdlib.free(c_value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment