Bug: operator[] does not respect except +
I apologize for not having a working demonstration, but I have found this bug and verified it is still an issue in Cython 0.20.2. No try/catch block is generated for operator[]. In contrast, a try/catch block does get generated for operator(). If it is any use, here is a paraphrasing of the pyx code and the generated cpp code. cdef extern from "blah.h" namespace "blah": cdef cppclass Blah: int operator[](int) except + ... cdef class PyBlah: ... def demo(self, int index): return deref(self.thisptr)[index] ... /* "Blah.pyx":107 * def demo(self, int index): * return deref(self.thisptr)[index] # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(((*__pyx_v_self->thisptr)[__pyx_v_index])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; Please let me know if I'm doing anything wrong. Thanks!
I looked into at least adding a unit test to verify "except +" behavior for all operators and I found that aside from operator(), it seems that all operators ignore "except +". I have C++ code that can throw exceptions inside operator[] and sadly this ends up causing the python interpreter to abort. On Fri, Aug 8, 2014 at 7:04 PM, J Robert Ray <jrobertray@gmail.com> wrote:
I apologize for not having a working demonstration, but I have found this bug and verified it is still an issue in Cython 0.20.2. No try/catch block is generated for operator[]. In contrast, a try/catch block does get generated for operator().
If it is any use, here is a paraphrasing of the pyx code and the generated cpp code.
cdef extern from "blah.h" namespace "blah": cdef cppclass Blah: int operator[](int) except +
...
cdef class PyBlah: ... def demo(self, int index): return deref(self.thisptr)[index]
...
/* "Blah.pyx":107 * def demo(self, int index): * return deref(self.thisptr)[index] # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(((*__pyx_v_self->thisptr)[__pyx_v_index])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
Please let me know if I'm doing anything wrong. Thanks!
Yes, this is a bug. On Fri, Sep 5, 2014 at 4:05 PM, J Robert Ray <jrobertray@gmail.com> wrote:
I looked into at least adding a unit test to verify "except +" behavior for all operators and I found that aside from operator(), it seems that all operators ignore "except +".
I have C++ code that can throw exceptions inside operator[] and sadly this ends up causing the python interpreter to abort.
On Fri, Aug 8, 2014 at 7:04 PM, J Robert Ray <jrobertray@gmail.com> wrote:
I apologize for not having a working demonstration, but I have found this bug and verified it is still an issue in Cython 0.20.2. No try/catch block is generated for operator[]. In contrast, a try/catch block does get generated for operator().
If it is any use, here is a paraphrasing of the pyx code and the generated cpp code.
cdef extern from "blah.h" namespace "blah": cdef cppclass Blah: int operator[](int) except +
...
cdef class PyBlah: ... def demo(self, int index): return deref(self.thisptr)[index]
...
/* "Blah.pyx":107 * def demo(self, int index): * return deref(self.thisptr)[index] # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_int(((*__pyx_v_self->thisptr)[__pyx_v_index])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
Please let me know if I'm doing anything wrong. Thanks!
_______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel
participants (2)
-
J Robert Ray -
Robert Bradshaw