diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-18 11:56:28 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-18 11:56:28 (GMT) |
commit | 327a39b047e3abcecb08aabe4f4fcb683dd06ef5 (patch) | |
tree | 07bee72fac09745a9f7309c7b297d4c7e200f658 /Python/import.c | |
parent | 5cf449cfb286465cb9b5248dded4fcf96da6cba3 (diff) | |
download | cpython-327a39b047e3abcecb08aabe4f4fcb683dd06ef5.zip cpython-327a39b047e3abcecb08aabe4f4fcb683dd06ef5.tar.gz cpython-327a39b047e3abcecb08aabe4f4fcb683dd06ef5.tar.bz2 |
Patch #1739468: Directories and zipfiles containing __main__.py are now executable
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 27 |
1 files changed, 20 insertions, 7 deletions
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 @@ static const struct filedescr _PyImport_StandardFiletab[] = { }; #endif -static PyTypeObject NullImporterType; /* Forward reference */ /* Initialize things */ @@ -167,7 +166,7 @@ _PyImportHooks_Init(void) /* 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 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks, } 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 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks, 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 PyMethodDef NullImporter_methods[] = { }; -static PyTypeObject NullImporterType = { +PyTypeObject PyNullImporter_Type = { PyVarObject_HEAD_INIT(NULL, 0) "imp.NullImporter", /*tp_name*/ sizeof(NullImporter), /*tp_basicsize*/ @@ -3096,7 +3109,7 @@ initimp(void) { 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 @@ initimp(void) 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: ; } |