mirror of
https://github.com/python/cpython.git
synced 2026-02-07 18:30:30 +00:00
gh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (#144339)
Ignore "math.integer" extension if "math" is in sys.stdlib_module_names.
This commit is contained in:
parent
0bb4ecafcb
commit
2aea861fe0
3 changed files with 36 additions and 7 deletions
|
|
@ -3393,11 +3393,25 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
|
|||
Py_hash_t hash;
|
||||
// if stdlib_module_names is not NULL, it is always a frozenset.
|
||||
while (_PySet_NextEntry(stdlib_module_names, &i, &item, &hash)) {
|
||||
if (PyUnicode_Check(item)
|
||||
&& PyUnicode_Compare(key, item) == 0)
|
||||
{
|
||||
is_stdlib_ext = 1;
|
||||
break;
|
||||
if (!PyUnicode_Check(item)) {
|
||||
continue;
|
||||
}
|
||||
Py_ssize_t len = PyUnicode_GET_LENGTH(item);
|
||||
if (PyUnicode_Tailmatch(key, item, 0, len, -1) == 1) {
|
||||
Py_ssize_t key_len = PyUnicode_GET_LENGTH(key);
|
||||
if (key_len == len) {
|
||||
is_stdlib_ext = 1;
|
||||
break;
|
||||
}
|
||||
assert(key_len > len);
|
||||
|
||||
// Ignore sub-modules of stdlib packages. For example,
|
||||
// ignore "math.integer" if key starts with "math.".
|
||||
Py_UCS4 ch = PyUnicode_ReadChar(key, len);
|
||||
if (ch == '.') {
|
||||
is_stdlib_ext = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_stdlib_ext) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue