diff options
author | Guido van Rossum <guido@python.org> | 1995-07-07 22:50:36 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-07-07 22:50:36 (GMT) |
commit | 7faeab3103dd81d8e9cc7ff1d95d4909d6523032 (patch) | |
tree | b0e3ebfd6a522671ab66027e5dabc2154df9e393 /Python/import.c | |
parent | e78c5d0a16aaa212d7ba0729ab46de3b3035d57e (diff) | |
download | cpython-7faeab3103dd81d8e9cc7ff1d95d4909d6523032.zip cpython-7faeab3103dd81d8e9cc7ff1d95d4909d6523032.tar.gz cpython-7faeab3103dd81d8e9cc7ff1d95d4909d6523032.tar.bz2 |
new MAGIC; some changes to default files for imp.load_... functions
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Python/import.c b/Python/import.c index ca3de3d..4239e12 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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) |