summaryrefslogtreecommitdiffstats
path: root/Python/import.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-04-01 20:59:32 (GMT)
committerGuido van Rossum <guido@python.org>1993-04-01 20:59:32 (GMT)
commitf56e3db1dd4bedc9331933504f5008a03f5d3131 (patch)
treee5dad2acc4127f93e054658c6226ecec274c2930 /Python/import.c
parent41ffccbba75413c64efad283da19b8038aa07dd1 (diff)
downloadcpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.zip
cpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.tar.gz
cpython-f56e3db1dd4bedc9331933504f5008a03f5d3131.tar.bz2
Support for frozen scripts; added -i option.
Diffstat (limited to 'Python/import.c')
-rw-r--r--Python/import.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c
index 2171f4b..4310afa 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -52,7 +52,7 @@ extern int verbose; /* Defined in pythonmain.c */
extern char *argv0;
#endif
-/* Magic word to reject pre-0.9.9 .pyc files */
+/* Magic word to reject .pyc files generated by other Python versions */
#define MAGIC 0x99BE3AL
@@ -325,8 +325,11 @@ import_module(name)
char *name;
{
object *m;
+ int n;
if ((m = dictlookup(modules, name)) == NULL) {
- if (init_builtin(name)) {
+ if ((n = init_builtin(name)) || (n = init_frozen(name))) {
+ if (n < 0)
+ return NULL;
if ((m = dictlookup(modules, name)) == NULL)
err_setstr(SystemError,
"builtin module missing");
@@ -411,3 +414,38 @@ init_builtin(name)
}
return 0;
}
+
+extern struct frozen {
+ char *name;
+ char *code;
+ int size;
+} frozen_modules[];
+
+int
+init_frozen(name)
+ char *name;
+{
+ struct frozen *p;
+ codeobject *co;
+ object *m, *d, *v;
+ for (p = frozen_modules; ; p++) {
+ if (p->name == NULL)
+ return 0;
+ if (strcmp(p->name, name) == 0)
+ break;
+ }
+ if (verbose)
+ fprintf(stderr, "import %s # frozen\n", name);
+ co = (codeobject *) rds_object(p->code, p->size);
+ if (co == NULL)
+ return -1;
+ if ((m = add_module(name)) == NULL ||
+ (d = getmoduledict(m)) == NULL ||
+ (v = eval_code(co, d, d, (object *)NULL)) == NULL) {
+ DECREF(co);
+ return -1;
+ }
+ DECREF(co);
+ DECREF(v);
+ return 1;
+}