A look at the value of "spam" with a debugger should tell you what's going on.
I have not yet figured out how to use a de-bugger with a python extension. Does anyone know of any nifty tutorial for how to do this (with gdb, preferably)? note that I'm a newby to C too, so I need a really basic run through.
I used gdb with gcc under Linux, and I just use it as I would on any other program:
gdb /usr/bin/python run spam.py
and wait for the crash. Of course your module should have been compiled with -g if you want symbolic debugging.
The only difficulty with debugging extension modules built as dynamic libraries is setting breakpoints. You can't do it right away because the module isn't loaded yet, so its symbols are unknown to gdb. My solution is to start my script with the import, followed immediately by "time.sleep(5)". That gives me five seconds to press Control-C to reenter the debugger, and from then on everything works as advertised. If someone knows a more elegant solution, please let me know!