8000 Factor out _extensions_cache_init(). · python/cpython@77ff3a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77ff3a6

Browse files
Factor out _extensions_cache_init().
1 parent 92697db commit 77ff3a6

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Python/import.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,25 @@ hashtable_destroy_str(void *ptr)
986986

987987
#define HTSEP ':'
988988

989+
static int
990+
_extensions_cache_init(void)
991+
{
992+
_Py_hashtable_allocator_t alloc = {PyMem_RawMalloc, PyMem_RawFree};
993+
EXTENSIONS.hashtable = _Py_hashtable_new_full(
994+
hashtable_hash_str,
995+
hashtable_compare_str,
996+
hashtable_destroy_str, // key
997+
/* There's no need to decref the def since it's immortal. */
998+
NULL, // value
999+
&alloc
1000+
);
1001+
if (EXTENSIONS.hashtable == NULL) {
1002+
PyErr_NoMemory();
1003+
return -1;
1004+
}
1005+
return 0;
1006+
}
1007+
9891008
static PyModuleDef *
9901009
_extensions_cache_get(PyObject *filename, PyObject *name)
9911010
{
@@ -1023,17 +1042,7 @@ _extensions_cache_set(PyObject *filename, PyObject *name, PyModuleDef *def)
10231042
extensions_lock_acquire();
10241043

10251044
if (EXTENSIONS.hashtable == NULL) {
1026-
_Py_hashtable_allocator_t alloc = {PyMem_RawMalloc, PyMem_RawFree};
1027-
EXTENSIONS.hashtable = _Py_hashtable_new_full(
1028-
hashtable_hash_str,
1029-
hashtable_compare_str,
1030-
hashtable_destroy_str, // key
1031-
/* There's no need to decref the def since it's immortal. */
1032-
NULL, // value
1033-
&alloc
1034-
);
1035-
if (EXTENSIONS.hashtable == NULL) {
1036-
PyErr_NoMemory();
1045+
if (_extensions_cache_init() < 0) {
10371046
goto finally;
10381047
}
10391048
}

0 commit comments

Comments
 (0)
0