[Python-3000-checkins] r58230 - in python/branches/py3k-importlib: Include/pythonrun.h NEWS Python/import.c Python/pythonrun.c
brett.cannon
python-3000-checkins at python.org
Sat Sep 22 06:41:13 CEST 2007
Author: brett.cannon
Date: Sat Sep 22 06:41:13 2007
New Revision: 58230
Modified:
python/branches/py3k-importlib/Include/pythonrun.h
python/branches/py3k-importlib/NEWS
python/branches/py3k-importlib/Python/import.c
python/branches/py3k-importlib/Python/pythonrun.c
Log:
Introduce _PyImport_Importlib() to handle importing _importlib.py during
startup.
Modified: python/branches/py3k-importlib/Include/pythonrun.h
==============================================================================
--- python/branches/py3k-importlib/Include/pythonrun.h (original)
+++ python/branches/py3k-importlib/Include/pythonrun.h Sat Sep 22 06:41:13 2007
@@ -123,6 +123,7 @@
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
PyAPI_FUNC(PyObject *) _PySys_Init(void);
PyAPI_FUNC(void) _PyImport_Init(void);
+PyAPI_FUNC(void) _PyImport_Importlib(void);
PyAPI_FUNC(void) _PyExc_Init(void);
PyAPI_FUNC(void) _PyImportHooks_Init(void);
PyAPI_FUNC(int) _PyFrame_Init(void);
Modified: python/branches/py3k-importlib/NEWS
==============================================================================
--- python/branches/py3k-importlib/NEWS (original)
+++ python/branches/py3k-importlib/NEWS Sat Sep 22 06:41:13 2007
@@ -1,3 +1,5 @@
+* Add _PyImport_Importlib() to import _importlib.
+
* Add Py_GetImportlibPath() as a way to get the path to _importlib.
* Have Modules/getpath.c use _importlib.py instead of os.py when searching for
Modified: python/branches/py3k-importlib/Python/import.c
==============================================================================
--- python/branches/py3k-importlib/Python/import.c (original)
+++ python/branches/py3k-importlib/Python/import.c Sat Sep 22 06:41:13 2007
@@ -104,7 +104,9 @@
{0, 0}
};
-static PyTypeObject NullImporterType; /* Forward reference */
+/* Forward declarations */
+static PyTypeObject NullImporterType;
+static PyCodeObject * parse_source_module(const char *, FILE *);
/* Initialize things */
@@ -152,6 +154,7 @@
code created in normal operation mode. */
pyc_magic = MAGIC + 1;
}
+
}
void
@@ -519,6 +522,34 @@
}
+void
+_PyImport_Importlib(void)
+{
+ const char *importlib_path = Py_GetImportlibPath();
+ FILE *fp = NULL;
+ PyCodeObject *code_object = NULL;
+ PyObject *module = NULL;
+
+
+ if (importlib_path[0] == '\0')
+ Py_FatalError("_importlib.py not found");
+
+ fp = fopen(importlib_path, "r");
+ code_object = parse_source_module(importlib_path, fp);
+ fclose(fp);
+
+ if (!code_object)
+ Py_FatalError("unable to parse _importlib");
+
+ module = PyImport_ExecCodeModuleEx("_importlib", (PyObject *)code_object,
+ (char *)importlib_path);
+ if (!module)
+ Py_FatalError("could not initialize _importlib");
+
+ Py_DECREF(module);
+}
+
+
/* Magic for extension modules (built-in as well as dynamically
loaded). To prevent initializing an extension module more than
once, we keep a static dictionary 'extensions' keyed by module name
Modified: python/branches/py3k-importlib/Python/pythonrun.c
==============================================================================
--- python/branches/py3k-importlib/Python/pythonrun.c (original)
+++ python/branches/py3k-importlib/Python/pythonrun.c Sat Sep 22 06:41:13 2007
@@ -237,6 +237,8 @@
_PyImportHooks_Init();
+ _PyImport_Importlib();
+
if (install_sigs)
initsigs(); /* Signal handling stuff, including initintr() */
More information about the Python-3000-checkins
mailing list