gh-117953: Small Cleanup of Extensions-Related Machinery Code (gh-118167)

This is a collection of very basic cleanups I've pulled out of gh-118116.  It is mostly renaming variables and moving a couple bits of code in functionally equivalent ways.
This commit is contained in:
Eric Snow 2024-04-23 08:25:50 -06:00 committed by GitHub
parent d0b664ee06
commit 23950beff8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 106 additions and 76 deletions

View file

@ -97,9 +97,10 @@ PyObject *
_PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
{
#ifndef MS_WINDOWS
PyObject *pathbytes = NULL;
PyObject *filename_bytes = NULL;
const char *filename_buf;
#endif
PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL;
PyObject *name_unicode = NULL, *name = NULL, *filename = NULL, *m = NULL;
const char *name_buf, *hook_prefix;
const char *oldcontext, *newcontext;
dl_funcptr exportfunc;
@ -126,26 +127,23 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
}
name_buf = PyBytes_AS_STRING(name);
path = PyObject_GetAttrString(spec, "origin");
if (path == NULL)
goto error;
if (PySys_Audit("import", "OOOOO", name_unicode, path,
Py_None, Py_None, Py_None) < 0) {
filename = PyObject_GetAttrString(spec, "origin");
if (filename == NULL) {
goto error;
}
#ifdef MS_WINDOWS
exportfunc = _PyImport_FindSharedFuncptrWindows(hook_prefix, name_buf,
path, fp);
exportfunc = _PyImport_FindSharedFuncptrWindows(
hook_prefix, name_buf, filename, fp);
#else
pathbytes = PyUnicode_EncodeFSDefault(path);
if (pathbytes == NULL)
filename_bytes = PyUnicode_EncodeFSDefault(filename);
if (filename_bytes == NULL) {
goto error;
exportfunc = _PyImport_FindSharedFuncptr(hook_prefix, name_buf,
PyBytes_AS_STRING(pathbytes),
fp);
Py_DECREF(pathbytes);
}
filename_buf = PyBytes_AS_STRING(filename_bytes);
exportfunc = _PyImport_FindSharedFuncptr(
hook_prefix, name_buf, filename_buf, fp);
Py_DECREF(filename_bytes);
#endif
if (exportfunc == NULL) {
@ -157,7 +155,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
hook_prefix, name_buf);
if (msg == NULL)
goto error;
PyErr_SetImportError(msg, name_unicode, path);
PyErr_SetImportError(msg, name_unicode, filename);
Py_DECREF(msg);
}
goto error;
@ -199,7 +197,7 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
if (PyObject_TypeCheck(m, &PyModuleDef_Type)) {
Py_DECREF(name_unicode);
Py_DECREF(name);
Py_DECREF(path);
Py_DECREF(filename);
return PyModule_FromDefAndSpec((PyModuleDef*)m, spec);
}
@ -228,25 +226,20 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp)
}
def->m_base.m_init = p0;
/* Remember the filename as the __file__ attribute */
if (PyModule_AddObjectRef(m, "__file__", path) < 0) {
PyErr_Clear(); /* Not important enough to report */
}
PyObject *modules = PyImport_GetModuleDict();
if (_PyImport_FixupExtensionObject(m, name_unicode, path, modules) < 0)
if (_PyImport_FixupExtensionObject(m, name_unicode, filename, modules) < 0)
goto error;
Py_DECREF(name_unicode);
Py_DECREF(name);
Py_DECREF(path);
Py_DECREF(filename);
return m;
error:
Py_DECREF(name_unicode);
Py_XDECREF(name);
Py_XDECREF(path);
Py_XDECREF(filename);
Py_XDECREF(m);
return NULL;
}