From: Guido van Rossum Date: Tue, 19 Feb 1991 12:23:57 +0000 (+0000) Subject: Call the init function of a built-in module here. X-Git-Tag: v0.9.8~1042 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f133ed0732d216e00eda8456911f08a10bbc493;p=thirdparty%2FPython%2Fcpython.git Call the init function of a built-in module here. , --- diff --git a/Python/import.c b/Python/import.c index f4b4ca9a9806..93952a5ebc10 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; +}