[Cython] Bug: operator[] does not respect except +

J Robert Ray jrobertray at gmail.com
Sat Sep 6 01:05:01 CEST 2014


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 at 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!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20140905/e6dc1f26/attachment.html>


More information about the cython-devel mailing list