On Oct 4, 2017, at 13:53, Benjamin Peterson <benja...@python.org> wrote:

> It might be helpful to enumerate the usecases for such an API. Perhaps a
> narrow, specialized API could satisfy most needs in a supportable way.

Currently `python -m dis thing.py` compiles the source then disassembles it.  
It would be kind of cool if you could pass a .pyc file to -m dis, in which case 
you’d need to unpack the header to get to the code object.  A naive 
implementation would unpack the magic number and refuse to disassemble any 
files that don’t match whatever that version of Python understands.  A more 
robust (possibly 3rd party) implementation could potentially disassemble a 
range of magic numbers and formats, and an API to get at the code object and 
metadata would help.

I was thinking about the bytecode hacking that some debuggers do.  This API 
would help them support multiple versions of Python.  They could use the API to 
discover what pyc format was in use, extract the code object, hack the bytecode 
and possibly rewrite a new PEP 3147 style pyc file with the debugger bytecodes 
inserted.

Third party bytecode optimizers could use the API to unpack multiple versions 
of pyc files, do their optimizations, and rewrite new files with the proper 
format.

Cheers,
-Barry

Attachment: signature.asc
Description: Message signed with OpenPGP

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to