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/Python/import.c b/Python/import.c
index a65614c..c224752 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -124,7 +124,7 @@
 		++countD;
 	for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
 		++countS;
-	filetab = malloc((countD + countS + 1) * sizeof(struct filedescr));
+	filetab = PyMem_NEW(struct filedescr, countD + countS + 1);
 	memcpy(filetab, _PyImport_DynLoadFiletab,
 	       countD * sizeof(struct filedescr));
 	memcpy(filetab + countD, _PyImport_StandardFiletab,
@@ -2398,10 +2398,10 @@
 }
 
 
-/* API for embedding applications that want to add their own entries to the
-   table of built-in modules.  This should normally be called *before*
-   Py_Initialize().  When the malloc() or realloc() call fails, -1 is returned
-   and the existing table is unchanged.
+/* API for embedding applications that want to add their own entries
+   to the table of built-in modules.  This should normally be called
+   *before* Py_Initialize().  When the table resize fails, -1 is
+   returned and the existing table is unchanged.
 
    After a similar function by Just van Rossum. */
 
@@ -2422,10 +2422,8 @@
 		;
 
 	/* Allocate new memory for the combined table */
-	if (our_copy == NULL)
-		p = malloc((i+n+1) * sizeof(struct _inittab));
-	else
-		p = realloc(our_copy, (i+n+1) * sizeof(struct _inittab));
+	p = our_copy;
+	PyMem_RESIZE(p, struct _inittab, i+n+1);
 	if (p == NULL)
 		return -1;