Sequence Protocol, assign item
Torsten Mohr
tmohr at s.netic.de
Mon Sep 6 14:49:02 EDT 2004
Hi,
thanks for your answer!
> You don't want to use PyArg_ParseTuple here, because 'val'
> isn't wrapped in a tuple, it's the bare value of the RHS.
> Instead you want
>
> v = PyInt_AsLong(val);
> if (PyErr_Occurred())
> return -1;
That exactly solves the problem.
> Also note the -1 return value (not 0) to signal an error.
I also found this by looking into the sources of Objects/listobject.c,
thanks for that other hint.
>> In part A some INCREF/DECREF stuff is done, but i think i don't need
>> this as the PyObjects are only temporarily.
>
> That's correct in this case.
>
>> Exception exceptions.SystemError: 'new style getargs format but argument
>> \ is not a tuple' in 'garbage collection' ignored
>
> That's because you were passing PyArg_ParseTuple something
> that wasn't a tuple. (The error message talks about argument
> formats because PyArg_ParseTuple is intended for processing
> argument lists, and in normal use it can't ever get passed
> anything other than a tuple.)
Thanks for your hint, that helped me fix the problem. But where
can i learn more about the internals? Maybe i just assumed this
as a Py_Object* always needed to be transformed the way i did
before.
I did not find any help regarding this in the documentation and also
in the sources it was not obvious to me.
Best regards,
Torsten.
More information about the Python-list
mailing list