Python/C API - PyArg_ParseTuple problem ?
Michael Hudson
mwh at python.net
Fri Aug 22 14:23:28 EDT 2003
"Poire Williams" <poire.williams at nomore.org> writes:
> Hi, everybody.
>
> I'm writing a Python binding for a C++ library and I just found something
> that puzzles me.
[snippety]
> If I do this:
>
> >> s = 'hi'
> >> t = NewType(0, 42, s)
>
> everything is well...
Even after a 'del s'?
> Moreover, if I change my C code to something like
> this:
>
> if (!PyArg_ParseTuple(args, "ii|O", &a, &b, &o)
> return NULL;
> s = PyString_AsString(o);
>
> everything's fine again, in both cases...
>
> I guess it's some kind of twisted reference count thing, and I'm still
> trying to get some minimal C code to reproduce this. Meanwhile, does
> anybody have a clue ?
>
> Thanks in advance.
>
> Precisions: I'm running Python 2.2.3 on Linux, and I don't free() the
> buffer retrieved via PyArg_ParseTuple or PyString_AsString :)
No, but I bet you're stuffing it into your data structure somewhere
along the line. I think you need to copy the string data.
Cheers,
mwh
--
In that case I suggest that to get the correct image you look at
the screen from inside the monitor whilst standing on your head.
-- James Bonfield, http://www.ioccc.org/2000/rince.hint
More information about the Python-list
mailing list