summaryrefslogtreecommitdiff
path: root/Python/import.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2014-05-12 17:54:55 -0600
committerEric Snow <ericsnowcurrently@gmail.com>2014-05-12 17:54:55 -0600
commit08197a4616f6294e21672fd8ebb5da7ce956c8e5 (patch)
treef288f00937c5fbb449f7edfb782654aee38dea64 /Python/import.c
parent0cc45baa3d160810f371ef7b69f4b56437bde790 (diff)
downloadcpython-git-08197a4616f6294e21672fd8ebb5da7ce956c8e5.tar.gz
Issue #21226: Set all attrs in PyImport_ExecCodeModuleObject.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/Python/import.c b/Python/import.c
index 0e26ffcd94..4c8f67f499 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -856,7 +856,7 @@ module_dict_for_exec(PyObject *name)
}
}
- return d;
+ return d; /* Return a borrowed reference. */
}
static PyObject *
@@ -888,33 +888,25 @@ PyObject*
PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname,
PyObject *cpathname)
{
- PyObject *d, *v;
+ PyObject *d, *res;
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
+ _Py_IDENTIFIER(_fix_up_module);
d = module_dict_for_exec(name);
if (d == NULL) {
return NULL;
}
- if (pathname != NULL) {
- v = pathname;
+ if (pathname == NULL) {
+ pathname = ((PyCodeObject *)co)->co_filename;
}
- else {
- v = ((PyCodeObject *)co)->co_filename;
+ res = _PyObject_CallMethodIdObjArgs(interp->importlib,
+ &PyId__fix_up_module,
+ d, name, pathname, cpathname, NULL);
+ if (res != NULL) {
+ res = exec_code_in_module(name, d, co);
}
- Py_INCREF(v);
- if (PyDict_SetItemString(d, "__file__", v) != 0)
- PyErr_Clear(); /* Not important enough to report */
- Py_DECREF(v);
-
- /* Remember the pyc path name as the __cached__ attribute. */
- if (cpathname != NULL)
- v = cpathname;
- else
- v = Py_None;
- if (PyDict_SetItemString(d, "__cached__", v) != 0)
- PyErr_Clear(); /* Not important enough to report */
-
- return exec_code_in_module(name, d, co);
+ return res;
}