gh-128911: Add PyImport_ImportModuleAttr() function (#128912)

Add PyImport_ImportModuleAttr() and
PyImport_ImportModuleAttrString() functions.

* Add unit tests.
* Replace _PyImport_GetModuleAttr()
  with PyImport_ImportModuleAttr().
* Replace _PyImport_GetModuleAttrString()
  with PyImport_ImportModuleAttrString().
* Remove "pycore_import.h" includes, no longer needed.
This commit is contained in:
Victor Stinner 2025-01-30 12:17:29 +01:00 committed by GitHub
parent f927204f64
commit 3bebe46d34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 194 additions and 56 deletions

View file

@ -14,7 +14,6 @@
#include "Python.h"
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_import.h" // _PyImport_GetModuleAttrString()
#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include <stdbool.h>
@ -1996,7 +1995,7 @@ kqueue_tracking_init(PyObject *module) {
// Register a callback to invalidate kqueues with open fds after fork.
PyObject *register_at_fork = NULL, *cb = NULL, *args = NULL,
*kwargs = NULL, *result = NULL;
register_at_fork = _PyImport_GetModuleAttrString("posix",
register_at_fork = PyImport_ImportModuleAttrString("posix",
"register_at_fork");
if (register_at_fork == NULL) {
goto finally;