Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 39129:f2031f15d99d legacy-trunk
Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Fri, 21 Jul 2006 05:32:28 +0000 |
| parents | 775f85b98e65 |
| children | baa54337c3d9 |
line wrap: on
line diff
--- a/Python/import.c Fri Jul 21 05:31:02 2006 +0000 +++ b/Python/import.c Fri Jul 21 05:32:28 2006 +0000 @@ -116,6 +116,8 @@ for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan) ++countS; filetab = PyMem_NEW(struct filedescr, countD + countS + 1); + if (filetab == NULL) + Py_FatalError("Can't intiialize import file table."); memcpy(filetab, _PyImport_DynLoadFiletab, countD * sizeof(struct filedescr)); memcpy(filetab + countD, _PyImport_StandardFiletab, @@ -239,8 +241,11 @@ long me = PyThread_get_thread_ident(); if (me == -1) return; /* Too bad */ - if (import_lock == NULL) + if (import_lock == NULL) { import_lock = PyThread_allocate_lock(); + if (import_lock == NULL) + return; /* Nothing much we can do. */ + } if (import_lock_thread == me) { import_lock_level++; return; @@ -259,7 +264,7 @@ unlock_import(void) { long me = PyThread_get_thread_ident(); - if (me == -1) + if (me == -1 || import_lock == NULL) return 0; /* Too bad */ if (import_lock_thread != me) return -1;
