Patch #1739468: Directories and zipfiles containing __main__.py are now executable
diff --git a/Python/import.c b/Python/import.c
index 6a4d22f..59a51bc 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -104,7 +104,6 @@
};
#endif
-static PyTypeObject NullImporterType; /* Forward reference */
/* Initialize things */
@@ -167,7 +166,7 @@
/* adding sys.path_hooks and sys.path_importer_cache, setting up
zipimport */
- if (PyType_Ready(&NullImporterType) < 0)
+ if (PyType_Ready(&PyNullImporter_Type) < 0)
goto error;
if (Py_VerboseFlag)
@@ -1088,7 +1087,7 @@
}
if (importer == NULL) {
importer = PyObject_CallFunctionObjArgs(
- (PyObject *)&NullImporterType, p, NULL
+ (PyObject *)&PyNullImporter_Type, p, NULL
);
if (importer == NULL) {
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
@@ -1106,6 +1105,20 @@
return importer;
}
+PyAPI_FUNC(PyObject *)
+PyImport_GetImporter(PyObject *path) {
+ PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL;
+
+ if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) {
+ if ((path_hooks = PySys_GetObject("path_hooks"))) {
+ importer = get_path_importer(path_importer_cache,
+ path_hooks, path);
+ }
+ }
+ Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */
+ return importer;
+}
+
/* Search the path (default sys.path) for a module. Return the
corresponding filedescr struct, and (via return arguments) the
pathname and an open file. Return NULL if the module is not found. */
@@ -3049,7 +3062,7 @@
};
-static PyTypeObject NullImporterType = {
+PyTypeObject PyNullImporter_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"imp.NullImporter", /*tp_name*/
sizeof(NullImporter), /*tp_basicsize*/
@@ -3096,7 +3109,7 @@
{
PyObject *m, *d;
- if (PyType_Ready(&NullImporterType) < 0)
+ if (PyType_Ready(&PyNullImporter_Type) < 0)
goto failure;
m = Py_InitModule4("imp", imp_methods, doc_imp,
@@ -3118,8 +3131,8 @@
if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure;
if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure;
- Py_INCREF(&NullImporterType);
- PyModule_AddObject(m, "NullImporter", (PyObject *)&NullImporterType);
+ Py_INCREF(&PyNullImporter_Type);
+ PyModule_AddObject(m, "NullImporter", (PyObject *)&PyNullImporter_Type);
failure:
;
}