Daniele Pianu wrote:
> The function is a cdef extension type's method. Here the part of the
> implementation which raises the exceptions:
>
> cdef void *getItem( self, int i ) except NULL:
> cdef void* tmpPtr
>
> # Check NULL pointer
> if self.rawPtr == NULL:
> raise ValueError( "Null pointer" )
> # Check specified index
> if i < 0:
> raise IndexError( "Unvalid index" )
> # Bound checking
> if self._layout[0] > 0 and i >= self._layout[0]:
> raise IndexError( "Index out of bounds" )
>
> # Code used for get the i-th value
> .......
>
> self.rawPtr is the void pointer stored by the extension type.
> self._layout is a simple tuple which defines the "shape" of
> self.rawPtr, used for bounds checking. The function is called by other
> extension types which extend the extension type which defines the
> getItem method. What do you main with "The "except NULL" is for
> propagating within-Cython exceptions"? Do I need to put the getItem
> call in a try-except block in the cython caller?
>
I don't think what I said applies in your case. I'm still a bit
confused, as "self" was typed as "void*" in your original example, while
here getitem seems to be part of a class.
Here's a minimal testcase, which seems to work OK for me. Can you please
modify it until it explains your situation?
Dag Sverre
"""
>>> f()
Traceback (most recent call last):
...
ValueError: foo
"""
cdef class A:
cdef void* ptr
def __init__(self):
self.ptr = NULL
cdef void* getitem(self) except NULL:
if self.ptr is NULL:
raise ValueError("foo")
def f():
cdef A a = A()
print a.getitem() == NULL
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev