gh-128911: Use PyImport_ImportModuleAttr() function (#129657)

* Replace PyImport_ImportModule() + PyObject_GetAttr() with
  PyImport_ImportModuleAttr().
* Replace PyImport_ImportModule() + PyObject_GetAttrString() with
  PyImport_ImportModuleAttrString().
This commit is contained in:
Victor Stinner 2025-02-05 11:03:58 +01:00 committed by GitHub
parent fb5d1c9236
commit dc804ffb2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 32 additions and 84 deletions

View file

@ -47,7 +47,6 @@ static PyObject *
test_code_extra(PyObject* self, PyObject *Py_UNUSED(callable))
{
PyObject *result = NULL;
PyObject *test_module = NULL;
PyObject *test_func = NULL;
// Get or initialize interpreter-specific code object storage index
@ -62,11 +61,8 @@ test_code_extra(PyObject* self, PyObject *Py_UNUSED(callable))
// Get a function to test with
// This can be any Python function. Use `test.test_misc.testfunction`.
test_module = PyImport_ImportModule("test.test_capi.test_misc");
if (!test_module) {
goto finally;
}
test_func = PyObject_GetAttrString(test_module, "testfunction");
test_func = PyImport_ImportModuleAttrString("test.test_capi.test_misc",
"testfunction");
if (!test_func) {
goto finally;
}
@ -102,7 +98,6 @@ test_code_extra(PyObject* self, PyObject *Py_UNUSED(callable))
}
result = Py_NewRef(Py_None);
finally:
Py_XDECREF(test_module);
Py_XDECREF(test_func);
return result;
}