[Pyrex] bug if exception is being generated in pyrex constructor

Gustavo Sverzut Barbieri barbieri at gmail.com
Wed May 2 16:29:59 UTC 2007


Attached is a test case that shows pyrex generated extension type
segfaulting if it inherits from a class that raised an exception in
its constructor.

cdef class A:
    def __new__(self):
        raise Exception("crash-me")

cdef class B(A):
    def __new__(self):
        print "hello world"

creating B() segfaults because generated code has:

static PyObject *__pyx_tp_new_5myext_B(PyTypeObject *t, PyObject *a,
PyObject *k) {
  PyObject *o = __pyx_ptype_5myext_A->tp_new(t, a, k);
  if (__pyx_f_5myext_1B___new__(o, a, k) < 0) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

then it segfaults because inside __pyx_f_5myext_1B___new__() it access
"o", now NULL.

I've got to found this after Greg replied to my last mail. I got this
same error, but thought it had something to do with not using "public"
or things like that. But after Greg said the correct way was that, I
started debugging and found this was the problem... in my binding test
case I was giving the class an invalid type, raising and exception and
causing the segfault! :-)

-- 
Gustavo Sverzut Barbieri
--------------------------------------
Jabber: barbieri at gmail.com
   MSN: barbieri at gmail.com
  ICQ#: 17249123
 Skype: gsbarbieri
Mobile: +55 (81) 9927 0010
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyrex-crash-on-exception.zip
Type: application/zip
Size: 4946 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20070502/4ad31a32/attachment.zip 


More information about the Pyrex mailing list