C API and memory allocation
castironpi at gmail.com
Thu Dec 18 12:52:52 CET 2008
On Dec 18, 5:09 am, Ivan Illarionov <ivan.illario... at gmail.com> wrote:
> On 18 ÄÅË, 03:51, Aaron Brady <castiro... at gmail.com> wrote:
> > How did you get a reference to the original
> > string object, with which to increment its reference count?
> Use the "O!" format instead of "s":
> PyObject *pystr;
> ... PyArg_ParseTuple(args, "O!", &PyStringObject, &pystr) ...
> Then you can use PyString_AS_STRING explicitly, and control ref.
> counts yourself.
> > How do you know its length to copy it into your own buffer?
> Use the "s#" format, as Gabriel has said.
I see. Do I read correctly that 's' is only useful when the
argument's position is known? Otherwise you can't know its length or
change its reference count.
More information about the Python-list