I have been using Python for some time now and I have written some small Rust extensions for fun.
Recently, after having read a book about C and playing around with it, I wanted to attempt reading a bit of CPython. I found it to be VERY difficult.
Are there any good resources on how to attack this? Is there a blog/talk/book that guides you through how to read the actual C source code?
I read parts of Anthony Shaws’ CPython internals. There are some nice things in there, but I am looking for more content in that space. Like a walkthrough of how the Python List object is implemented in C, what the most important structs are, what the important parts of the codebase are, things like that.
IMO, writing a simple extension module using the CPython C API would be a good exercise to get you going with the basic concepts; you’ll be better equipped for this task after you’ve played a bit with the C API.
Yeah, that is good advice.
I made one and tried to reverse engineer some of the CPython builtins and objects. I have to say, this is VERY hard.
Keeping a list of things and links:
/include: header files. Include these in your IDE.
/objects: object implementations. Here you will find the
/python: interpreer, bytecode compiler & more infra
/parser: parser, lexer and parser generator
/modules: stdlib extensions and ‘main.c’
/programs: contains the ‘real’ main
I’ll just slog away. Perhaps I will collect my notes and share them later for others.
I suggest taking a look at dev guide there are some other sources from Victor Stinner’s Notes
Also, you can take a look at bugs to see current issues.