mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-93741: Add private C API _PyImport_GetModuleAttrString() (GH-93742)
It combines PyImport_ImportModule() and PyObject_GetAttrString() and saves 4-6 lines of code on every use. Add also _PyImport_GetModuleAttr() which takes Python strings as arguments.
This commit is contained in:
parent
7b2064b4b9
commit
6fd4c8ec77
24 changed files with 114 additions and 248 deletions
|
@ -1841,43 +1841,21 @@ static PyObject *
|
|||
pysqlite_connection_iterdump_impl(pysqlite_Connection *self)
|
||||
/*[clinic end generated code: output=586997aaf9808768 input=1911ca756066da89]*/
|
||||
{
|
||||
PyObject* retval = NULL;
|
||||
PyObject* module = NULL;
|
||||
PyObject* module_dict;
|
||||
PyObject* pyfn_iterdump;
|
||||
|
||||
if (!pysqlite_check_connection(self)) {
|
||||
goto finally;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
module = PyImport_ImportModule(MODULE_NAME ".dump");
|
||||
if (!module) {
|
||||
goto finally;
|
||||
}
|
||||
|
||||
module_dict = PyModule_GetDict(module);
|
||||
if (!module_dict) {
|
||||
goto finally;
|
||||
}
|
||||
|
||||
PyObject *meth = PyUnicode_InternFromString("_iterdump");
|
||||
if (meth == NULL) {
|
||||
goto finally;
|
||||
}
|
||||
pyfn_iterdump = PyDict_GetItemWithError(module_dict, meth);
|
||||
Py_DECREF(meth);
|
||||
if (!pyfn_iterdump) {
|
||||
PyObject *iterdump = _PyImport_GetModuleAttrString(MODULE_NAME ".dump", "_iterdump");
|
||||
if (!iterdump) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(self->OperationalError,
|
||||
"Failed to obtain _iterdump() reference");
|
||||
}
|
||||
goto finally;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval = PyObject_CallOneArg(pyfn_iterdump, (PyObject *)self);
|
||||
|
||||
finally:
|
||||
Py_XDECREF(module);
|
||||
PyObject *retval = PyObject_CallOneArg(iterdump, (PyObject *)self);
|
||||
Py_DECREF(iterdump);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue