On Tuesday 11 October 2005 4:17 pm, Nigel Stewart wrote: > >>Another thing we've tried is creating a binding > >>for struct FILE, but the sip-generated code > >>is inclined to delete it once passed to > >>MyWriter... > >> > >>struct FILE > >>{ > >>%TypeHeaderCode > >>#include <cstdio> > >>using namespace std; > >>%End > >> > >>private: > >> FILE(); > >> FILE(const FILE &); > >> ~FILE(); > >> > >>%ConvertToTypeCode > >> > >> if (sipIsErr == NULL) > >> return PyFile_Check(sipPy); > >> > >> if (PyFile_Check(sipPy)) > >> { > >> *sipCppPtr = PyFile_AsFile(sipPy); > >> return 1; > >> } > >> > >> *sipIsErr = 1; > >> return 0; > >>%End > >>}; > > > > I don't know what you mean by "inclined to delete it". It should follow > > the normal garbage collection rules. If you want MyWriter to take > > ownership of the FILE then take ownership of it in the ctor. > > Sorry for being vague. %ConvertToTypeCode normally allocates a new > object - but in this special case it's merely unwrapping the existing > FILE pointer from the PyFileObject. > > (1) > > MyWriter(FILE *) > > ... > if (a0IsTemp) > delete a0; > > ... > > > (2) > > MyWriter(FILE * /Transfer/) > > ... > if (a0IsTemp) > delete a0; > ... > > > There seems to be an assumption that %ConvertToTypeCode creates > a copy that needs to be deleted and ownership can't be transferred > to C++.
It's not an assumption - it's the return value of %ConvertToTypeCode. Just make sure it always returns 0. Phil _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde