PyCObject_FromVoidPtrAndDesc... proper destructor use in DLL, HELP!

Kevin@Cazabon.com kevin at cazabon.com
Fri Jan 3 04:20:59 CET 2003


I need a little help on how to properly use PyCObject_FromVoidPtrAndDesc.  I
can't seem to find any good examples, and I'm apparently not bright enough
to understand the documentation (Hey, I'm a Python programmer, not a C
programmer... why should I care about pointers and casting and crap!  That's
why I LOVE Python in the first place!  q:]  )

Here's the situation:

hTransform =  cmsCreateProofingTransform(blah, blah, );
// this works just dandy... I now have a void * to a C object that I want to
pass back to Python for later use in my DLL...(hTransform is a void *)

// I want to convert hTransform to a PyCObject so I can pass it back to
Python for later use in my DLL, so I call:
hTransformPointer = PyCObject_FromVoidPtrAndDesc(hTransform, hTransform,
cmsDeleteTransform);

// The destructor function is cmsDeleteTransform, and takes a single
argument:  the void* for the transform I want to destruct,
// So, I used hTransform as both the object and the desc args to
PyCObject_FromVoidPtrAndDesc... is this correct?

// and I return it to Python using Py_BuildValue... this is fine as-is too.
return Py_BuildValue("O", hTransformPointer);


The problem is that this setup doesn't seem to work:  the memory doesn't
seem to be reclaimed when the object is deleted (or goes out of scope).  If
you create/delete objects this way repeatedly, memory keeps climbing.
(however, I can properly use the object later by passing it back to the
DLL... no problems there, just in memory usage)

Any pointers (haha) on how to use this correctly so that cmsDeleteTransform
gets called with hTransform as the argument when Python reclaims the object
would be appreciated!!!  (Is it possible that I have to play with reference
counts?)

Thanks!

Kevin Cazabon.






More information about the Python-list mailing list