diff --git a/Examples/test-suite/allowexcept.i b/Examples/test-suite/allowexcept.i index 076173e8f..14b19b33d 100644 --- a/Examples/test-suite/allowexcept.i +++ b/Examples/test-suite/allowexcept.i @@ -34,12 +34,20 @@ private: XYZ* operator&(); // prevent dereferencing used in normally generated get method }; %} - +#if defined(SWIGUTL) +%exception { + /* + $action + */ + SWIG_fail; +} +#else %exception { /* $action */ } +#endif %allowexception; %inline %{ diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 89c463c31..7189845e1 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -479,6 +479,13 @@ int Language::constantDirective(Node *n) { if (CurrentClass && (cplus_mode != PUBLIC)) return SWIG_NOWRAP; + if (!GetFlag(n,"feature:allowexcept")) { + UnsetFlag(n,"feature:except"); + } + if (Getattr(n,"feature:exceptvar")) { + Setattr(n,"feature:except",Getattr(n,"feature:exceptvar")); + } + if (!ImportMode) { Swig_require("constantDirective",n,"name", "?value",NIL); String *name = Getattr(n,"name"); @@ -1548,6 +1555,13 @@ int Language::memberconstantHandler(Node *n) { Swig_require("memberconstantHandler",n,"*name","*sym:name","value",NIL); + if (!GetFlag(n,"feature:allowexcept")) { + UnsetFlag(n,"feature:except"); + } + if (Getattr(n,"feature:exceptvar")) { + Setattr(n,"feature:except",Getattr(n,"feature:exceptvar")); + } + String *name = Getattr(n,"name"); String *symname = Getattr(n,"sym:name"); String *value = Getattr(n,"value"); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 7ce24a90b..85d8dc19b 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -844,7 +844,7 @@ public: } /* Now write a function to evaluate the variable */ - + int addfail = 0; Printf(getf->def,"SWIGCLASS_STATIC int %s(pTHX_ SV *sv, MAGIC *SWIGUNUSEDPARM(mg)) {\n", val_name); Printv(getf->code, tab4, "MAGIC_PPERL\n", @@ -860,15 +860,17 @@ public: Replaceall(tm, "$shadow", "0"); } /* Printf(getf->code,"%s\n", tm);*/ - emit_action_code(n, getf, tm); + addfail = emit_action_code(n, getf, tm); } else { Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t,0)); return SWIG_NOWRAP; } Printf(getf->code," return 1;\n"); - Append(getf->code,"fail:\n"); - Append(getf->code," return 0;\n"); + if (addfail) { + Append(getf->code,"fail:\n"); + Append(getf->code," return 0;\n"); + } Append(getf->code,"}\n"); diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 9f586401f..55ccfda0e 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1393,7 +1393,7 @@ public: String *tmp = NewString(""); String *dispatch; - const char *dispatch_code = funpack ? "return %s(self, argv);" : "return %s(self, args);"; + const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);"; if (castmode) { dispatch = Swig_overload_dispatch_cast(n,dispatch_code,&maxargs); @@ -1737,11 +1737,12 @@ public: if (overname) { if (noargs) { Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); + "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL); } else{ Printv(f->def, "SWIGINTERN PyObject *", wname, - "(PyObject *SWIGUNUSEDPARM(self), PyObject **swig_obj) {", NIL); + "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {", NIL); } + Printf(parse_args,"if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments); } else { if (noargs) { Printv(f->def, "SWIGINTERN PyObject *", wname, @@ -1751,12 +1752,13 @@ public: "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); } if (onearg) { - Printf(parse_args,"if (!args) { SWIG_fail; } else { swig_obj[0] = args; }\n"); + Printf(parse_args,"if (!args) SWIG_fail;\n"); + Printf(parse_args,"swig_obj[0] = args;\n"); } else if (!noargs) { - Printf(parse_args,"if(!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", + Printf(parse_args,"if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,swig_obj)) SWIG_fail;\n", iname, num_required, num_arguments); } else if (noargs) { - Printf(parse_args,"if(!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", + Printf(parse_args,"if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_required, num_arguments); } } @@ -2129,7 +2131,6 @@ public: setnamef = Swig_name_set(iname); /* Create a function for setting the value of the variable */ - if (assignable) { Printf(setf->def,"SWIGINTERN int %s(PyObject *_val) {", setnamef); if ((tm = Swig_typemap_lookup_new("varin",n,name,0))) { @@ -2165,22 +2166,24 @@ public: Wrapper_print(setf,f_wrappers); /* Create a function for getting the value of a variable */ + int addfail = 0; Printf(getf->def,"SWIGINTERN PyObject *%s(void) {", getnamef); Wrapper_add_local(getf,"pyobj", "PyObject *pyobj = 0"); if ((tm = Swig_typemap_lookup_new("varout",n,name,0))) { Replaceall(tm,"$source",name); Replaceall(tm,"$target","pyobj"); Replaceall(tm,"$result","pyobj"); - emit_action_code(n, getf, tm); + addfail = emit_action_code(n, getf, tm); Delete(tm); } else { Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t,0)); } - Append(getf->code," return pyobj;\n"); - Append(getf->code,"fail:\n"); - Append(getf->code," return NULL;\n"); + if (addfail) { + Append(getf->code,"fail:\n"); + Append(getf->code," return NULL;\n"); + } Append(getf->code,"}\n"); Wrapper_print(getf,f_wrappers); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index bc89eea37..d111292cc 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1426,6 +1426,7 @@ public: setf = NewWrapper(); /* create getter */ + int addfail = 0; getfname = Swig_name_get(iname); Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL); Printf(getf->def, "VALUE self"); @@ -1438,14 +1439,16 @@ public: Replaceall(tm,"$target","_val"); Replaceall(tm,"$source",name); /* Printv(getf->code,tm, NIL); */ - emit_action_code(n, getf, tm); + addfail = emit_action_code(n, getf, tm); } else { Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(t,0)); } Printv(getf->code, tab4, "return _val;\n", NIL); - Append(getf->code,"fail:\n"); - Append(getf->code," return Qnil;\n"); + if (addfail) { + Append(getf->code,"fail:\n"); + Append(getf->code," return Qnil;\n"); + } Append(getf->code,"}\n"); Wrapper_print(getf,f_wrappers); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 86cb52708..9986d88cc 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -574,6 +574,7 @@ public: if (!addSymbol(iname,n)) return SWIG_ERROR; /* Create a function for getting a variable */ + int addfail = 0; getf = NewWrapper(); getname = Swig_name_get(iname); Printv(getf->def,"SWIGINTERN char *",getname,"(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, char *name1, char *name2, int flags) {",NIL); @@ -583,14 +584,16 @@ public: Replaceall(tm,"$target","value"); Replaceall(tm,"$result", "value"); /* Printf(getf->code, "%s\n",tm); */ - emit_action_code(n, getf, tm); + addfail = emit_action_code(n, getf, tm); Printf(getf->code, "if (value) {\n"); Printf(getf->code, "Tcl_SetVar2(interp,name1,name2,Tcl_GetStringFromObj(value,NULL), flags);\n"); Printf(getf->code, "Tcl_DecrRefCount(value);\n"); Printf(getf->code, "}\n"); Printf(getf->code, "return NULL;\n"); - Append(getf->code,"fail:\n"); - Printf(getf->code,"return \"%s\";\n", iname); + if (addfail) { + Append(getf->code,"fail:\n"); + Printf(getf->code,"return \"%s\";\n", iname); + } Printf(getf->code,"}\n"); Wrapper_print(getf,f_wrappers); } else {