[PyKDE] SIP and overloaded non-pure virtual functions

Phil Thompson phil at riverbankcomputing.co.uk
Thu May 29 20:34:00 BST 2003


On Thursday 29 May 2003 7:17 pm, Paul F. Kunz wrote:
> >>>>> On Thu, 29 May 2003 18:56:06 +0100, Phil Thompson
> >>>>> <phil at riverbankcomputing.co.uk> said:
> >
> > On Thursday 29 May 2003 1:15 am, Paul F. Kunz wrote:
> >> In my PlotterBase.zip file I have
> >>
> >> class PlotterBase {
> >>
> >> public:
> >>
> >> PlotterBase ( const std::string & ); void setRange ( const
> >> std::string &, double, double ); virtual void setBinWidth ( const
> >> std::string &, double );
> >>
> >> In the C++ code there's an implementation that is overridden by a
> >> number of derived classes of PlotterBase.  The Python user gets his
> >> handle on them via
> >>
> >> class DisplayController {
> >>
> >> public:
> >>
> >> static DisplayController * instance (); PlotterBase * createDisplay
> >> ( const std::string &, const NTuple &, const
> >> std::vector<std::string> & ) const;
> >>
> >> Where the Python class will have a pinter to a C++ derived class of
> >> PlotterBase.
> >>
> >> The SIP generated code for setBinWidth member function contains...
> >>
> >> PlotterBase *sipCpp;
> >>
> >> if
> >> (sipParseArgs(&sipArgsParsed,sipArgs,"mM1d",sipThisObj,sipClass_PlotterB
> >>ase ,&sipCpp,sipConvertTo_std_string,&a0,&a0IsTemp,&a1)) {
> >> Py_BEGIN_ALLOW_THREADS sipCpp -> PlotterBase::setBinWidth(*a0,a1);
> >> Py_END_ALLOW_THREADS
> >>
> >> The C++ call to setBinWidth is scoped, the the virtual function
> >> table of the derived class is not used.
> >>
> >> Is this a know bug in SIP code generation?
> >
> > No, that's what it is supposed to be. Deciding which is the right
> > implementation of setBinWidth() to call happens ealier on in the
> > process.
>
>    Its not working.   The C++ derived class of this C++ base class is
> not being exposed to Python   There's no way for Python to know to
> call the virtual function as a virtual function.   The scoping in the
> SIP generated code is messing things up.
>
>    Or, there's something I don't understand.

SIP expects the whole class hierarchy to be exposed.

The scoping is necessary to prevent loops when a Python re-implementation 
calls the super-class implementation.

A workaround would be to provide a handwritten version of setBinWidth() with 
the scoping omitted.

Phil




More information about the PyQt mailing list