EMBEDDERS--REQUEST FOR COMMENTS:
Courageous
jkraska1 at san.rr.com
Wed May 24 01:22:43 EDT 2000
Here's a brief code snippet:
--------
static int ExampleObjectSetattr ( ExampleObject* self, char* name, PyObject* value )
{
if (strcmp(name,"data")==0)
{
if (PyString_Check(value))
{
self->data = PyString_AsString(value);
return 0;
}
else
{
PyErr_SetString(PyExc_AttributeError,"attempt to set data attribute to a value which is
not a string");
return -1;
}
}
else
{
PyErr_SetString(PyExc_AttributeError,"attempt to set unknown attribute on non dynamic
external type");
return -1;
}
}
--------
My presumption is that, in this instance, I don't increase the reference count
on the valuem because I've ascertained that it's a primitive (string, int, et
al).
However, if this were a real object, I'd be doing an INCREF() on it, and
furthermore, would have to take care to do a DECREF() on what I was assigning
over.
Do I have this right?
Thanks.
C/
More information about the Python-list
mailing list