<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>&nbsp;cdef extern from &quot;Python.h&quot;:
<br>&nbsp;&nbsp;&nbsp; ctypedef struct PyTypeObject:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass
<br>&nbsp;&nbsp;&nbsp; ctypedef struct PyObject:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Py_ssize_t ob_refcnt
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PyTypeObject * ob_type
<br>cdef extern from &quot;longintrepr.h&quot;:
<br>&nbsp;&nbsp;&nbsp; cdef struct _longobject:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ob_refcnt
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PyTypeObject * ob_type
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ob_size
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int * ob_digit
<br>def test(temp = long(0)):
<br>&nbsp;&nbsp;&nbsp; cdef _longobject *l
<br>&nbsp;&nbsp;&nbsp; l = &lt;_longobject *&gt; temp
<br>&nbsp;&nbsp;&nbsp; print sizeof(l.ob_size)
<br>&nbsp;&nbsp;&nbsp; print sizeof(l.ob_digit[0])
<br><br>The error:<br><br>Error converting Pyrex file to C:<br>------------------------------------------------------------<br>...<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ob_size<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int * ob_digit<br>def test(temp = long(0)):<br>

&nbsp;&nbsp;&nbsp; cdef _longobject *l<br>&nbsp;&nbsp;&nbsp; l = &lt;_longobject *&gt; temp<br>&nbsp;&nbsp;&nbsp; print sizeof(l.ob_size)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^<br>------------------------------------------------------------<br><br>/home/case/code/cvh.pyx:16:18: &#39;cvh.test&#39; is not a cimported module</div>
</div>