It really works! Thanks!<br><br><div class="gmail_quote">On Thu, Jan 8, 2009 at 5:01 PM, John Arbash Meinel <span dir="ltr">&lt;<a href="mailto:john@arbash-meinel.com">john@arbash-meinel.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<div><div></div><div class="Wj3C7c"><br>
Anand Patil wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;d like to make an int* pointer stored in one Pyrex object available to<br>
&gt; another:<br>
&gt;<br>
&gt; cdef class NumberHolder:<br>
&gt; &nbsp; &nbsp; cdef int number<br>
&gt; &nbsp; &nbsp; def __init__(self):<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; self.number = 0<br>
&gt;<br>
&gt; cdef class PointerHolder:<br>
&gt; &nbsp; &nbsp; cdef int* my_pointer<br>
&gt; &nbsp; &nbsp; def __init__(self, number_holder):<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; my_pointer = number_holder.number<br>
&gt;<br>
&gt; If I try it this way, of course, I get errors like &#39;NumberHolder&#39; object<br>
&gt; has no attribute &#39;number&#39;. I&#39;m currently creating a NumPy array in<br>
&gt; NumberHolder and using PyArray_DATA from PointerHolder, but it seems<br>
&gt; excessive and possibly dangerous, since PointerHolder may change<br>
&gt; *my_pointer later. What&#39;s the best way to do this?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Anand<br>
&gt;<br>
<br>
</div></div>I believe you can do:<br>
<div class="Ih2E3d"><br>
<br>
cdef class PointerHolder:<br>
 &nbsp; &nbsp;cdef int* my_pointer<br>
 &nbsp; &nbsp;def __init__(self, number_holder):<br>
</div> &nbsp; &nbsp; &nbsp; &nbsp;cdef NumberHolder real_holder<br>
 &nbsp; &nbsp; &nbsp; &nbsp;real_holder = number_holder<br>
 &nbsp; &nbsp; &nbsp; &nbsp;self.my_pointer = &amp;real_holder.number<br>
<br>
You need to indicate to pyrex that number_holder is really a<br>
NumberHolder object, and not just a generic python object. Further, I&#39;m<br>
pretty sure the &amp; is necessary, since you want to point to the int, and<br>
not point at whatever the int points at.<br>
<br>
John<br>
=:-&gt;<br>
-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.9 (Cygwin)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org" target="_blank">http://enigmail.mozdev.org</a><br>
<br>
iEYEARECAAYFAklmMXUACgkQJdeBCYSNAAO2ygCfSsARbUIzUJODVy3moKdFCCJ2<br>
638AoKAyWfJ8vMo2l1oRUUgV1x8hbQEM<br>
=owSx<br>
-----END PGP SIGNATURE-----<br>
</blockquote></div><br>