[Python-Dev] Proposal: .pyc file format change

M.-A. Lemburg mal@lemburg.com
Fri, 26 May 2000 12:48:05 +0200

Peter Funk wrote:
> [Guido van Rossum]:
> > Given Christian Tismer's testimonial and inspection of marshal.c, I
> > think Peter's small patch is acceptable.
> >
> > A bigger question is whether we should freeze the magic number and add
> > a version number.  In theory I'm all for that, but it means more
> > changes; there are several tools (e.c. Lib/py_compile.py,
> > Tools/freeze/modulefinder.py and Tools/scripts/checkpyc.py) that have
> > intimate knowledge of the .pyc file format that would have to be
> > modified to match.
> >
> > The current format of a .pyc file is as follows:
> >
> > bytes 0-3   magic number
> > bytes 4-7   timestamp (mtime of .py file)
> > bytes 8-*   marshalled code object
> Proposal:
> The future format (Python 1.6 and newer) of a .pyc file should be as follows:
> bytes 0-3   a new magic number, which should be definitely frozen in 1.6.
> bytes 4-7   a version number (which should be == 1 in Python 1.6)
> bytes 8-11  timestamp (mtime of .py file) (same as earlier)
> bytes 12-*  marshalled code object (same as earlier)

This will break all tools relying on having the code object available
in bytes[8:] and believe me: there are lots of those around ;-)

You cannot really change the file header, only add things to the end
of the PYC file...

Hmm, or perhaps we should move the version number to the code object
itself... after all, the changes we want to refer to
using the version number are located in the code object and not the
PYC file layout. Unmarshalling it would then raise the error.

Marc-Andre Lemburg
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/