[Zodb-checkins] CVS: Zope/lib/python/BTrees - BTreeItemsTemplate.c:1.7.18.2 BTreeModuleTemplate.c:1.15.18.2 BTreeTemplate.c:1.20.18.2 BucketTemplate.c:1.24.6.2

Jeremy Hylton jeremy@zope.com
Fri, 8 Mar 2002 14:12:58 -0500


Update of /cvs-repository/Zope/lib/python/BTrees
In directory cvs.zope.org:/tmp/cvs-serv14838

Modified Files:
      Tag: Zope-2_5-branch
	BTreeItemsTemplate.c BTreeModuleTemplate.c BTreeTemplate.c 
	BucketTemplate.c 
Log Message:
Backport bug fixes from trunk.  

Original checkin message follows:

(Possibly) correct use of Python memory APIs.

Fix SF bug #516768 reported by Dave Wallace.

Replace use of PyMem_DEL() with PyObject_Del() on object dealloc
functions.  The use of PyMem_DEL() is incorrect for object
deallocation, because it only ever calls the low-level free().  If a
custom allocator like pymalloc is used, it needs to be called to free
the memory.

Also replace bare malloc() and realloc() with PyMem_Malloc() and
PyMem_Realloc().  I think this isn't a strict bug fix, but a would be
nice.  It guarantees that BTrees objects get their memory from the
same allocator as the Python core.


=== Zope/lib/python/BTrees/BTreeItemsTemplate.c 1.7.18.1 => 1.7.18.2 ===
   Py_XDECREF(self->lastbucket);
   Py_XDECREF(self->currentbucket);
-  PyMem_DEL(self);
+  PyObject_DEL(self);
 }
 
 static int 


=== Zope/lib/python/BTrees/BTreeModuleTemplate.c 1.15.18.1 => 1.15.18.2 ===
   ASSERT(sz > 0, "non-positive size malloc", NULL);
 
-  if ((r=malloc(sz))) return r;
+  if ((r=PyMem_Malloc(sz))) return r;
 
   PyErr_NoMemory();
   return NULL;
@@ -224,8 +224,8 @@
 
   ASSERT(sz > 0, "non-positive size realloc", NULL);
 
-  if (p) r=realloc(p,sz);
-  else r=malloc(sz);
+  if (p) r=PyMem_Realloc(p,sz);
+  else r=PyMem_Malloc(sz);
 
   UNLESS (r) PyErr_NoMemory();
 


=== Zope/lib/python/BTrees/BTreeTemplate.c 1.20.18.1 => 1.20.18.2 ===
 
   Py_DECREF(self->ob_type);
-  PyMem_DEL(self);
+  PyObject_Del(self);
 }
 
 static int


=== Zope/lib/python/BTrees/BucketTemplate.c 1.24.6.1 => 1.24.6.2 ===
 
   Py_DECREF(self->ob_type);
-  PyMem_DEL(self);
+  PyObject_Del(self);
 }
 
 /* Code to access Bucket objects as mappings */