diff Python/import.c @ 12576:1c7c2dd1beb1 legacy-trunk

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.)
author Guido van Rossum <guido@python.org>
date Wed, 03 May 2000 23:44:39 +0000
parents c8dbd5f70288
children 6f4669814884
line wrap: on
line diff
--- a/Python/import.c	Wed May 03 22:34:12 2000 +0000
+++ b/Python/import.c	Wed May 03 23:44:39 2000 +0000
@@ -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;