J Robert Ray
2014-08-09 02:04:31 UTC
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!
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!