[Pyrex] access to c data class members

ahalda at cs.mcgill.ca ahalda at cs.mcgill.ca
Sun Aug 27 22:49:29 UTC 2006


On Sun, August 27, 2006 4:51 pm, Daniele Varrazzo wrote:
> You can declare newObj being of the exact class you expect:
>
> def load_File():
>     cdef MyClass newObj
>     newObj = MyClass()
>     newObj.data = getData()
>     return newObj
>
> so newObj is C-typed and you can access its C members.

Thanks! That solves my precise problem.

So, the solution is to do BOTH strategies at once, on the same name:
Define it a C-object, and then *also* as a python object. (at least
semantically.. I haven't looked at the C output) I was only trying
one of those at a time, so I never got it working.

Maybe that should go in the language definition page in the 'tricks'
section. It is a little non-intuitive (but seems logical once you see it).

Allan

(oh, and I made a typo in my last email.. 'cdef Module newObj' should be
'cdef MyClass newObj' ..I had renamed it for clarity)




More information about the Pyrex mailing list