using Mac OS X CoreGraphics via ctypes

Richard Jones richardjones at optushome.com.au
Mon Jun 18 17:53:10 EDT 2007


Daniel wrote:
> Thanks Diez. I'll try that if I decide to keep going with ctypes. I
> got a bit further but had some problems with memory management (i.e.
> retaining and releasing object references). It seemed like Python/
> ctypes was accessing referenced objects after I had released them,
> which caused segfaults.

I would be unlikely that this is the case. Much more likely is that you've
got some memory allocated by Python which is being passed on to a C library
and is subsequently freed by Python before the C library is finished with
it. Happens all the time. Just make sure you keep a reference in Python
land to any objects you've handed over to C for the lifetime that the C
library is likely to use it.

Having said that, it doesn't look like that's what's happening with your
CGPDFDocumentRelease call, though perhaps you needed to clean up the page
or rect that you obtained in the loop? 

"k" constants defined as strings are 32-bit numbers derived from 4 character
strings. You'll need to convert those strings to the correct number. Once
you've done that I believe your CGColorSpaceCreateWithName call will work.


    Richard




More information about the Python-list mailing list