[Cython] Accessing the internals of a Python long
Robert Bradshaw
robertwb at math.washington.edu
Fri Aug 22 10:19:37 CEST 2008
On Aug 2, 2008, at 7:53 PM, Case Vanhorsen wrote:
> I am trying to access the internal structure of a Python long. The
> code fragment below works when I use Pyrex 0.9.8.4 but generates a
> compile error when using Cython 0.9.8.
>
> Is there a better way to access the internals of a Python long?
>
> What is causing the cimport error and how can I fix it?
FYI, this has been resolved. The problem is whether to interpret a.b
as a cimported type (from the module a) or an attribute. This
decision is made at parsing, and Pyrex assumed one way and Cython the
other. I've made it accept both.
>
>
> Thanks,
>
> casevh
>
> ------------------------------
> ------------------------
>
> The code:
>
> cdef extern from "Python.h":
> ctypedef struct PyTypeObject:
> pass
> ctypedef struct PyObject:
> Py_ssize_t ob_refcnt
> PyTypeObject * ob_type
> cdef extern from "longintrepr.h":
> cdef struct _longobject:
> int ob_refcnt
> PyTypeObject * ob_type
> int ob_size
> unsigned int * ob_digit
> def test(temp = long(0)):
> cdef _longobject *l
> l = <_longobject *> temp
> print sizeof(l.ob_size)
> print sizeof(l.ob_digit[0])
>
> The error:
>
> Error converting Pyrex file to C:
> ------------------------------------------------------------
> ...
> int ob_size
> unsigned int * ob_digit
> def test(temp = long(0)):
> cdef _longobject *l
> l = <_longobject *> temp
> print sizeof(l.ob_size)
> ^
> ------------------------------------------------------------
>
> /home/case/code/cvh.pyx:16:18: 'cvh.test' is not a cimported module
> _______________________________________________
> Cython-dev mailing list
> Cython-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/cython-dev
More information about the Cython-dev
mailing list