Menu

#1359 FW: Bug with allprotected virtual wraps in Python

open
nobody
None
5
2023-06-24
2014-02-18
No

I’m running into problems using allprotected, generating wraps… I’ve tried to debug, but I don’t know nearly enough on how this code is supposed to work. Here is the code I’m seeing the problem with:

Myplugin.i

%module(directors="1", allprotected="1") myplugin
%import "base.i"

class myPlugin : public PluginBase
{
public:
       //void Foo(); <- not required..
} ;

base.i

%module(directors="1", allprotected="1") base

class string { };
class widget { };
class settings { };

%feature("director");
class PluginBase
{
  public:
    virtual ~PluginBase ();
  protected:
    virtual bool SaveWindowInfo(const string &, const string &, widget * w);
    virtual bool SaveWindowInfo(const string &, const string &, widget * w, settings *s);
};

The problem is if I look at the generated file, I see this code:

SWIGINTERN PyObject *_wrap_myPlugin_SaveWindowInfo(PyObject *self, PyObject *args) {
  int argc;
  PyObject *argv[2];
  int ii;

  if (!PyTuple_Check(args)) SWIG_fail;
  argc = args ? (int)PyObject_Length(args) : 0;
  for (ii = 0; (ii < 1) && (ii < argc); ii++) {
    argv[ii] = PyTuple_GET_ITEM(args,ii);
  }

fail:
  SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number or type of arguments for overloaded function 'myPlugin_SaveWindowInfo'.\n"
    "  Possible C/C++ prototypes are:\n"
    "    PluginBase::SaveWindowInfo(string const &,string const &,widget *)\n"
    "    PluginBase::SaveWindowInfo(string const &,string const &,widget *,settings *)\n");
  return 0;
}

Notice it contains no code to execute the different ‘SWIG_#’ wrapped functions (but those functions do exist)!

It seems this bug occurs when the following 3 cases are true:

1) Multiple variations of virtual function are defined in a base class
2) Derived class does not defined the virtual function
3) The base class and derived classes are defined in different SWIG modules

I've found a workaround - negate #2. So, defined the virtual functions in derived class (in an #ifdef 0 block). But, would be nice to not have to do that...

Discussion

  • Olly Betts

    Olly Betts - 2022-01-30

    Still reproducible with current git master. The arg decoding logic in the highlighted function is different, but still no actual dispatching yet the functions to dispatch to are generated.

     
  • Olly Betts

    Olly Betts - 2023-06-24

    There have been some allprotected fixes recently, but this is still reproducible.

     

Log in to post a comment.