C API: Testing my reference counting

lord trousers neil.toronto at gmail.com
Mon Mar 20 07:34:36 CET 2006


I'm currently replacing the Quake 3 game code (not the rendering,
sound, or collision detection pieces) with Python. I've now
successfully loaded Python modules and made callbacks to them, rendered
maps, written some fly-through code, and embedded a Python interactive
mode into the console (which is way, way cool).

It's my first C API project, and I want to make sure I've got my
reference counting right. I *could* go through the API docs and
determine which function returns what kind of PyObject pointer (shared,
new, etc.), and double- and triple-check all my code. In fact, I am,
but it's definitely prone to error, because I'm not as perfect as I'd
like to think. I want a more automatic way of doing it, or at least a
good way of checking correctness.

When the game is just running and spinning out frames, I *know* that no
new memory should be allocated that isn't immediately deallocated
(memory usage should be constant), and that Python's total reference
count shouldn't change. I can also set up tests that exercise various
parts of the Q3 engine / Python game thunking layer and support objects
that should leave memory in the same state it was at when they started.

Is there a way I can get hold of these kinds of statistics for
debugging?

Neil




More information about the Python-list mailing list