# CPython
# Reading python source code
- Start with Python C API
- Py_INCREF
# Tasks
# Python C API
Use inside of python to build new python
# Hello World Extension
- Why write in C?
- speed
- Legacy
- Integration
- Community
- Used to build Python
- ~600 Entrypoints
- only applies to CPython
- Any built-in function or type
- Deal with with C messyness
- write something and then say we wrote it.
- Building C Extensions - distutils know how to do that
ext_modules
PyObject*
pointer- Type-specific functions
- bunch of dedicated
C
functions, just fordicts
- lists etc.
- bunch of dedicated
Py_BuildValues
likesprintf
PyArg_ParseTuples
- reading arguments
def hello_world():
return "Hello World"
#include "python.h"
static PyObject *
# Memory Management
most messy part
- Reference counting protocol
- counting borrowed references
Pt_DECREF
# Making a Type
- Create structure
- Write
init
anddealloc
- decalre members
- Write functions
- Declare functions
- Make the type ready