-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules #144339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -388,9 +388,11 @@ def test_disable(self): | |||||||
|
|
||||||||
| @skip_segfault_on_android | ||||||||
| def test_dump_ext_modules(self): | ||||||||
| # Disable sys.stdlib_module_names | ||||||||
| code = """ | ||||||||
| import faulthandler | ||||||||
| import sys | ||||||||
| import math | ||||||||
| # Don't filter stdlib module names | ||||||||
| sys.stdlib_module_names = frozenset() | ||||||||
| faulthandler.enable() | ||||||||
|
|
@@ -403,9 +405,22 @@ def test_dump_ext_modules(self): | |||||||
| if not match: | ||||||||
| self.fail(f"Cannot find 'Extension modules:' in {stderr!r}") | ||||||||
| modules = set(match.group(1).strip().split(', ')) | ||||||||
| for name in ('sys', 'faulthandler'): | ||||||||
| for name in ('sys', 'faulthandler', 'math'): | ||||||||
| self.assertIn(name, modules) | ||||||||
|
|
||||||||
| # Ignore "math.integer" sub-module if "math" package is | ||||||||
| # in sys.stdlib_module_names | ||||||||
| code = """ | ||||||||
| import faulthandler | ||||||||
| import math.integer | ||||||||
| faulthandler.enable() | ||||||||
| faulthandler._sigsegv() | ||||||||
| """ | ||||||||
| stderr, exitcode = self.get_output(code) | ||||||||
| stderr = '\n'.join(stderr) | ||||||||
| match = re.search(r'^Extension modules:', stderr, re.MULTILINE) | ||||||||
| self.assertIsNone(match) | ||||||||
|
Comment on lines
+421
to
+422
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Why not just so? |
||||||||
|
|
||||||||
| def test_is_enabled(self): | ||||||||
| orig_stderr = sys.stderr | ||||||||
| try: | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| When :mod:`faulthandler` dumps the list of third-party extension modules, | ||
| ignore ``math.integer`` sub-module since ``math`` package is part of | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we be more general, e.g. "ignore sub-modules of packages in ..."? Otherwise it makes it seem like only the one specific case is affected. |
||
| :data:`sys.stdlib_module_names`. Patch by Victor Stinner. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3393,11 +3393,24 @@ _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 "math.integer" if key starts with "math." | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as above. |
||||||
| Py_UCS4 ch = PyUnicode_ReadChar(key, len); | ||||||
| if (ch == '.') { | ||||||
| is_stdlib_ext = 1; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| if (is_stdlib_ext) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just duplicates the below, "Don't filter stdlib module names," IMO we don't need both.