mirror of https://github.com/swig/swig
Fix -Wunused-variable warning in Lua and Octave wrappers
Add bool output parameter to Swig_overload_dispatch to say when it has generated code that will use the typecheck typemap code to help Lua and Octave to not emit unused argv[] arrays. Alas, resorted to warning suppression for deficient cpp11_initializer_list typecheck typemap in cpp11_std_initializer_list testcase.
This commit is contained in:
parent
4bf9547982
commit
22a8088a98
|
@ -12,7 +12,6 @@
|
|||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#pragma clang diagnostic ignored "-Wattributes"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
|
|
|
@ -18,6 +18,19 @@
|
|||
#endif
|
||||
%}
|
||||
|
||||
#if defined(SWIGLUA) || defined(SWIGOCTAVE)
|
||||
%{
|
||||
// The empty typecheck typemap for std::initializer_list results in $input not being used and a resulting unused variable warning
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(disable : 4990)
|
||||
#endif
|
||||
%}
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
|
|
@ -951,7 +951,8 @@ public:
|
|||
/* Emit overloading dispatch function */
|
||||
|
||||
int maxargs;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(argc,argv);", &maxargs);
|
||||
bool check_emitted = false;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(argc,argv);", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
|
|
@ -839,8 +839,9 @@ public:
|
|||
/* Last node in overloaded chain */
|
||||
|
||||
int maxargs;
|
||||
bool check_emitted = false;
|
||||
String *tmp = NewString("");
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs);
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(L);", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
@ -861,12 +862,14 @@ public:
|
|||
|
||||
Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL);
|
||||
Wrapper_add_local(f, "argc", "int argc");
|
||||
Printf(tmp, "int argv[%d]={1", maxargs + 1);
|
||||
for (int i = 1; i <= maxargs; i++) {
|
||||
Printf(tmp, ",%d", i + 1);
|
||||
if (maxargs > 0 && check_emitted) {
|
||||
Printf(tmp, "int argv[%d]={1", maxargs + 1);
|
||||
for (int i = 1; i <= maxargs; i++) {
|
||||
Printf(tmp, ",%d", i + 1);
|
||||
}
|
||||
Printf(tmp, "}");
|
||||
Wrapper_add_local(f, "argv", tmp);
|
||||
}
|
||||
Printf(tmp, "}");
|
||||
Wrapper_add_local(f, "argv", tmp);
|
||||
Printf(f->code, "argc = lua_gettop(L);\n");
|
||||
|
||||
Replaceall(dispatch, "$args", "self,args");
|
||||
|
|
|
@ -703,10 +703,9 @@ public:
|
|||
if (isOverloaded) {
|
||||
if (!Getattr(n, "sym:nextSibling")) {
|
||||
int maxargs;
|
||||
bool check_emitted = false;
|
||||
Wrapper *df = NewWrapper();
|
||||
String *dispatch = Swig_overload_dispatch(n,
|
||||
"free(argv);\n" "CAMLreturn(%s(args));\n",
|
||||
&maxargs);
|
||||
String *dispatch = Swig_overload_dispatch(n, "free(argv);\n" "CAMLreturn(%s(args));\n", &maxargs, &check_emitted);
|
||||
|
||||
Wrapper_add_local(df, "argv", "value *argv");
|
||||
|
||||
|
|
|
@ -796,12 +796,13 @@ public:
|
|||
String *iname = Getattr(n, "sym:name");
|
||||
String *wname = Swig_name_wrapper(iname);
|
||||
int maxargs;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs);
|
||||
bool check_emitted = false;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(args, nargout);", &maxargs, &check_emitted);
|
||||
String *tmp = NewString("");
|
||||
|
||||
Octave_begin_function(n, f->def, iname, wname, true);
|
||||
Wrapper_add_local(f, "argc", "int argc = args.length()");
|
||||
if (maxargs > 0) {
|
||||
if (maxargs > 0 && check_emitted) {
|
||||
Printf(tmp, "octave_value_ref argv[%d]={", maxargs);
|
||||
for (int j = 0; j < maxargs; ++j)
|
||||
Printf(tmp, "%soctave_value_ref(args,%d)", j ? "," : " ", j);
|
||||
|
|
|
@ -360,9 +360,9 @@ List *Swig_overload_rank(Node *n, bool script_lang_wrapping) {
|
|||
return result;
|
||||
}
|
||||
|
||||
// /* -----------------------------------------------------------------------------
|
||||
// * print_typecheck()
|
||||
// * ----------------------------------------------------------------------------- */
|
||||
/* -----------------------------------------------------------------------------
|
||||
* print_typecheck()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static bool print_typecheck(String *f, int j, Parm *pj, bool implicitconvtypecheckoff) {
|
||||
char tmp[256];
|
||||
|
@ -425,10 +425,11 @@ static String *ReplaceFormat(const_String_or_char_ptr fmt, int j) {
|
|||
/*
|
||||
Cast dispatch mechanism.
|
||||
*/
|
||||
String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *maxargs) {
|
||||
String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *maxargs, bool *check_emitted) {
|
||||
int i, j;
|
||||
|
||||
*maxargs = 0;
|
||||
*check_emitted = false;
|
||||
|
||||
String *f = NewString("");
|
||||
String *sw = NewString("");
|
||||
|
@ -533,6 +534,7 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *
|
|||
}
|
||||
|
||||
if (emitcheck) {
|
||||
*check_emitted = true;
|
||||
if (need_v) {
|
||||
Printf(f, "int _v = 0;\n");
|
||||
need_v = 0;
|
||||
|
@ -612,10 +614,11 @@ String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *
|
|||
/*
|
||||
Fast dispatch mechanism, provided by Salvador Fandi~no Garc'ia (#930586).
|
||||
*/
|
||||
static String *overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int *maxargs, const_String_or_char_ptr fmt_fastdispatch) {
|
||||
static String *overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int *maxargs, bool *check_emitted, const_String_or_char_ptr fmt_fastdispatch) {
|
||||
int i, j;
|
||||
|
||||
*maxargs = 0;
|
||||
*check_emitted = false;
|
||||
|
||||
String *f = NewString("");
|
||||
|
||||
|
@ -713,6 +716,7 @@ static String *overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int
|
|||
}
|
||||
|
||||
if (emitcheck) {
|
||||
*check_emitted = true;
|
||||
if (need_v) {
|
||||
Printf(f, "int _v = 0;\n");
|
||||
need_v = 0;
|
||||
|
@ -775,15 +779,16 @@ static String *overload_dispatch_fast(Node *n, const_String_or_char_ptr fmt, int
|
|||
return f;
|
||||
}
|
||||
|
||||
String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxargs, const_String_or_char_ptr fmt_fastdispatch) {
|
||||
String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxargs, bool *check_emitted, const_String_or_char_ptr fmt_fastdispatch) {
|
||||
|
||||
if (fast_dispatch_mode || GetFlag(n, "feature:fastdispatch")) {
|
||||
return overload_dispatch_fast(n, fmt, maxargs, fmt_fastdispatch);
|
||||
return overload_dispatch_fast(n, fmt, maxargs, check_emitted, fmt_fastdispatch);
|
||||
}
|
||||
|
||||
int i, j;
|
||||
|
||||
*maxargs = 0;
|
||||
*check_emitted = false;
|
||||
|
||||
String *f = NewString("");
|
||||
|
||||
|
@ -824,6 +829,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar
|
|||
pj = Getattr(pj, "tmap:in:next");
|
||||
continue;
|
||||
}
|
||||
*check_emitted = true;
|
||||
if (j >= num_required) {
|
||||
String *lfmt = ReplaceFormat(fmt, num_arguments);
|
||||
Printf(f, "if (%s <= %d) {\n", argc_template_string, j);
|
||||
|
|
|
@ -908,7 +908,8 @@ public:
|
|||
} else if (!Getattr(n, "sym:nextSibling")) {
|
||||
/* Generate overloaded dispatch function */
|
||||
int maxargs;
|
||||
String *dispatch = Swig_overload_dispatch_cast(n, "PUSHMARK(MARK); SWIG_CALLXS(%s); return;", &maxargs);
|
||||
bool check_emitted = false;
|
||||
String *dispatch = Swig_overload_dispatch_cast(n, "PUSHMARK(MARK); SWIG_CALLXS(%s); return;", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
|
|
@ -1004,8 +1004,9 @@ public:
|
|||
/* Last node in overloaded chain */
|
||||
|
||||
int maxargs;
|
||||
bool check_emitted = false;
|
||||
String *tmp = NewStringEmpty();
|
||||
String *dispatch = Swig_overload_dispatch(n, "%s(INTERNAL_FUNCTION_PARAM_PASSTHRU); return;", &maxargs);
|
||||
String *dispatch = Swig_overload_dispatch(n, "%s(INTERNAL_FUNCTION_PARAM_PASSTHRU); return;", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
|
|
@ -2580,6 +2580,7 @@ public:
|
|||
bool add_self = builtin_self && (!builtin_ctor || director_class);
|
||||
|
||||
int maxargs;
|
||||
bool check_emitted = false;
|
||||
|
||||
String *tmp = NewString("");
|
||||
String *dispatch;
|
||||
|
@ -2588,7 +2589,7 @@ public:
|
|||
String *dispatch_code = NewStringf("return %s", dispatch_call);
|
||||
|
||||
if (castmode) {
|
||||
dispatch = Swig_overload_dispatch_cast(n, dispatch_code, &maxargs);
|
||||
dispatch = Swig_overload_dispatch_cast(n, dispatch_code, &maxargs, &check_emitted);
|
||||
} else {
|
||||
String *fastdispatch_code;
|
||||
if (builtin_ctor)
|
||||
|
@ -2599,7 +2600,7 @@ public:
|
|||
Insert(fastdispatch_code, 0, "{\n");
|
||||
Append(fastdispatch_code, "\n}");
|
||||
}
|
||||
dispatch = Swig_overload_dispatch(n, dispatch_code, &maxargs, fastdispatch_code);
|
||||
dispatch = Swig_overload_dispatch(n, dispatch_code, &maxargs, &check_emitted, fastdispatch_code);
|
||||
Delete(fastdispatch_code);
|
||||
}
|
||||
|
||||
|
|
|
@ -2043,8 +2043,9 @@ public:
|
|||
/* Last node in overloaded chain */
|
||||
|
||||
int maxargs;
|
||||
bool check_emitted = false;
|
||||
String *tmp = NewString("");
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(nargs, args, self);", &maxargs);
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(nargs, args, self);", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
|
|
@ -571,9 +571,10 @@ public:
|
|||
String *functionName = Getattr(node, "sym:name");
|
||||
String *wrapperName = Swig_name_wrapper(functionName);
|
||||
int maxargs = 0;
|
||||
bool check_emitted = false;
|
||||
|
||||
/* Generate the dispatch function */
|
||||
String *dispatch = Swig_overload_dispatch(node, "return %s(SWIG_GatewayArguments);", &maxargs);
|
||||
String *dispatch = Swig_overload_dispatch(node, "return %s(SWIG_GatewayArguments);", &maxargs, &check_emitted);
|
||||
String *tmp = NewString("");
|
||||
|
||||
Printv(wrapper->def, "SWIGEXPORT int ", wrapperName, "(SWIG_GatewayParameters) {\n", NIL);
|
||||
|
|
|
@ -388,8 +388,8 @@ void emit_mark_varargs(ParmList *l);
|
|||
String *emit_action(Node *n);
|
||||
int emit_action_code(Node *n, String *wrappercode, String *action);
|
||||
void Swig_overload_check(Node *n);
|
||||
String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *, const_String_or_char_ptr fmt_fastdispatch = 0);
|
||||
String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *);
|
||||
String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxargs, bool *check_emitted, const_String_or_char_ptr fmt_fastdispatch = 0);
|
||||
String *Swig_overload_dispatch_cast(Node *n, const_String_or_char_ptr fmt, int *maxargs, bool *check_emitted);
|
||||
List *Swig_overload_rank(Node *n, bool script_lang_wrapping);
|
||||
SwigType *cplus_value_type(SwigType *t);
|
||||
|
||||
|
|
|
@ -500,7 +500,8 @@ public:
|
|||
/* Emit overloading dispatch function */
|
||||
|
||||
int maxargs;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(clientData, interp, objc, argv - 1);", &maxargs);
|
||||
bool check_emitted = false;
|
||||
String *dispatch = Swig_overload_dispatch(n, "return %s(clientData, interp, objc, argv - 1);", &maxargs, &check_emitted);
|
||||
|
||||
/* Generate a dispatch wrapper for all overloaded functions */
|
||||
|
||||
|
|
Loading…
Reference in New Issue