Although we've covered a fair amount of ground already, we're still
not in a position to write an actually useful extension. Part of the
reason for this is the fact that we've only handled raw
PyObjects. One of the primary purposes of writing C extensions
is interfacing with third party APIs, and not many of them take
As was mentioned earlier, all Python objects are allocated on the
heap, and the first few bytes of every object can be interpreted as
being those of a
struct PyObject. In a release build, a
PyObject just consists of a reference count and a pointer to a
type object. The reference count we have seen. The type object
determines almost every aspect of the behavior of the object.
The problem of handling differing data-types is naturally two-sided: one must be able to extract raw C-level data from Python objects and assemble such data into Python objects.