Python is the programming language, while CPython
is the default Python interpreter (that is written in C). Python is defined as both a compiled & interpreted language.
Marshalling
refers to the serialization of Python objects so that they can be stored (as bytes)
Freezing
is to package Python scripts into a single executable
.pyc
files contains the compiled Python byte code
.pyd
files are frozen Python modules (i.e. DLL files made using Python)
.py
gets compiled to Python byte code .pyc
.pyc
PyCodeObject
struct in CPython (see below)https://nowave.it/python-bytecode-analysis-1.html
https://late.am/post/2012/03/26/exploring-python-code-objects.html https://blog.svenskithesource.be/posts/code-objects
When we compile source code in Python, the result is a code object. These objects contain lots of metadata, and are especially useful in cases where it is difficult to recover the source code. Eventually, these marshalled objects will get passed to CPython as a PyCodeObject
struct to be interpreted.
// <https://github.com/python/cpython/blob/3.10/Include/cpython/code.h>
struct PyCodeObject {
PyObject_HEAD
int co_argcount; /* #arguments, except *args */
int co_posonlyargcount; /* #positional only arguments */
int co_kwonlyargcount; /* #keyword only arguments */
int co_nlocals; /* #local variables */
int co_stacksize; /* #entries needed for evaluation stack */
int co_flags; /* CO_..., see below */
int co_firstlineno; /* first source line number */
PyObject *co_code; /* instruction opcodes */
PyObject *co_consts; /* list (constants used) */
PyObject *co_names; /* list of strings (names used) */
PyObject *co_varnames; /* tuple of strings (local variable names) */
PyObject *co_freevars; /* tuple of strings (free variable names) */
PyObject *co_cellvars; /* tuple of strings (cell variable names) */
Py_ssize_t *co_cell2arg; /* Maps cell vars which are arguments. */
PyObject *co_filename; /* unicode (where it was loaded from) */
PyObject *co_name; /* unicode (name, for reference) */
PyObject *co_linetable; /* string (encoding addr<->lineno mapping) */
// truncated ...
};