Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77ff3a6

Browse filesBrowse files
Factor out _extensions_cache_init().
1 parent 92697db commit 77ff3a6
Copy full SHA for 77ff3a6

File tree

Expand file treeCollapse file tree

1 file changed

+20
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-11
lines changed

‎Python/import.c

Copy file name to clipboardExpand all lines: Python/import.c
+20-11Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.