Commit ee471d52 authored by Stefan Behnel's avatar Stefan Behnel

fix: make sure PyUnicode_READY() is called before unicode iteration

parent 04ff4ecc
...@@ -283,14 +283,20 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -283,14 +283,20 @@ class IterationTransform(Visitor.VisitorTransform):
), ),
reversed = reversed)) reversed = reversed))
PyUnicode_READY_func_type = PyrexTypes.CFuncType(
PyrexTypes.c_int_type, [
PyrexTypes.CFuncTypeArg("s", PyrexTypes.py_object_type, None)
],
exception_value='-1')
PyUnicode_GET_LENGTH_func_type = PyrexTypes.CFuncType( PyUnicode_GET_LENGTH_func_type = PyrexTypes.CFuncType(
PyrexTypes.c_py_ssize_t_type, [ PyrexTypes.c_py_ssize_t_type, [
PyrexTypes.CFuncTypeArg("s", Builtin.unicode_type, None) PyrexTypes.CFuncTypeArg("s", PyrexTypes.py_object_type, None)
]) ])
PyUnicode_KIND_func_type = PyrexTypes.CFuncType( PyUnicode_KIND_func_type = PyrexTypes.CFuncType(
PyrexTypes.c_int_type, [ PyrexTypes.c_int_type, [
PyrexTypes.CFuncTypeArg("s", Builtin.unicode_type, None) PyrexTypes.CFuncTypeArg("s", PyrexTypes.py_object_type, None)
]) ])
PyUnicode_READ_func_type = PyrexTypes.CFuncType( PyUnicode_READ_func_type = PyrexTypes.CFuncType(
...@@ -302,7 +308,7 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -302,7 +308,7 @@ class IterationTransform(Visitor.VisitorTransform):
PyUnicode_DATA_func_type = PyrexTypes.CFuncType( PyUnicode_DATA_func_type = PyrexTypes.CFuncType(
PyrexTypes.c_void_ptr_type, [ PyrexTypes.c_void_ptr_type, [
PyrexTypes.CFuncTypeArg("s", Builtin.unicode_type, None) PyrexTypes.CFuncTypeArg("s", PyrexTypes.py_object_type, None)
]) ])
def _transform_unicode_iteration(self, node, slice_node, reversed=False): def _transform_unicode_iteration(self, node, slice_node, reversed=False):
...@@ -349,7 +355,7 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -349,7 +355,7 @@ class IterationTransform(Visitor.VisitorTransform):
slice_node.pos, "__Pyx_PyUnicode_READ", slice_node.pos, "__Pyx_PyUnicode_READ",
self.PyUnicode_READ_func_type, self.PyUnicode_READ_func_type,
args = [kind_temp, data_temp, counter_temp], args = [kind_temp, data_temp, counter_temp],
is_temp = 0, is_temp = False,
)) ))
body = Nodes.StatListNode( body = Nodes.StatListNode(
node.pos, node.pos,
...@@ -366,9 +372,21 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -366,9 +372,21 @@ class IterationTransform(Visitor.VisitorTransform):
loop_node = UtilNodes.TempsBlockNode( loop_node = UtilNodes.TempsBlockNode(
node.pos, temps=[counter], body=loop_node) node.pos, temps=[counter], body=loop_node)
for temp in (kind_temp, data_temp, unpack_temp_node): # last is outermost temp for temp in (kind_temp, data_temp):
loop_node = UtilNodes.LetNode(temp, loop_node) loop_node = UtilNodes.LetNode(temp, loop_node)
return loop_node
setup_node = Nodes.ExprStatNode(
node.pos,
expr = ExprNodes.PythonCapiCallNode(
slice_node.pos, "__Pyx_PyUnicode_READY",
self.PyUnicode_READY_func_type,
args = [unpack_temp_node],
is_temp = True,
result_is_used = False,
))
return UtilNodes.LetNode(
unpack_temp_node,
Nodes.StatListNode(node.pos, stats=[setup_node, loop_node]))
def _transform_carray_iteration(self, node, slice_node, reversed=False): def _transform_carray_iteration(self, node, slice_node, reversed=False):
neg_step = False neg_step = False
......
...@@ -119,6 +119,7 @@ ...@@ -119,6 +119,7 @@
/* new Py3.3 unicode type (PEP 393) */ /* new Py3.3 unicode type (PEP 393) */
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) #if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
#define CYTHON_PEP393_ENABLED 1 #define CYTHON_PEP393_ENABLED 1
#define __Pyx_PyUnicode_READY(u) PyUnicode_READY(u)
#define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u) #define __Pyx_PyUnicode_KIND(u) PyUnicode_KIND(u)
#define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u)
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u)
...@@ -126,6 +127,7 @@ ...@@ -126,6 +127,7 @@
#define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i)
#else #else
#define CYTHON_PEP393_ENABLED 0 #define CYTHON_PEP393_ENABLED 0
#define __Pyx_PyUnicode_READY(u) (0)
#define __Pyx_PyUnicode_KIND(u) (0) /* PyUnicode_WCHAR_KIND */ #define __Pyx_PyUnicode_KIND(u) (0) /* PyUnicode_WCHAR_KIND */
#define __Pyx_PyUnicode_DATA(u) PyUnicode_AS_UNICODE(u) #define __Pyx_PyUnicode_DATA(u) PyUnicode_AS_UNICODE(u)
#define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u)
......
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