[Python] Improve handling of SWIG_Py*Method_New

The SWIG_PyInstanceMethod_New method is no longer added to wrapped
classes except when it's actually needed, which is when
(!builtin && fastproxy) is true (which it isn't by default).

The SWIG_PyStaticMethod_New method is no longer is now similarly
gated - previously only (fastproxy) was checked.

Finally the C/C++ functions that implement these were always compiled
into the module, but now they're only included if
(!builtin && fastproxy) is true.

Issue noted by vadz in #2190.
This commit is contained in:
Olly Betts 2022-02-04 11:32:01 +13:00 committed by Olly Betts
commit 951f946341
2 changed files with 24 additions and 8 deletions

View file

@ -8,6 +8,8 @@
%fragment("<stddef.h>"); // For offsetof
#endif
#if defined SWIGPYTHON_FASTPROXY && !defined SWIGPYTHON_BUILTIN
%insert(runtime) %{
#ifdef __cplusplus
extern "C" {
@ -24,6 +26,8 @@ SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyO
#endif
%}
#endif
%init %{
#ifdef __cplusplus
@ -103,6 +107,8 @@ SWIG_Python_FixMethods(PyMethodDef *methods, const swig_const_info *const_table,
}
}
#if defined SWIGPYTHON_FASTPROXY && !defined SWIGPYTHON_BUILTIN
/* -----------------------------------------------------------------------------
* Method creation and docstring support functions
* ----------------------------------------------------------------------------- */
@ -161,6 +167,8 @@ SWIGINTERN PyObject *SWIG_PyStaticMethod_New(PyObject *SWIGUNUSEDPARM(self), PyO
return PyStaticMethod_New(func);
}
#endif
#ifdef __cplusplus
}
#endif