[Pyrex] Assign C object to a cdeffed variable of a class

Lenard Lindstrom len-l at telus.net
Sun Sep 9 18:53:03 CEST 2007


Stefano Esposito wrote:
> On Sat, 08 Sep 2007 10:05:44 -0700
> Lenard Lindstrom <len-l at telus.net> wrote:
>
> [snip]
>   
>> But why? Is it not more sensible for package_new_from_file to return a 
>> Package object?
>>     
>
> Indeed i was returning the pypkg, but i haven't showed it on the list 'cause it was after the error :)
>
>   
>> def package_new_from_file(filename):
>>     cdef Package pypkg
>>     cdef pmpkg_t *pkg
>>     alpm_pkg_load(filename, &pkg)
>>     pypkg = Package()
>>     pypkg.pkg = pkg
>>     return package
>>     
>
> This worked, thanks :)
>
>   
>> Better still, if alpm_pkg_load is the only way to create a pmpkp_t then 
>> call it from the Package constructor.
>>     
>
> Nope, it's not the only way.
>
> Thanks for the help, anyway... could you point me to a link which explains what is the exact meaning of cdeffing a pyrex defined class? :)
>
>   

I cannot find documentation on Pyrex class variables. So here are the 
specifics. A cdeffed Pyrex class is an extension type. A cdef variable 
that is an extension type allows access to the extension type's 
attributes and C methods. A module level cdeffed variable is invisible 
to Python programs. A Python exception is raised if an object of the 
wrong class is  assigned to the variable. The self argument of and 
extension type method has an implicitly extension type declaration.

Hope this helps.

Lenard




More information about the Pyrex mailing list