summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-02-19 12:23:57 (GMT)
committerGuido van Rossum <guido@python.org>1991-02-19 12:23:57 (GMT)
commit7f133ed0732d216e00eda8456911f08a10bbc493 (patch)
treee6d78329982634395c08de886be16a80f01a9bea /Python/import.c
parent59e53a564c3ad6d7787e1626882e069459ff1a79 (diff)
downloadcpython-7f133ed0732d216e00eda8456911f08a10bbc493.zip
cpython-7f133ed0732d216e00eda8456911f08a10bbc493.tar.gz
cpython-7f133ed0732d216e00eda8456911f08a10bbc493.tar.bz2
Call the init function of a built-in module here.
,
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index f4b4ca9..93952a5 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -148,8 +148,15 @@ import_module(name)
char *name;
{
object *m;
- if ((m = dictlookup(modules, name)) == NULL)
- m = load_module(name);
+ if ((m = dictlookup(modules, name)) == NULL) {
+ if (init_builtin(name)) {
+ if ((m = dictlookup(modules, name)) == NULL)
+ err_setstr(SystemError, "builtin module missing");
+ }
+ else {
+ m = load_module(name);
+ }
+ }
return m;
}
@@ -204,3 +211,25 @@ doneimport()
}
DECREF(modules);
}
+
+
+/* Initialize built-in modules when first imported */
+
+extern struct {
+ char *name;
+ void (*initfunc)();
+} inittab[];
+
+static int
+init_builtin(name)
+ char *name;
+{
+ int i;
+ for (i = 0; inittab[i].name != NULL; i++) {
+ if (strcmp(name, inittab[i].name) == 0) {
+ (*inittab[i].initfunc)();
+ return 1;
+ }
+ }
+ return 0;
+}