Commit cf2bbce5 authored by Stefan Behnel's avatar Stefan Behnel

Improve error handling in "cython.array" creation code to avoid calling...

Improve error handling in "cython.array" creation code to avoid calling Py_BuildValue() with an exception set if "__pyx_format_from_typeinfo()" failed.
parent 125cf1d1
...@@ -13,6 +13,9 @@ Bugs fixed ...@@ -13,6 +13,9 @@ Bugs fixed
* Error handling early in the module init code could lead to a crash. * Error handling early in the module init code could lead to a crash.
* Error handling in ``cython.array`` creation was improved to avoid calling
C-API functions with and error held.
* Complex buffer item types of structs of arrays could fail to validate. * Complex buffer item types of structs of arrays could fail to validate.
Patch by Leo and smutch. (Github issue #1407) Patch by Leo and smutch. (Github issue #1407)
......
...@@ -10697,17 +10697,20 @@ class CythonArrayNode(ExprNode): ...@@ -10697,17 +10697,20 @@ class CythonArrayNode(ExprNode):
code.putln(code.error_goto(self.operand.pos)) code.putln(code.error_goto(self.operand.pos))
code.putln("}") code.putln("}")
code.putln("%s = __pyx_format_from_typeinfo(&%s);" % code.putln("%s = __pyx_format_from_typeinfo(&%s); %s" % (
(format_temp, type_info)) format_temp,
buildvalue_fmt = " __PYX_BUILD_PY_SSIZE_T " * len(shapes) type_info,
code.putln('%s = Py_BuildValue((char*) "(" %s ")", %s);' % ( code.error_goto_if_null(format_temp, self.pos),
shapes_temp, buildvalue_fmt, ", ".join(shapes))) ))
err = "!%s || !%s || !PyBytes_AsString(%s)" % (format_temp,
shapes_temp,
format_temp)
code.putln(code.error_goto_if(err, self.pos))
code.put_gotref(format_temp) code.put_gotref(format_temp)
buildvalue_fmt = " __PYX_BUILD_PY_SSIZE_T " * len(shapes)
code.putln('%s = Py_BuildValue((char*) "(" %s ")", %s); %s' % (
shapes_temp,
buildvalue_fmt,
", ".join(shapes),
code.error_goto_if_null(shapes_temp, self.pos),
))
code.put_gotref(shapes_temp) code.put_gotref(shapes_temp)
tup = (self.result(), shapes_temp, itemsize, format_temp, tup = (self.result(), shapes_temp, itemsize, format_temp,
......
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