[PyKDE] Sip support for FILE */PyFileObject

Nigel Stewart ns at fluent.com
Tue Oct 11 16:17:38 BST 2005


>>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++.

Nigel




More information about the PyQt mailing list