[PyKDE] Sip support for FILE */PyFileObject

Nigel Stewart ns at fluent.com
Tue Oct 11 18:01:28 BST 2005


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

     Yes, that is the solution to the problem.
     Many thanks!

Nigel

--------

 From the Sip documentation...

"If sipIsErr is not NULL then a non-zero value is returned if the mapped
  type instance returned through sipCppPtr was created on the heap.
  Otherwise zero is returned."

--------

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 0;  /* The item was not allocated on the heap */
     }

     *sipIsErr = 1;
     return 0;
%End
};




More information about the PyQt mailing list