diff options
author | Guido van Rossum <guido@python.org> | 2000-05-03 23:44:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-05-03 23:44:39 (GMT) |
commit | b18618dab7b6b85bb05b084693706e59211fa180 (patch) | |
tree | 785d51f6677da8366be2ad4b4296a62f53161276 /Python/import.c | |
parent | 2808b744e8d94459f189e1d89c97072d6a1f53b6 (diff) | |
download | cpython-b18618dab7b6b85bb05b084693706e59211fa180.zip cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.gz cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.bz2 |
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.)
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 16 |
1 files changed, 7 insertions, 9 deletions
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 @@ _PyImport_Init() ++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 @@ initimp() } -/* 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 @@ PyImport_ExtendInittab(newtab) ; /* 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; |