[Pyrex] Issue with strings (when working interactively)
Yann Vernier
yann at donkey.dyndns.org
Thu Dec 16 12:26:13 CET 2004
On Thu, Dec 16, 2004 at 12:02:04PM +0100, Yuriy Pasichnyk wrote:
> Let's say I have the following in my spam.pyx file:
>
> cdef class Test:
> cdef char *x
That's a pointer. It doesn't store a string, only refers to it, and
unlike a Python object reference it's not reference counted. Pyrex'
conversion from strings to char* are meant for C function calls, and I
assume in this case what happens is that the char* points into the
Python string, which loses its last reference when you run it
interactively like that. As such, its memory may be reused, and your
pointer is invalid. Try using a "cdef object" if you want to keep a
hidden reference, and use str(arg) in your setter to coerce it into a
string, I guess.
--
PGP fingerprint = 9242 DC15 2502 FEAB E15F 84C6 D538 EC09 5380 5746
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20041216/a0307f03/attachment.bin
More information about the Pyrex
mailing list