mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
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:
parent
fb5d1c9236
commit
dc804ffb2f
7 changed files with 32 additions and 84 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue