Playing with CPython Objects Internals
summary
Uses ctypes and the C API to poke at CPython object fields like ob_refcnt, ob_type, ob_size and ob_digit, freeing None and truncating tuples and lists, sharing list buffers and turning two lists into aliases. Demonstrates small-int cache from -5 to 256 so mutating a cached 100 makes every 100 become 101, flips True/False, and replaces integer add slot to always return 42. Examples run but corrupt interpreter state and are unsafe for production.
AI-written summary · about
chapters (26)
- 0:00Start
- 0:54Object
- 1:53Basic structure
- 5:20int structure
- 5:51int examples
- 6:27Accessing int
- 9:01bool structure
- 9:31Accessing bool
- 10:54bytes structure
- 11:30bytes examples
- 11:52Accessing bytes
- 12:23tuple structure
- 12:41tuple example
- 13:00Accessing tuple
- 13:52list structure
- 14:24list example
- 15:11Accessing list
- 15:42Very bad things
- 16:40dict structure
- 17:58dict keys structure
- 18:35dict key entry structure
- 18:45dict example (combined tables)
- 20:02dict example (splitted tables)
- 21:18Accessing dict
- 24:03References
- 25:18Conclusions
related talks
31mUnderstanding Python from the inside: C concepts to dive into CPython fearless
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
22mLow Level Python a Deep dive into the python sources
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
02h 26mPointers in Python
23mMemoirs of a Python Object: Memory Management and Improving Performance
25mAdvanced Python
50mExploring CPython's bytecode
