Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.
(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode. I'm also holding back on his
change to main.c, which seems unnecessary to me.)
diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c
index b1fef39..3d570f7 100644
--- a/Modules/rotormodule.c
+++ b/Modules/rotormodule.c
@@ -178,7 +178,7 @@
{
Rotorobj *xp;
- xp = PyObject_NEW(Rotorobj, &Rotor_Type);
+ xp = PyObject_New(Rotorobj, &Rotor_Type);
if (xp == NULL)
return NULL;
set_key(xp, key);
@@ -204,10 +204,14 @@
return xp;
finally:
- PyMem_XDEL(xp->e_rotor);
- PyMem_XDEL(xp->d_rotor);
- PyMem_XDEL(xp->positions);
- PyMem_XDEL(xp->advances);
+ if (xp->e_rotor)
+ PyMem_DEL(xp->e_rotor);
+ if (xp->d_rotor)
+ PyMem_DEL(xp->d_rotor);
+ if (xp->positions)
+ PyMem_DEL(xp->positions);
+ if (xp->advances)
+ PyMem_DEL(xp->advances);
Py_DECREF(xp);
return (Rotorobj*)PyErr_NoMemory();
}
@@ -473,11 +477,15 @@
rotor_dealloc(xp)
Rotorobj *xp;
{
- PyMem_XDEL(xp->e_rotor);
- PyMem_XDEL(xp->d_rotor);
- PyMem_XDEL(xp->positions);
- PyMem_XDEL(xp->advances);
- PyMem_DEL(xp);
+ if (xp->e_rotor)
+ PyMem_DEL(xp->e_rotor);
+ if (xp->d_rotor)
+ PyMem_DEL(xp->d_rotor);
+ if (xp->positions)
+ PyMem_DEL(xp->positions);
+ if (xp->advances)
+ PyMem_DEL(xp->advances);
+ PyObject_Del(xp);
}
static PyObject *