summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-12-20 21:23:41 (GMT)
committerGuido van Rossum <guido@python.org>1999-12-20 21:23:41 (GMT)
commited1170e49fe775b3af0926db7fa6c984a79ecc8f (patch)
treeebcf19471a780c82fccf2433f31b47a4dee2e7e7 /Python
parent9f65081d90dcc40650adffd2ed730ff5eb1e47c0 (diff)
downloadcpython-ed1170e49fe775b3af0926db7fa6c984a79ecc8f.zip
cpython-ed1170e49fe775b3af0926db7fa6c984a79ecc8f.tar.gz
cpython-ed1170e49fe775b3af0926db7fa6c984a79ecc8f.tar.bz2
In _PyImport_Init(), dynamically construct the table of legal suffixes
from two static tables (one standard, one provided by the platform's dynload_*.c variant). This is part of a set of patches by Greg Stein.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c
index 851fd06..e10463b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -94,17 +94,45 @@ extern struct _inittab _PyImport_Inittab[];
struct _inittab *PyImport_Inittab = _PyImport_Inittab;
+/* these tables define the module suffixes that Python recognizes */
+struct filedescr * _PyImport_Filetab = NULL;
+static const struct filedescr _PyImport_StandardFiletab[] = {
+ {".py", "r", PY_SOURCE},
+ {".pyc", "rb", PY_COMPILED},
+ {0, 0}
+};
+
/* Initialize things */
void
_PyImport_Init()
{
+ const struct filedescr *scan;
+ struct filedescr *filetab;
+ int countD = 0;
+ int countS = 0;
+
+ /* prepare _PyImport_Filetab: copy entries from
+ _PyImport_DynLoadFiletab and _PyImport_StandardFiletab.
+ */
+ for (scan = _PyImport_DynLoadFiletab; scan->suffix != NULL; ++scan)
+ ++countD;
+ for (scan = _PyImport_StandardFiletab; scan->suffix != NULL; ++scan)
+ ++countS;
+ filetab = malloc((countD + countS + 1) * sizeof(struct filedescr));
+ memcpy(filetab, _PyImport_DynLoadFiletab,
+ countD * sizeof(struct filedescr));
+ memcpy(filetab + countD, _PyImport_StandardFiletab,
+ countS * sizeof(struct filedescr));
+ filetab[countD + countS].suffix = NULL;
+
+ _PyImport_Filetab = filetab;
+
if (Py_OptimizeFlag) {
- /* Replace ".pyc" with ".pyo" in import_filetab */
- struct filedescr *p;
- for (p = _PyImport_Filetab; p->suffix != NULL; p++) {
- if (strcmp(p->suffix, ".pyc") == 0)
- p->suffix = ".pyo";
+ /* Replace ".pyc" with ".pyo" in _PyImport_Filetab */
+ for (; filetab->suffix != NULL; filetab++) {
+ if (strcmp(filetab->suffix, ".pyc") == 0)
+ filetab->suffix = ".pyo";
}
}
}