Sequence Protocol, assign item
greg
greg at cosc.canterbury.ac.nz
Sun Sep 5 06:34:25 EDT 2004
Torsten Mohr wrote:
> static int pytypeseq_ass_item(PyObject* s, int nr, PyObject* val) {
> int v;
> pytype_obj* self = (pytype_obj*)s;
>
> if(!PyArg_ParseTuple(val, "i", &v)) {
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;
Also note the -1 return value (not 0) to signal an error.
> 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.)
Greg
More information about the Python-list
mailing list