Fix wrapping of references/pointers and qualifiers to member pointers

Also fix Go wrapping of member const function pointers.
This commit is contained in:
William S Fulton 2017-03-16 21:04:38 +00:00
parent cf7d53599c
commit 72ba741d1c
21 changed files with 70 additions and 42 deletions

View File

@ -7,7 +7,7 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 3.0.13 (in progress)
============================
2017-03-10: wsfulton
2017-03-16: wsfulton
Add support for member const function pointers such as:
int fn(short (Funcs::* parm)(bool)) const;

View File

@ -1,5 +1,11 @@
%module member_funcptr_galore
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) extra2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) extra3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) pp5;
%{
#if defined(__SUNPRO_CC)
#pragma error_messages (off, badargtype2w) /* Formal argument ... is being passed extern "C" ... */
@ -185,7 +191,6 @@ int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool)) const { return 0; }
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool)) const { return 0; }
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool)) const { return 0; }
#if !defined(SWIGGO)
// member function pointer variables
short (Funcs::* pp1)(bool) = &Funcs::FF;
@ -199,5 +204,4 @@ short (Funcs::* *const& pp4)(bool) = extra4;
short (Funcs::* & pp5)(bool) = pp1;
short (Funcs::* const pp6)(bool) = &Funcs::FF;
short (Funcs::* const& pp7)(bool) = pp1;
#endif
%}

View File

@ -48,24 +48,18 @@ public:
typedef double (Shape::*PerimeterFunc_td)(void);
extern double do_op(Shape *s, double (Shape::*m)(void));
#if !defined(SWIGGO)
extern double do_op_td(Shape *s, PerimeterFunc_td m);
#endif
/* Functions that return member pointers */
extern double (Shape::*areapt())(void);
extern double (Shape::*perimeterpt())(void);
#if !defined(SWIGGO)
extern PerimeterFunc_td perimeterpt_td();
#endif
/* Global variables that are member pointers */
extern double (Shape::*areavar)(void);
extern double (Shape::*perimetervar)(void);
#if !defined(SWIGGO)
extern PerimeterFunc_td perimetervar_td;
#endif
%}
%{

View File

@ -49,24 +49,18 @@ public:
typedef double (Shape::*PerimeterFunc_td)(void) const;
extern double do_op(Shape *s, double (Shape::*m)(void) const);
#if !defined(SWIGGO)
extern double do_op_td(Shape *s, PerimeterFunc_td m);
#endif
/* Functions that return member pointers */
extern double (Shape::*areapt())(void) const;
extern double (Shape::*perimeterpt())(void) const;
#if !defined(SWIGGO)
extern PerimeterFunc_td perimeterpt_td();
#endif
/* Global variables that are member pointers */
extern double (Shape::*areavar)(void) const;
extern double (Shape::*perimetervar)(void) const;
#if !defined(SWIGGO)
extern PerimeterFunc_td perimetervar_td;
#endif
%}
%{
@ -124,11 +118,9 @@ PerimeterFunc_td perimetervar_td = &Shape::perimeter;
/* Some constants */
#if !defined(SWIGGO)
%constant double (Shape::*AREAPT)(void) const = &Shape::area;
%constant double (Shape::*PERIMPT)(void) const = &Shape::perimeter;
%constant double (Shape::*NULLPT)(void) const = 0;
#endif
/*
%inline %{
@ -152,8 +144,6 @@ int call1(int (Funktions::*d)(const int &, int) const, int a, int b) { Funktions
//int call3(int & (Funktions::*d)(const int &, int) const, int a, int b) { Funktions f; return (f.*d)(a, b); }
%}
#if !defined(SWIGGO)
%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const = &Funktions::addByValue;
#endif
//%constant int * (Funktions::*ADD_BY_POINTER)(const int &, int) const = &Funktions::addByPointer;
//%constant int & (Funktions::*ADD_BY_REFERENCE)(const int &, int) const = &Funktions::addByReference;

View File

@ -232,6 +232,8 @@ $body)"
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* name conversion for overloaded operators. */
#ifdef __cplusplus

View File

@ -136,6 +136,8 @@
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
%{

View File

@ -716,6 +716,8 @@ $result = C_SCHEME_UNDEFINED;
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* ------------------------------------------------------------
* Overloaded operator support

View File

@ -843,6 +843,13 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
$*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
return ret;
}
%typemap(csvarout, excode=SWIGEXCODE) SWIGTYPE *const& %{
get {
global::System.IntPtr cPtr = $imcall;
$*csclassname ret = (cPtr == global::System.IntPtr.Zero) ? null : new $*csclassname(cPtr, $owner);$excode
return ret;
} %}
%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
%{ temp = ($*1_ltype)$input;
$1 = ($1_ltype)&temp; %}
@ -1011,6 +1018,8 @@ SWIG_CSBODY_TYPEWRAPPER(internal, protected, internal, SWIGTYPE)
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* csharp keywords */
%include <csharpkw.swg>

View File

@ -43,6 +43,8 @@
return ret;
}
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/*
* Helper functions to pack/unpack arbitrary binary data (member function

View File

@ -341,8 +341,6 @@
%typemap(directorout) SWIGTYPE *
%{ $result = *($&1_ltype)&$input; %}
%apply SWIGTYPE * { SWIGTYPE *const }
/* Pointer references. */
%typemap(gotype) SWIGTYPE *const&
@ -692,6 +690,10 @@
SWIGTYPE (CLASS::*)
""
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* Go keywords. */
%include <gokw.swg>

View File

@ -468,5 +468,7 @@ typedef unsigned long SCM;
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* typemaps.i ends here */

View File

@ -1338,6 +1338,8 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* String & length */
%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray"

View File

@ -386,6 +386,8 @@ parameters match which function
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
// size_t (which is just a unsigned long)
%apply unsigned long { size_t };

View File

@ -782,4 +782,6 @@ FROM BlaBla IMPORT Bla;
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }

View File

@ -368,4 +368,6 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }

View File

@ -525,7 +525,8 @@
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* php keywords */
%include <phpkw.swg>

View File

@ -523,7 +523,8 @@
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* php keywords */
%include <phpkw.swg>

View File

@ -273,6 +273,8 @@ extern "C" {
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* ------------------------------------------------------------
* Overloaded operator support

View File

@ -584,6 +584,9 @@
}
#endif
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* ------------------------------------------------------------
* --- function ptr typemaps ---
* ------------------------------------------------------------ */

View File

@ -2806,17 +2806,25 @@ private:
return SWIG_NOWRAP;
}
String *rawval = Getattr(n, "rawval");
if (rawval && Len(rawval)) {
// Based on Swig_VargetToFunction
String *nname = NewStringf("(%s)", rawval);
String *call;
if (SwigType_isclass(type)) {
call = NewStringf("%s", nname);
} else {
call = SwigType_lcaststr(type, nname);
}
String *cres = Swig_cresult(type, Swig_cresult_name(), call);
Setattr(n, "wrap:action", cres);
Delete(nname);
Delete(call);
Delete(cres);
} else {
String *get = NewString("");
Printv(get, Swig_cresult_name(), " = ", NULL);
String *rawval = Getattr(n, "rawval");
if (rawval && Len(rawval)) {
if (SwigType_type(type) == T_STRING) {
Printv(get, "(char *)", NULL);
}
Printv(get, rawval, NULL);
} else {
char quote;
if (Getattr(n, "wrappedasconstant")) {
quote = '\0';
@ -2838,11 +2846,12 @@ private:
if (quote != '\0') {
Printf(get, "%c", quote);
}
}
Printv(get, ";\n", NULL);
Setattr(n, "wrap:action", get);
Delete(get);
}
String *sname = Copy(symname);
if (class_name) {
@ -6234,7 +6243,7 @@ private:
}
} else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) {
ret = NewString("_swig_fnptr");
} else if (SwigType_ismemberpointer(type)) {
} else if (SwigType_ismemberpointer(t)) {
ret = NewString("_swig_memberptr");
} else if (SwigType_issimple(t)) {
Node *cn = classLookup(t);

View File

@ -439,13 +439,8 @@ SwigType *SwigType_default_deduce(const SwigType *t) {
Setitem(l, numitems-2, deduced_subtype);
}
} else if (SwigType_ismemberpointer(subtype)) {
if (numitems >= 3) {
/* member pointer deduction, eg, r.p.m(CLASS) => r.m(CLASS) */
Delitem(l, numitems-3);
} else {
/* member pointer deduction, m(CLASS). => p. */
Setitem(l, numitems-2, NewString("p."));
}
} else if (is_enum && !SwigType_isqualifier(subtype)) {
/* enum deduction, enum SWIGTYPE => SWIGTYPE */
Setitem(l, numitems-1, NewString("SWIGTYPE"));