Swap_8_and_9: A simple import can modify the Python interpreter

The swap_8_and_9 module is a simple Python module written entirely in C. It consists of two files: setup.py and the C source file, swap_8_and_9.c. The setup.py file is responsible for setting up the module, while the C source file contains the module’s definition and the function that is called upon import. The module modifies the cached small integers in CPython, specifically integers 8 and 9. By importing this module, the interpreter is likely to crash, making it important to only install and import trusted modules. This module serves as a learning exercise rather than having a practical purpose. The complete code can be found on GitHub.

https://kenschutte.com/python-swap-ints/

To top