Ah, ctypes
Nick Craig-Wood
nick at craig-wood.com
Mon Jun 1 11:29:44 EDT 2009
Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> I wrote some code months ago to output 1-bit-per-pixel PNG files from
> Python, doing direct calls to libpng using ctypes, because PIL didn't give
> me sufficient control over colour tables and pixel depths.
>
> I thought the code was working fine. I left it aside for some months, came
> back to it a week or two ago, and found it was crashing. I was creating
> CFUNCTYPE objects to do callbacks to my own I/O routines
[snip]
> Make sure you keep references to CFUNCTYPE objects as long as they are
> used from C code. ctypes doesn’t, and if you don’t, they may be garbage
> collected, crashing your program when a callback is made.
>
> Yup, that was it. I changed my installation of the callbacks from
[snip]
As a ctypes user I found this an interesting story - thanks for
posting it!
ctypes could potentially note that function types don't have enough
references to them when passed in as arguments to C functions? It
might slow it down microscopically but it would fix this problem.
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list