[Pyrex] Type conversion to arguments for a C method

Lenard Lindstrom len-l at telus.net
Mon Oct 17 23:52:00 CEST 2005


Use 'def' instead of 'cdef' for special methods of extension types.

This posting is closely related to one I was going to make, so I will bring it up here. 
Declaring __init__ as 'cdef' instead of 'def' prevents Pyrex from making it a proper 
extention type init function. Instead the C function is used as is. The arguments are 
not converted as described for a Pyrex __init__ .

The same thing is happening to __getitem__. Pyrex is using the C function given, 
unchanged. The first delcaration is correct for a C subscipt mapping method, and 
works. The second is wrong, so 'i' gives the address of the integer python object 
instead of the object itself.

So I am wondering if this is an undocumented feature of Pyrex, or an unintensional 
one?

Lenard Lindstrom
<len-l at telus.net>

On 17 Oct 2005 at 11:44, Michael Hordijk wrote:

> Alrighty,
> 	Continuing with my project now that things don't segfault on __init__, 
> I think I've run into a missing type conversion.  Exawple through code 
> is probably easiest.
> 
> [[[
> cdef class test(ListType):
>      cdef __getitem__(self, i):
>          cdef int j
>          j = i
>          print j
>          return None
> ]]]
> 
> yields:
> 
> [[[
>  >>> import testMod
>  >>> a = testMod.test()
>  >>> a[0]
> 0
> ]]]
> 
> So far so good.  Now:
> 
> [[[
> cdef class test(ListType):
>      cdef __getitem__(self, int i):
>          print i
>          return None
> ]]]
> 
> yields:
> 
> [[[
>  >>> import testMod
>  >>> a = testMod.test()
>  >>> a[0]
> 134537076
> ]]]
> 
> Huh.  I couldn't find anything in the documentation that said this type 
> conversion would not automatically happen.  Did I miss something?




More information about the Pyrex mailing list