<div dir="ltr">I am trying to access the internal structure of a Python long. The code fragment below works when I use Pyrex <a href="http://0.9.8.4/" target="_blank">0.9.8.4</a> but generates a compile error when using Cython <a href="http://0.9.8./" target="_blank">0.9.8.</a> <br>
<br>Is there a better way to access the internals of a Python long?<br><br>What is causing the cimport error and how can I fix it?<br><br>Thanks,<br><br>casevh<br><br>------------------------------<div dir="ltr">------------------------ <br>
<br>The code:<br><br> cdef extern from "Python.h":
<br> ctypedef struct PyTypeObject:
<br> pass
<br> ctypedef struct PyObject:
<br> Py_ssize_t ob_refcnt
<br> PyTypeObject * ob_type
<br>cdef extern from "longintrepr.h":
<br> cdef struct _longobject:
<br> int ob_refcnt
<br> PyTypeObject * ob_type
<br> int ob_size
<br> unsigned int * ob_digit
<br>def test(temp = long(0)):
<br> cdef _longobject *l
<br> l = <_longobject *> temp
<br> print sizeof(l.ob_size)
<br> print sizeof(l.ob_digit[0])
<br><br>The error:<br><br>Error converting Pyrex file to C:<br>------------------------------------------------------------<br>...<br> int ob_size<br> unsigned int * ob_digit<br>def test(temp = long(0)):<br>
cdef _longobject *l<br> l = <_longobject *> temp<br> print sizeof(l.ob_size)<br> ^<br>------------------------------------------------------------<br><br>/home/case/code/cvh.pyx:16:18: 'cvh.test' is not a cimported module</div>
</div>