@@ -344,9 +344,11 @@ def _write_pyc(state, co, source_stat, pyc):
344
344
try :
345
345
with atomicwrites .atomic_write (pyc , mode = "wb" , overwrite = True ) as fp :
346
346
fp .write (imp .get_magic ())
347
- mtime = int (source_stat .mtime )
347
+ # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
348
+ mtime = int (source_stat .mtime ) & 0xFFFFFFFF
348
349
size = source_stat .size & 0xFFFFFFFF
349
- fp .write (struct .pack ("<ll" , mtime , size ))
350
+ # "<LL" stands for 2 unsigned longs, little-ending
351
+ fp .write (struct .pack ("<LL" , mtime , size ))
350
352
fp .write (marshal .dumps (co ))
351
353
except EnvironmentError as e :
352
354
state .trace ("error writing pyc file at %s: errno=%s" % (pyc , e .errno ))
@@ -441,7 +443,7 @@ def _read_pyc(source, pyc, trace=lambda x: None):
441
443
if (
442
444
len (data ) != 12
443
445
or data [:4 ] != imp .get_magic ()
444
- or struct .unpack ("<ll " , data [4 :]) != (mtime , size )
446
+ or struct .unpack ("<LL " , data [4 :]) != (mtime & 0xFFFFFFFF , size & 0xFFFFFFFF )
445
447
):
446
448
trace ("_read_pyc(%s): invalid or out of date pyc" % source )
447
449
return None
0 commit comments