Search code examples
c++tclswig

Why is my swig generated tcl code missing methods at runtime?


I am using swig 4.0.2 to generate a package for tcl use.

The source .i file contains lots of classes and the generated _wrap.cpp file contains the all the classes with their methods as I would expect and everything compiles ok with no warnings.

However, for at least 1 class, when I come to call a method on a instance from a tcl script I get a runtime error saying the method does not exist. The error also dumps out all the available methods of the class. The method I am trying to call, along with a few others, does not exist in that list.

Invalid method. Must be one of: configure cget -acquire -disown -delete ...

There doesn't appear to be any pattern to which methods are not in the list though it is consistent which methods are missing.

The missing methods are scattered through the declared swig interface. ie they aren't at the beginning or end, nor all in one block. There is no pattern to their names nor function signature that I can see.

The function being run when the error occurs is SWIG_Tcl_MethodCommand: a function generated by swig. It is responsible for looking up the method by name and printing out the error code.

The function wrappers all exist and are referenced in the class's swig_method array.

I would have imagined that if a method was not going to be found by the look up it would be all or nothing.

Does anyone have ideas where I could look for errors? I'm afraid I haven't been able to isolate into a small testcase that I can share.

I'm using swig 4.02, generating code for tcl8 and compiling under c++ 14.


Solution

  • The problem is caused by copy and paste code.

    A second swig package exists in the Project I'm working on. It redeclares the same class interface but with some methods missing!

    If I sync up the declarations then everything works.

    This leaves the question of how the original code with unsynced swig interfaces (that was generated with swig1.0) ever worked.