diff --git a/Source/Modules/emit.cxx b/Source/Modules/emit.cxx index c97e434c0..e32f4aea8 100644 --- a/Source/Modules/emit.cxx +++ b/Source/Modules/emit.cxx @@ -339,6 +339,23 @@ void replace_contract_args(Parm *cp, Parm *rp, String *s) { * * Emits action code for a wrapper and checks for exception handling * ----------------------------------------------------------------------------- */ +int emit_action_code(Node *n, Wrapper *f, String *eaction) { + /* Look for except feature */ + String *tm = GetFlagAttr(n,"feature:except"); + if (tm) tm = Copy(tm); + if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) { + Replaceall(tm,"$name",Getattr(n,"name")); + Replaceall(tm,"$symname", Getattr(n,"sym:name")); + Replaceall(tm,"$function", eaction); + Replaceall(tm,"$action", eaction); + Printv(f->code,tm,"\n", NIL); + Delete(tm); + return 1; + } else { + Printv(f->code,eaction,"\n", NIL); + return 0; + } +} void emit_action(Node *n, Wrapper *f) { String *tm; @@ -458,22 +475,14 @@ void emit_action(Node *n, Wrapper *f) { /* Look for except typemap (Deprecated) */ tm = Swig_typemap_lookup_new("except",n,"result",0); - - /* Look for except feature */ - if (!tm) { - tm = GetFlagAttr(n,"feature:except"); - if (tm) tm = Copy(tm); - } - if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) { - Replaceall(tm,"$name",Getattr(n,"name")); - Replaceall(tm,"$symname", Getattr(n,"sym:name")); - Replaceall(tm,"$function", eaction); - Replaceall(tm,"$action", eaction); - Printv(f->code,tm,"\n", NIL); - Delete(tm); - } else { - Printv(f->code,eaction,"\n",NIL); + if (tm) { + Setattr(n,"feature:except", tm); + tm = 0; } + + /* emit the except feature code */ + emit_action_code(n, f, eaction); + Delete(eaction); /* Emit contract code (if any) */ @@ -486,3 +495,5 @@ void emit_action(Node *n, Wrapper *f) { } } + + diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 8750dba3b..59226d61e 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -1261,7 +1261,8 @@ public: Replaceall(tm,"$source","s_0"); Replaceall(tm,"$input","s_0"); Replaceall(tm,"$target",name); - Printv(f->code,tm,"\n",NIL); + /* Printv(f->code,tm,"\n",NIL); */ + emit_action_code(n, f, tm); } else { throw_unhandled_guile_type_error (t); @@ -1276,7 +1277,8 @@ public: Replaceall(tm,"$source",name); Replaceall(tm,"$target","gswig_result"); Replaceall(tm,"$result", "gswig_result"); - Printv(f->code,tm,"\n",NIL); + /* Printv(f->code,tm,"\n",NIL); */ + emit_action_code(n, f, tm); } else { throw_unhandled_guile_type_error (t); diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx index 5f0cb3437..3f6b9cb8e 100644 --- a/Source/Modules/mzscheme.cxx +++ b/Source/Modules/mzscheme.cxx @@ -506,7 +506,8 @@ public: Replaceall(tm,"$source","argv[0]"); Replaceall(tm,"$target",name); Replaceall(tm,"$input","argv[0]"); - Printv(f->code, tm, "\n",NIL); + /* Printv(f->code, tm, "\n",NIL); */ + emit_action_code(n, f, tm); } else { throw_unhandled_mzscheme_type_error (t); @@ -521,7 +522,8 @@ public: Replaceall(tm,"$source",name); Replaceall(tm,"$target","swig_result"); Replaceall(tm,"$result","swig_result"); - Printf (f->code, "%s\n", tm); + /* Printf (f->code, "%s\n", tm); */ + emit_action_code(n, f, tm); } else { throw_unhandled_mzscheme_type_error (t); diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx index 5d5e7ec83..f79a6092c 100755 --- a/Source/Modules/ocaml.cxx +++ b/Source/Modules/ocaml.cxx @@ -886,7 +886,8 @@ public: Replaceall(tm,"$source","args"); Replaceall(tm,"$target",name); Replaceall(tm,"$input","args"); - Printv(f->code, tm, "\n",NIL); + /* Printv(f->code, tm, "\n",NIL); */ + emit_action_code(n, f, tm); } else if ((tm = Swig_typemap_lookup_new("in",n,name,0))) { Replaceall(tm,"$source","args"); Replaceall(tm,"$target",name); @@ -905,7 +906,8 @@ public: Replaceall(tm,"$source",name); Replaceall(tm,"$target","swig_result"); Replaceall(tm,"$result","swig_result"); - Printf (f->code, "%s\n", tm); + /* Printf (f->code, "%s\n", tm); */ + emit_action_code(n, f, tm); } else if ((tm = Swig_typemap_lookup_new("out",n,name,0))) { Replaceall(tm,"$source",name); Replaceall(tm,"$target","swig_result"); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 9bce554c8..58b61d4e2 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -831,7 +831,8 @@ public: Replaceall(tm,"$source","sv"); Replaceall(tm,"$target",name); Replaceall(tm,"$input","sv"); - Printf(setf->code,"%s\n", tm); + /* Printf(setf->code,"%s\n", tm); */ + emit_action_code(n, setf, tm); } else { Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(t,0)); @@ -860,7 +861,8 @@ public: } else { Replaceall(tm, "$shadow", "0"); } - Printf(getf->code,"%s\n", tm); + /* Printf(getf->code,"%s\n", tm);*/ + 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)); diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 337051672..216049601 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -1437,7 +1437,8 @@ public: Replaceall(tm,"$result","_val"); Replaceall(tm,"$target","_val"); Replaceall(tm,"$source",name); - Printv(getf->code,tm, NIL); + /* Printv(getf->code,tm, NIL); */ + 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)); @@ -1451,14 +1452,14 @@ public: /* create setter */ setfname = Swig_name_set(iname); Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL); - Printf(setf->def, "VALUE _val) {"); - + Printf(setf->def, "VALUE _val) {"); tm = Swig_typemap_lookup_new("varin",n,name,0); if (tm) { Replaceall(tm,"$input","_val"); Replaceall(tm,"$source","_val"); Replaceall(tm,"$target",name); - Printv(setf->code,tm,"\n",NIL); + /* Printv(setf->code,tm,"\n",NIL); */ + emit_action_code(n, setf, tm); } else { Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s\n", SwigType_str(t,0)); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 985d0ebb8..cb87f1158 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -583,7 +583,8 @@ public: Replaceall(tm,"$source", name); Replaceall(tm,"$target","value"); Replaceall(tm,"$result", "value"); - Printf(getf->code, "%s\n",tm); + /* Printf(getf->code, "%s\n",tm); */ + 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"); @@ -615,7 +616,8 @@ public: Printf(setf->code,"value = Tcl_ObjGetVar2(interp, name1o, 0, flags);\n"); Printf(setf->code,"Tcl_DecrRefCount(name1o);\n"); Printf(setf->code,"if (!value) SWIG_fail;\n"); - Printf(setf->code,"%s\n", tm); + /* Printf(setf->code,"%s\n", tm);*/ + emit_action_code(n, setf, tm); Printf(setf->code,"return NULL;\n"); Printf(setf->code,"fail:\n"); Printf(setf->code,"return \"%s\";\n", iname);