Re: Overloaded C++ static methods and Python
William S Fulton <[email protected]> Thu, 30 Mar 2023 19:00:37 +0100
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CANGqftDBsSQpYrxTekaK2qHErx=H7CgmMcVxgb79032PBE8Y9Q@mail.gmail.com> |
On Thu, 23 Feb 2023 at 11:36, Jim Easterbrook <[email protected]> wrote: > I've encountered an interesting problem with the SWIG generated Python > interface of overloaded C++ methods. This is my test case: > > > %module overload_test > > > > class class_A { > > public: > > int method_1(); > > int method_1(int x); > > int method_2(); > > static int method_2(int x); > > }; > > The Python interface for method_1 is as you'd expect, but method_2() > becomes a static method requiring a class_A object to be passed as a > parameter. I'm running swig as follows: > > swig -c++ -python -builtin -fastdispatch overload_test.i > > The relevant parts of the wrapper file are > > > (void)self; > > if (!(argc = SWIG_Python_UnpackTuple(args, "class_A_method_1", 0, 2, > argv+1))) SWIG_fail; > > argv[0] = self; > > if (argc == 1) { > > PyObject *retobj = _wrap_class_A_method_1__SWIG_0(self, argc, argv); > > if (!SWIG_Python_TypeErrorOccurred(retobj)) return retobj; > > SWIG_fail; > > } > > if (argc == 2) { > > PyObject *retobj = _wrap_class_A_method_1__SWIG_1(self, argc, argv); > > if (!SWIG_Python_TypeErrorOccurred(retobj)) return retobj; > > SWIG_fail; > > } > > and > > > (void)self; > > if (!(argc = SWIG_Python_UnpackTuple(args, "class_A_method_2", 0, 1, > argv))) SWIG_fail; > > --argc; > > if (argc == 1) { > > int _v = 0; > > { > > void *vptr = 0; > > int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_class_A, 0); > > _v = SWIG_CheckState(res); > > } > > if (!_v) goto check_1; > > return _wrap_class_A_method_2__SWIG_0(self, argc, argv); > > } > > check_1: > > > > if (argc == 1) { > > PyObject *retobj = _wrap_class_A_method_2__SWIG_1(self, argc, argv); > > if (!SWIG_Python_TypeErrorOccurred(retobj)) return retobj; > > SWIG_fail; > > } > > Is this a known problem? Is there a workaround? > > Overloading static with non-static... goodness! Might be worth analysing to see if it only happens with -fastdispatch and/or -builtin. William _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user