Mercurial > cpython-lru_cache-weakref
diff Python/import.c @ 141:bf5a8539d8ba legacy-trunk
Call the init function of a built-in module here.
,
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 19 Feb 1991 12:23:57 +0000 |
| parents | a6934380c6e7 |
| children | 853b736a6a9e |
line wrap: on
line diff
--- a/Python/import.c Tue Feb 19 12:22:24 1991 +0000 +++ b/Python/import.c Tue Feb 19 12:23:57 1991 +0000 @@ -148,8 +148,15 @@ 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 @@ } 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; +}
