From 350d43d98822c80d5a8696f33ee5634a720736fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Tomulik?= Date: Wed, 23 Mar 2016 16:11:15 +0100 Subject: [PATCH] handle const pointers to functions --- Examples/test-suite/funcptr_cpp.i | 2 +- Examples/test-suite/lua/funcptr_cpp_runme.lua | 1 + Examples/test-suite/python/funcptr_cpp_runme.py | 2 ++ Examples/test-suite/scilab/funcptr_cpp_runme.sci | 1 + Lib/python/pytypemaps.swg | 4 +++- Lib/typemaps/swigtype.swg | 1 + 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Examples/test-suite/funcptr_cpp.i b/Examples/test-suite/funcptr_cpp.i index 015164ed9..b63749dc1 100644 --- a/Examples/test-suite/funcptr_cpp.i +++ b/Examples/test-suite/funcptr_cpp.i @@ -20,7 +20,7 @@ int call3(int & (*d)(const int &, int), int a, int b) { return d(a, b); } %constant int (*ADD_BY_VALUE)(const int &, int) = addByValue; %constant int * (*ADD_BY_POINTER)(const int &, int) = addByPointer; %constant int & (*ADD_BY_REFERENCE)(const int &, int) = addByReference; - +%constant int (* const ADD_BY_VALUE_C)(const int &, int) = addByValue; %inline %{ typedef int AddByValueTypedef(const int &a, int b); diff --git a/Examples/test-suite/lua/funcptr_cpp_runme.lua b/Examples/test-suite/lua/funcptr_cpp_runme.lua index 3b8469348..d814e059a 100644 --- a/Examples/test-suite/lua/funcptr_cpp_runme.lua +++ b/Examples/test-suite/lua/funcptr_cpp_runme.lua @@ -16,3 +16,4 @@ assert(fc.addByValue(5,10) == 15) assert(fc.call1(fc.ADD_BY_VALUE, 5, 10) == 15) assert(fc.call2(fc.ADD_BY_POINTER, 7, 9) == 16) assert(fc.call3(fc.ADD_BY_REFERENCE, 8, 9) == 17) +assert(fc.call1(fc.ADD_BY_VALUE_C, 2, 3) == 5) diff --git a/Examples/test-suite/python/funcptr_cpp_runme.py b/Examples/test-suite/python/funcptr_cpp_runme.py index 08e85ad7b..eb113d226 100644 --- a/Examples/test-suite/python/funcptr_cpp_runme.py +++ b/Examples/test-suite/python/funcptr_cpp_runme.py @@ -6,3 +6,5 @@ if call2(ADD_BY_POINTER, 12, 13) != 25: raise RuntimeError if call3(ADD_BY_REFERENCE, 14, 15) != 29: raise RuntimeError +if call1(ADD_BY_VALUE_C, 2, 3) != 5: + raise RuntimeError diff --git a/Examples/test-suite/scilab/funcptr_cpp_runme.sci b/Examples/test-suite/scilab/funcptr_cpp_runme.sci index cb4c3cd0d..2065fb1df 100644 --- a/Examples/test-suite/scilab/funcptr_cpp_runme.sci +++ b/Examples/test-suite/scilab/funcptr_cpp_runme.sci @@ -3,5 +3,6 @@ exec("swigtest.start", -1); checkequal(call1(ADD_BY_VALUE_get(), 10, 11), 21, "ADD_BY_VALUE"); checkequal(call2(ADD_BY_POINTER_get(), 12, 13), 25, "ADD_BY_POINTER"); checkequal(call3(ADD_BY_REFERENCE_get(), 14, 15), 29, "ADD_BY_REFERENCE"); +checkequal(call1(ADD_BY_VALUE_C_get(), 2, 3), 5, "ADD_BY_VALUE_C"); exec("swigtest.quit", -1); diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 2341980f2..48b0bcdc8 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -79,10 +79,12 @@ /* Consttab, needed for callbacks, it should be removed later */ -%typemap(consttab) SWIGTYPE ((*)(ANY)) +%typemap(consttab) SWIGTYPE ((*)(ANY)) { SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)($value), &$descriptor } +%typemap(consttab) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY)); %typemap(constcode) SWIGTYPE ((*)(ANY)) ""; +%typemap(constcode) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY)); /* Smart Pointers */ diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index e8124df9c..40d3ff5e9 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -625,6 +625,7 @@ %typemap(constcode, noblock=1) SWIGTYPE ((*)(ANY)){ %set_constant("$symname", SWIG_NewFunctionPtrObj((void *)$value, $descriptor)); } +%typemap(constcode) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY)); #if defined(SWIG_DIRECTOR_TYPEMAPS)