From: Lisandro Dalcin Date: Thu, 7 Apr 2011 22:25:45 +0000 (-0300) Subject: PEP 3118: fix for NULL Py_buffer arg X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dd3da6c283a0750c9c6514991be719ac064e79b4;p=cython.git PEP 3118: fix for NULL Py_buffer arg --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b8f94cee..280dc926 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1623,20 +1623,24 @@ class FuncDefNode(StatNode, BlockNode): info = self.local_scope.arg_entries[1].cname # Python 3.0 betas have a bug in memoryview which makes it call # getbuffer with a NULL parameter. For now we work around this; - # the following line should be removed when this bug is fixed. - code.putln("if (%s == NULL) return 0;" % info) + # the following block should be removed when this bug is fixed. + code.putln("if (%s != NULL) {" % info) code.putln("%s->obj = Py_None; __Pyx_INCREF(Py_None);" % info) code.put_giveref("%s->obj" % info) # Do not refnanny object within structs + code.putln("}") def getbuffer_error_cleanup(self, code): info = self.local_scope.arg_entries[1].cname + code.putln("if (%s != NULL && %s->obj != NULL) {" + % (info, info)) code.put_gotref("%s->obj" % info) - code.putln("__Pyx_DECREF(%s->obj); %s->obj = NULL;" % - (info, info)) + code.putln("__Pyx_DECREF(%s->obj); %s->obj = NULL;" + % (info, info)) + code.putln("}") def getbuffer_normal_cleanup(self, code): info = self.local_scope.arg_entries[1].cname - code.putln("if (%s->obj == Py_None) {" % info) + code.putln("if (%s != NULL && %s->obj == Py_None) {" % (info, info)) code.put_gotref("Py_None") code.putln("__Pyx_DECREF(Py_None); %s->obj = NULL;" % info) code.putln("}") diff --git a/Cython/Includes/numpy.pxd b/Cython/Includes/numpy.pxd index 7ddd00ba..6b36670a 100644 --- a/Cython/Includes/numpy.pxd +++ b/Cython/Includes/numpy.pxd @@ -190,6 +190,9 @@ cdef extern from "numpy/arrayobject.h": # requirements, and does not yet fullfill the PEP. # In particular strided access is always provided regardless # of flags + + if info == NULL: return + cdef int copy_shape, i, ndim cdef int endian_detector = 1 cdef bint little_endian = ((&endian_detector)[0] != 0)