]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
new MAGIC; some changes to default files for imp.load_... functions
authorGuido van Rossum <guido@python.org>
Fri, 7 Jul 1995 22:50:36 +0000 (22:50 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 7 Jul 1995 22:50:36 +0000 (22:50 +0000)
Python/import.c

index ca3de3d02351567cc9bf06f4ba1716f7b5b9fb7b..4239e1230f7354d8781a6596c12dbf9ed6b03728 100644 (file)
@@ -48,9 +48,13 @@ extern int verbose; /* Defined in pythonrun.c */
 extern long getmtime(); /* In getmtime.c */
 
 /* Magic word to reject .pyc files generated by other Python versions */
-/* Increment by one for each incompatible change */
-/* MPW swaps CR and LF, so their value is incorporated as well */
-#define MAGIC (0x999903L ^ (('\n'^10L)<<16) ^ (('\r'^13L)<<8))
+/* Change for each incompatible change */
+/* The value of CR and LF is incorporated so if you ever read or write
+   a .pyc file in text mode the magic number will be wrong; also, the
+   Apple MPW compiler swaps their values, botching string constants */
+/* XXX Perhaps the magic number should be frozen and a version field
+   added to the .pyc file header? */
+#define MAGIC (0x4127L | ((long)'\r'<<16) | ((long)'\n'<<24))
 
 object *import_modules; /* This becomes sys.modules */
 
@@ -847,7 +851,7 @@ imp_load_compiled(self, args)
        object *fob = NULL;
        object *m;
        FILE *fp;
-       if (!newgetargs(args, "ss|O!", &name, &pathname, &Filetype, &fob))
+       if (!newgetargs(args, "ssO!", &name, &pathname, &Filetype, &fob))
                return NULL;
        fp = get_file(pathname, fob, "rb");
        if (fp == NULL)
@@ -865,10 +869,17 @@ imp_load_dynamic(self, args)
 {
        char *name;
        char *pathname;
-       object *dummy;
-       if (!newgetargs(args, "ss|O", &name, &pathname, &dummy))
+       object *fob = NULL;
+       object *m;
+       FILE *fp = NULL;
+       if (!newgetargs(args, "ss|O!", &name, &pathname, &Filetype, &fob))
                return NULL;
-       return load_dynamic_module(name, pathname, NULL);
+       if (fob)
+               fp = get_file(pathname, fob, "r");
+       m = load_dynamic_module(name, pathname, fp);
+       if (fob == NULL)
+               fclose(fp);
+       return m;
 }
 
 static object *
@@ -881,7 +892,7 @@ imp_load_source(self, args)
        object *fob = NULL;
        object *m;
        FILE *fp;
-       if (!newgetargs(args, "ss|O!", &name, &pathname, &Filetype, &fob))
+       if (!newgetargs(args, "ssO!", &name, &pathname, &Filetype, &fob))
                return NULL;
        fp = get_file(pathname, fob, "r");
        if (fp == NULL)