handle const pointers to functions
This commit is contained in:
parent
ba333729c3
commit
350d43d988
6 changed files with 9 additions and 2 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue