[PYTHON MATRIX-SIG] URNG-2.2
P. Dubois
dubois@kristen.llnl.gov
Thu, 22 Feb 1996 13:03:58 -0800
URNG-2.2 is available at ftp-icf.llnl.gov/pub/basis/URNG-2.2.tar.gz.
This fixes an error in memory management. This was the first C extension
I wrote. I'd like to describe the error to make sure I have it right this
time.
I have a routine that allocates a new "urngobject", and I was using it
like this:
static PyObject *
URNG_CreateGenerator(self, args)
PyObject *self; /* Not used */
PyObject *args;
{
int seed;
PyObject *result;
if (!PyArg_ParseTuple(args, "i", &seed))
return NULL;
result = (PyObject *) newurngobject(seed);
return result;
}
I was getting a core dump when the program ended if I created such an object.
As a newbie, I assumed I had the reference count stuff messed up, so
I tried returning Py_BuildValue("O", result) instead of just result. I
stopped dumping core and went on. But this is wrong, of course, since
I now have a reference count of two on the object and it is never
deleted.
I had made the skeleton using modulator and had not checked the "dealloc"
option. When I add such a routine:
static void
urng_dealloc(self)
urngobject *self;
{
PyMem_DEL(self);
}
and put it in the object's table, all is well.
So is this right, you *have* to supply a dealloc method when you write an
extension object? If so, maybe modulator shouldn't give you a choice.
Or, am I still confused?
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================