[C++-sig] Wrapping classes that inherit from classes already wrapped

Alex Olivas olivas at icecube.umd.edu
Tue Feb 14 19:56:22 CET 2012

Hey All,
     I was working on a project a few months ago where I
was wrapping a lib ( using Boost.Python ) that inherited
from classes that were already wrapped ( using SIP ).
Boost.Python however couldn't find the base classes.  I
hacked something up ( that I'm not very proud of ) in class.cpp :

    type_handle get_class(type_info id)
         type_handle result(query_class(id));

         if (result.get() == 0)
           PyObject* globals = PyEval_GetGlobals() ;
           PyObject* key = object( id.name() ).ptr() ;
           PyObject* obj = PyDict_GetItem( globals, key );
           if( obj ){
             return type_handle( obj->ob_type );
             object report("extension class wrapper for base class ");
             report = report + id.name() + " has not been created yet";
             PyErr_SetObject(PyExc_RuntimeError, report.ptr());
         return result;

Surely there has to be a better way.  Does anyone have a
better solution than this?

This was also followed by metaclass and layout conflicts,
but that's another issue I think.

To give a little background I was trying to wrap a lib that
inherits from Qt and I really would prefer to use the
bindings from PyQt rather than re-wrap ( which also seems
more difficult than I thought it would be ).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120214/35af41f7/attachment.html>

More information about the Cplusplus-sig mailing list