diff options
Diffstat (limited to 'cython')
| -rw-r--r-- | cython/plist.pyx | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/cython/plist.pyx b/cython/plist.pyx index e08d76a..99b344c 100644 --- a/cython/plist.pyx +++ b/cython/plist.pyx | |||
| @@ -4,13 +4,7 @@ from libc.stdint cimport * | |||
| 4 | 4 | ||
| 5 | # https://groups.google.com/forum/#!topic/cython-users/xoKNFTRagvk | 5 | # https://groups.google.com/forum/#!topic/cython-users/xoKNFTRagvk |
| 6 | cdef _from_string_and_size(char *s, size_t length): | 6 | cdef _from_string_and_size(char *s, size_t length): |
| 7 | if PY_MAJOR_VERSION < 3 or s == NULL: | 7 | return s[:length].encode('utf-8') |
| 8 | return s[:length] | ||
| 9 | |||
| 10 | if s == NULL: | ||
| 11 | return s[:length] | ||
| 12 | else: | ||
| 13 | return s[:length].decode("ascii") | ||
| 14 | 8 | ||
| 15 | cdef extern from *: | 9 | cdef extern from *: |
| 16 | ctypedef enum plist_type: | 10 | ctypedef enum plist_type: |
| @@ -606,7 +600,12 @@ cdef class Dict(Node): | |||
| 606 | plist_dict_next_item(self._c_node, it, &key, &subnode); | 600 | plist_dict_next_item(self._c_node, it, &key, &subnode); |
| 607 | 601 | ||
| 608 | while subnode is not NULL: | 602 | while subnode is not NULL: |
| 609 | cpython.PyDict_SetItem(self._map, key, plist_t_to_node(subnode, False)) | 603 | py_key = key |
| 604 | |||
| 605 | if PY_MAJOR_VERSION >= 3: | ||
| 606 | py_key = py_key.decode('utf-8') | ||
| 607 | |||
| 608 | cpython.PyDict_SetItem(self._map, py_key, plist_t_to_node(subnode, False)) | ||
| 610 | subnode = NULL | 609 | subnode = NULL |
| 611 | libc.stdlib.free(key) | 610 | libc.stdlib.free(key) |
| 612 | key = NULL | 611 | key = NULL |
