diff --git a/CHANGES.current b/CHANGES.current index aaa7475eb..42a2be6e7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.4.0 (in progress) =========================== +2024-10-25: olly + [Guile] Allow wrapping anything with a `varout` typemap as a + constant. + 2024-10-24: olly [Perl] https://sourceforge.net/p/swig/bugs/1134/ Ensure C++ local variables get destroyed before throwing a Perl exception. diff --git a/Examples/test-suite/constant_directive.i b/Examples/test-suite/constant_directive.i index 9789fa1d3..cc6a72ba0 100644 --- a/Examples/test-suite/constant_directive.i +++ b/Examples/test-suite/constant_directive.i @@ -3,10 +3,8 @@ // %constant and struct #ifdef SWIGGUILE -// Suppress warnings for function pointer constants which SWIG/Guile doesn't +// Suppress warning for function pointer constant which SWIG/Guile doesn't // currently handle. -%warnfilter(SWIGWARN_TYPEMAP_CONST_UNDEF) TYPE1_CONSTANT1; -%warnfilter(SWIGWARN_TYPEMAP_CONST_UNDEF) TYPE1_CONSTANT2; %warnfilter(SWIGWARN_TYPEMAP_CONST_UNDEF) TYPE1CFPTR1DEF_CONSTANT1; #endif diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 224e68db7..97517df79 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -1,12 +1,6 @@ %module li_std_string %include -#ifdef SWIGGUILE -// Suppress warnings for constants SWIG/Guile doesn't currently handle. -%warnfilter(SWIGWARN_TYPEMAP_CONST_UNDEF) MY_STRING; -%warnfilter(SWIGWARN_TYPEMAP_CONST_UNDEF) MY_STRING_2; -#endif - #if defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGUTL) %apply std::string& INPUT { std::string &input } %apply std::string& INOUT { std::string &inout } diff --git a/Examples/test-suite/schemerunme/li_std_string.scm b/Examples/test-suite/schemerunme/li_std_string.scm index c598de991..383d9b688 100644 --- a/Examples/test-suite/schemerunme/li_std_string.scm +++ b/Examples/test-suite/schemerunme/li_std_string.scm @@ -61,4 +61,11 @@ (if (not (string=? (get-null (stdstring-empty)) "non-null")) (error "get-null stdstring-empty test")) +(if (not (string=? (aString) "something")) + (error "aString test")) +(if (not (string=? (MY-STRING) "")) + (error "MY-STRING test")) +(if (not (string=? (MY-STRING-2) "OK")) + (error "MY-STRING-2 test")) + (exit 0) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 403949df1..4e7635e9e 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -12,6 +12,7 @@ * ----------------------------------------------------------------------------- */ #include "swigmod.h" +#include #include // Note string broken in half for compilers that can't handle long strings @@ -1093,8 +1094,7 @@ public: int assignable = !is_immutable(n); - if (1 || (SwigType_type(t) != T_USER) || (is_a_pointer(t))) { - + { Printf(f->def, "static SCM\n%s(SCM s_0)\n{\n", var_name); /* Define the scheme name in C. This define is used by several Guile @@ -1111,6 +1111,8 @@ public: /* Printv(f->code,tm,"\n",NIL); */ emit_action_code(n, f->code, tm); } else { + // The fake variable constantWrapper() creates is immutable. + assert(!GetFlag(n, "guile:reallywrappingaconstant")); throw_unhandled_guile_type_error(t); } Printf(f->code, "}\n"); @@ -1123,6 +1125,12 @@ public: /* Printv(f->code,tm,"\n",NIL); */ emit_action_code(n, f->code, tm); } else { + if (GetFlag(n, "guile:reallywrappingaconstant")) { + Delete(var_name); + Delete(proc_name); + DelWrapper(f); + return SWIG_ERROR; + } throw_unhandled_guile_type_error(t); } Printf(f->code, "\nreturn gswig_result;\n"); @@ -1241,9 +1249,6 @@ public: Delete(signature2); Delete(doc); } - - } else { - Swig_warning(WARN_TYPEMAP_VAR_UNDEF, input_file, line_number, "Unsupported variable type %s (ignored).\n", SwigType_str(t, 0)); } Delete(var_name); Delete(proc_name); @@ -1286,12 +1291,6 @@ public: proc_name = NewString(iname); Replaceall(proc_name, "_", "-"); - if ((SwigType_type(nctype) == T_USER) && (!is_a_pointer(nctype))) { - Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); - Delete(var_name); - DelWrapper(f); - return SWIG_NOWRAP; - } // See if there's a typemap if ((tm = Swig_typemap_lookup("constant", n, name, 0))) { @@ -1301,7 +1300,8 @@ public: // Create variable and assign it a value Printf(f_header, "static %s = (%s)(%s);\n", SwigType_str(type, var_name), SwigType_str(type, 0), value); } - { + int result = SWIG_OK; + if (Len(nctype) > 0) { /* Hack alert: will cleanup later -- Dave */ Node *nn = NewHash(); Setfile(nn, Getfile(n)); @@ -1313,14 +1313,22 @@ public: if (constasvar) { SetFlag(nn, "feature:constasvar"); } - variableWrapper(nn); + SetFlag(nn, "guile:reallywrappingaconstant"); + if (variableWrapper(nn) == SWIG_ERROR) { + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + result = SWIG_NOWRAP; + } + Delete(nn); + } else { + Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n"); + result = SWIG_NOWRAP; } Delete(var_name); Delete(nctype); Delete(proc_name); DelWrapper(f); - return SWIG_OK; + return result; } /* ------------------------------------------------------------