[Pyrex] Getting address of ob_type
Nicholas Riley
njriley at uiuc.edu
Fri Dec 29 17:37:39 UTC 2006
Hi,
I'm attempting to get the address of the ob_type field of a Python
object from Pyrex. I tried the following:
cdef extern from "object.h":
ctypedef struct PyTypeObject:
char *tp_name
ctypedef class __builtin__.object [object PyObject]:
cdef PyTypeObject *ob_type
cdef unsigned long type_addr(object object_):
return <unsigned long>&object_.ob_type
but I get back:
/home/dcsfiles/njriley/Python/UFO/pyUFO.pyx:215:26: Cannot take
address of Python variable
I've done something similar with a dict object, but I think the
problem is that "object" in the cdef is being interpreted as a
generic Python object (which it is, but...). I also tried:
ctypedef class __builtin__.object as obj [object PyObject]:
and
ctypedef class __builtin__.object [object PyObject] as obj:
which look like they should fix it, but they don't work at all.
Any ideas on how I can do this?
--Nicholas
More information about the Pyrex
mailing list