@@ -48,9 +48,13 @@ extern int verbose; /* Defined in pythonrun.c */
4848extern long getmtime (); /* In getmtime.c */
4949
5050/* Magic word to reject .pyc files generated by other Python versions */
51- /* Increment by one for each incompatible change */
52- /* MPW swaps CR and LF, so their value is incorporated as well */
53- #define MAGIC (0x999903L ^ (('\n'^10L)<<16) ^ (('\r'^13L)<<8))
51+ /* Change for each incompatible change */
52+ /* The value of CR and LF is incorporated so if you ever read or write
53+ a .pyc file in text mode the magic number will be wrong; also, the
54+ Apple MPW compiler swaps their values, botching string constants */
55+ /* XXX Perhaps the magic number should be frozen and a version field
56+ added to the .pyc file header? */
57+ #define MAGIC (0x4127L | ((long)'\r'<<16) | ((long)'\n'<<24))
5458
5559object * import_modules ; /* This becomes sys.modules */
5660
@@ -847,7 +851,7 @@ imp_load_compiled(self, args)
847851 object * fob = NULL ;
848852 object * m ;
849853 FILE * fp ;
850- if (!newgetargs (args , "ss|O !" , & name , & pathname , & Filetype , & fob ))
854+ if (!newgetargs (args , "ssO !" , & name , & pathname , & Filetype , & fob ))
851855 return NULL ;
852856 fp = get_file (pathname , fob , "rb" );
853857 if (fp == NULL )
@@ -865,10 +869,17 @@ imp_load_dynamic(self, args)
865869{
866870 char * name ;
867871 char * pathname ;
868- object * dummy ;
869- if (!newgetargs (args , "ss|O" , & name , & pathname , & dummy ))
872+ object * fob = NULL ;
873+ object * m ;
874+ FILE * fp = NULL ;
875+ if (!newgetargs (args , "ss|O!" , & name , & pathname , & Filetype , & fob ))
870876 return NULL ;
871- return load_dynamic_module (name , pathname , NULL );
877+ if (fob )
878+ fp = get_file (pathname , fob , "r" );
879+ m = load_dynamic_module (name , pathname , fp );
880+ if (fob == NULL )
881+ fclose (fp );
882+ return m ;
872883}
873884
874885static object *
@@ -881,7 +892,7 @@ imp_load_source(self, args)
881892 object * fob = NULL ;
882893 object * m ;
883894 FILE * fp ;
884- if (!newgetargs (args , "ss|O !" , & name , & pathname , & Filetype , & fob ))
895+ if (!newgetargs (args , "ssO !" , & name , & pathname , & Filetype , & fob ))
885896 return NULL ;
886897 fp = get_file (pathname , fob , "r" );
887898 if (fp == NULL )
0 commit comments