diff --git a/.gitignore b/.gitignore index 8cec1dc..5a3031c 100644 --- a/.gitignore +++ b/.gitignore @@ -24,12 +24,3 @@ swig-2.0.0.tar.gz /swig-3.0.12.tar.gz /swig-4.0.0.tar.gz /swig-4.0.1.tar.gz -/swig-4.0.2.tar.gz -/swig-4.1.0.tar.gz -/swig-4.1.1.tar.gz -/swig-4.2.0.tar.gz -/swig-4.2.1.tar.gz -/swig-4.3.0.tar.gz -/swig-4.3.1.tar.gz -/swig-4.4.0.tar.gz -/swig-4.4.1.tar.gz diff --git a/sources b/sources index f6fe3ce..49043de 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -SHA512 (swig-4.4.1.tar.gz) = 103ddb4a5914f28e6739a006d35042c701e55ba05066acff3f3609befb5f43f253ea717fc41d06c93d8fb187ded4399c12c94665b93dc06d0fb835069391c7c7 +SHA512 (swig-4.0.1.tar.gz) = 595ef01cb83adfa960ceed9c325a9429192549e8d1e9aa3ab35a4301512a61d82e2e89a8c7939c2a5a0811254ea1832a443bd387e11459eb2b0bafc563ad1308 diff --git a/swig-4.0.1-Add-support-for-Ruby-2.7.patch b/swig-4.0.1-Add-support-for-Ruby-2.7.patch new file mode 100644 index 0000000..359422b --- /dev/null +++ b/swig-4.0.1-Add-support-for-Ruby-2.7.patch @@ -0,0 +1,296 @@ +From 00e291b319bd6b58bf061feee3721a58c9c6be32 Mon Sep 17 00:00:00 2001 +From: Thomas Reitmayr +Date: Mon, 30 Dec 2019 20:11:03 +0100 +Subject: [PATCH] Add support for Ruby 2.7 + +This commit fixes the signatures of various callback methods +and cleans up the macro definitions used for casting callbacks. + +Note that the transparent version of the macro RUBY_METHOD_FUNC +is currently masked behind RUBY_DEVEL, see commit +https://github.com/ruby/ruby/commit/1d91feaf13e0ffe04b2dabc6e77e4101b6d0bb07 +In order to still support strict signature checking and prevent +nasty deprecation warnings, the use of RUBY_METHOD_FUNC had to +be replaced with VALUEFUNC. +--- + Lib/ruby/rubyclasses.swg | 14 +++++++------- + Lib/ruby/rubyhead.swg | 26 +++++++++----------------- + Lib/ruby/rubyprimtypes.swg | 15 ++++++++------- + Lib/ruby/rubytracking.swg | 10 +++++----- + Source/Modules/ruby.cxx | 22 +++++++++------------- + 5 files changed, 38 insertions(+), 49 deletions(-) + +diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg +index f7b51bdcc..b345fcebe 100644 +--- a/Lib/ruby/rubyclasses.swg ++++ b/Lib/ruby/rubyclasses.swg +@@ -174,7 +174,7 @@ namespace swig { + return rb_inspect(_obj); + } + +- static VALUE swig_rescue_swallow(VALUE) ++ static VALUE swig_rescue_swallow(VALUE, VALUE) + { + /* + VALUE errstr = rb_obj_as_string(rb_errinfo()); +@@ -203,8 +203,8 @@ namespace swig { + args.id = op_id; + args.nargs = 1; + args.target = VALUE(other); +- ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), +- (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); ++ ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args), ++ (VALUEFUNC(swig_rescue_swallow)), Qnil); + } + if (ret == Qnil) { + VALUE a = rb_funcall( _obj, hash_id, 0 ); +@@ -243,8 +243,8 @@ namespace swig { + args.id = op_id; + args.nargs = 0; + args.target = Qnil; +- ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), +- (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); ++ ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args), ++ (VALUEFUNC(swig_rescue_swallow)), Qnil); + SWIG_RUBY_THREAD_END_BLOCK; + return ret; + } +@@ -262,8 +262,8 @@ namespace swig { + args.id = op_id; + args.nargs = 1; + args.target = VALUE(other); +- ret = rb_rescue(RUBY_METHOD_FUNC(swig_rescue_funcall), VALUE(&args), +- (RUBY_METHOD_FUNC(swig_rescue_swallow)), Qnil); ++ ret = rb_rescue(VALUEFUNC(swig_rescue_funcall), VALUE(&args), ++ (VALUEFUNC(swig_rescue_swallow)), Qnil); + SWIG_RUBY_THREAD_END_BLOCK; + return GC_VALUE(ret); + } +diff --git a/Lib/ruby/rubyhead.swg b/Lib/ruby/rubyhead.swg +index 90f07cf68..9a0400eea 100644 +--- a/Lib/ruby/rubyhead.swg ++++ b/Lib/ruby/rubyhead.swg +@@ -110,26 +110,18 @@ + * can be passed as an argument to API functions like Data_Wrap_Struct() + * and Data_Make_Struct(). + */ +- +-#ifdef __cplusplus +-# ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */ +-# define PROTECTFUNC(f) ((VALUE (*)()) f) +-# define VALUEFUNC(f) ((VALUE (*)()) f) +-# define VOIDFUNC(f) ((void (*)()) f) +-# else +-# ifndef ANYARGS /* These definitions should work for Ruby 1.6 */ +-# define PROTECTFUNC(f) ((VALUE (*)()) f) +-# define VALUEFUNC(f) ((VALUE (*)()) f) +-# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) +-# else /* These definitions should work for Ruby 1.7+ */ +-# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f) +-# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f) +-# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) +-# endif +-# endif ++#if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL) ++# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f) ++# define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f) ++# define VOIDFUNC(f) ((RUBY_DATA_FUNC) f) ++# define VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f)) ++# define INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f)) + #else ++# define PROTECTFUNC(f) (f) + # define VALUEFUNC(f) (f) + # define VOIDFUNC(f) (f) ++# define VOID_ANYARGS_FUNC(f) (f) ++# define INT_ANYARGS_FUNC(f) (f) + #endif + + /* Don't use for expressions have side effect */ +diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg +index 3a848191c..4b078deea 100644 +--- a/Lib/ruby/rubyprimtypes.swg ++++ b/Lib/ruby/rubyprimtypes.swg +@@ -10,15 +10,16 @@ + %fragment("SWIG_ruby_failed","header") + { + SWIGINTERN VALUE +-SWIG_ruby_failed(void) ++SWIG_ruby_failed(VALUE SWIGUNUSEDPARM(arg1), VALUE SWIGUNUSEDPARM(arg2)) + { + return Qnil; + } + } + + %define %ruby_aux_method(Type, Method, Action) +-SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE *args) ++SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE arg) + { ++ VALUE *args = (VALUE *)arg; + VALUE obj = args[0]; + VALUE type = TYPE(obj); + Type *res = (Type *)(args[1]); +@@ -79,7 +80,7 @@ SWIG_AsVal_dec(long)(VALUE obj, long* val) + VALUE a[2]; + a[0] = obj; + a[1] = (VALUE)(&v); +- if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) { ++ if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2LONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { + if (val) *val = v; + return SWIG_OK; + } +@@ -111,7 +112,7 @@ SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val) + VALUE a[2]; + a[0] = obj; + a[1] = (VALUE)(&v); +- if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) { ++ if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { + if (val) *val = v; + return SWIG_OK; + } +@@ -149,7 +150,7 @@ SWIG_AsVal_dec(long long)(VALUE obj, long long *val) + VALUE a[2]; + a[0] = obj; + a[1] = (VALUE)(&v); +- if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) { ++ if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2LL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { + if (val) *val = v; + return SWIG_OK; + } +@@ -187,7 +188,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val) + VALUE a[2]; + a[0] = obj; + a[1] = (VALUE)(&v); +- if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) { ++ if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2ULL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { + if (val) *val = v; + return SWIG_OK; + } +@@ -215,7 +216,7 @@ SWIG_AsVal_dec(double)(VALUE obj, double *val) + VALUE a[2]; + a[0] = obj; + a[1] = (VALUE)(&v); +- if (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2DBL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) { ++ if (rb_rescue(VALUEFUNC(SWIG_AUX_NUM2DBL), (VALUE)a, VALUEFUNC(SWIG_ruby_failed), 0) != Qnil) { + if (val) *val = v; + return SWIG_OK; + } +diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg +index b9fb249d8..221a68193 100644 +--- a/Lib/ruby/rubytracking.swg ++++ b/Lib/ruby/rubytracking.swg +@@ -32,7 +32,7 @@ extern "C" { + */ + static st_table* swig_ruby_trackings = NULL; + +-static VALUE swig_ruby_trackings_count(ANYARGS) { ++static VALUE swig_ruby_trackings_count(ID id, VALUE *var) { + return SWIG2NUM(swig_ruby_trackings->num_entries); + } + +@@ -69,7 +69,7 @@ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { + swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value); + } + +- rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL); ++ rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", VALUEFUNC(swig_ruby_trackings_count), VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL)); + } + + /* Add a Tracking from a C/C++ struct to a Ruby object */ +@@ -118,13 +118,13 @@ SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) { + to the passed callback function. */ + + /* Proxy method to abstract the internal trackings datatype */ +-static int swig_ruby_internal_iterate_callback(void* ptr, VALUE obj, void(*meth)(void* ptr, VALUE obj)) { +- (*meth)(ptr, obj); ++static int swig_ruby_internal_iterate_callback(st_data_t ptr, st_data_t obj, st_data_t meth) { ++ ((void (*) (void *, VALUE))meth)((void *)ptr, (VALUE)obj); + return ST_CONTINUE; + } + + SWIGRUNTIME void SWIG_RubyIterateTrackings( void(*meth)(void* ptr, VALUE obj) ) { +- st_foreach(swig_ruby_trackings, (int (*)(ANYARGS))&swig_ruby_internal_iterate_callback, (st_data_t)meth); ++ st_foreach(swig_ruby_trackings, INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback), (st_data_t)meth); + } + + #ifdef __cplusplus +diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx +index c8f582679..01b75befa 100644 +--- a/Source/Modules/ruby.cxx ++++ b/Source/Modules/ruby.cxx +@@ -2191,6 +2191,7 @@ public: + String *tm; + String *getfname, *setfname; + Wrapper *getf, *setf; ++ const int assignable = is_assignable(n); + + // Determine whether virtual global variables shall be used + // which have different getter and setter signatures, +@@ -2206,7 +2207,7 @@ public: + getfname = Swig_name_wrapper(getname); + Setattr(n, "wrap:name", getfname); + Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL); +- Printf(getf->def, (use_virtual_var) ? "ID id" : "VALUE self"); ++ Printf(getf->def, (use_virtual_var) ? "ID id, VALUE *data" : "VALUE self"); + Printf(getf->def, ") {"); + Wrapper_add_local(getf, "_val", "VALUE _val"); + +@@ -2229,8 +2230,8 @@ public: + + Wrapper_print(getf, f_wrappers); + +- if (!is_assignable(n)) { +- setfname = NewString("NULL"); ++ if (!assignable) { ++ setfname = NewString("(rb_gvar_setter_t *)NULL"); + } else { + /* create setter */ + String* docs = docstring(n, AUTODOC_SETTER); +@@ -2242,7 +2243,7 @@ public: + Setattr(n, "wrap:name", setfname); + Printf(setf->def, "SWIGINTERN "); + if (use_virtual_var) { +- Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id) {", NIL); ++ Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id, VALUE *data) {", NIL); + } else { + Printv(setf->def, "VALUE\n", setfname, "(VALUE self, VALUE _val) {", NIL); + } +@@ -2273,7 +2274,7 @@ public: + if (CPlusPlus) { + Insert(getfname, 0, "VALUEFUNC("); + Append(getfname, ")"); +- Insert(setfname, 0, (use_virtual_var) ? "(void (*)(ANYARGS))(" : "VALUEFUNC("); ++ Insert(setfname, 0, (use_virtual_var) ? "VOID_ANYARGS_FUNC(" : "VALUEFUNC("); + Append(setfname, ")"); + } + +@@ -2282,7 +2283,7 @@ public: + case STATIC_VAR: + /* C++ class variable */ + Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "\", ", getfname, ", 0);\n", NIL); +- if (!GetFlag(n, "feature:immutable")) { ++ if (assignable) { + Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"", klass->strip(iname), "=\", ", setfname, ", 1);\n", NIL); + } + Printv(klass->init, s, NIL); +@@ -2293,16 +2294,11 @@ public: + assert(current == NO_CPP); + if (!useGlobalModule) { + Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "\", ", getfname, ", 0);\n", NIL); +- if (!GetFlag(n, "feature:immutable")) { ++ if (assignable) { + Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "=\", ", setfname, ", 1);\n", NIL); + } + } else { +- Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", NIL); +- if (GetFlag(n, "feature:immutable")) { +- Printv(s, tab4, "0);\n", NIL); +- } else { +- Printv(s, tab4, setfname, ");\n", NIL); +- } ++ Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", setfname, ");\n", NIL); + } + Printv(f_init, s, NIL); + Delete(s); +-- +2.21.1 + diff --git a/swig-4.0.1-Fix-code-generated-for-Ruby-global-variables.patch b/swig-4.0.1-Fix-code-generated-for-Ruby-global-variables.patch new file mode 100644 index 0000000..7e24cb8 --- /dev/null +++ b/swig-4.0.1-Fix-code-generated-for-Ruby-global-variables.patch @@ -0,0 +1,534 @@ +From 18a3ef391121d7c4d819448c929721fd1708b40b Mon Sep 17 00:00:00 2001 +From: Thomas Reitmayr +Date: Sun, 27 Oct 2019 21:41:03 +0100 +Subject: [PATCH] Fix code generated for Ruby global variables + +This commit fixes swig#1653 by creating a Ruby virtual variable +for a C/c++ global variable when SWIG is invoked with the +-globalmodule option. +--- + Doc/Manual/Ruby.html | 18 +++++++ + Examples/test-suite/common.mk | 2 + + Examples/test-suite/global_immutable_vars.i | 24 +++++++++ + .../test-suite/global_immutable_vars_cpp.i | 24 +++++++++ + Examples/test-suite/ruby/Makefile.in | 4 ++ + .../ruby/global_immutable_vars_cpp_runme.rb | 47 +++++++++++++++++ + .../ruby/global_immutable_vars_runme.rb | 51 +++++++++++++++++++ + .../ruby_global_immutable_vars_cpp_runme.rb | 47 +++++++++++++++++ + .../ruby/ruby_global_immutable_vars_runme.rb | 51 +++++++++++++++++++ + .../test-suite/ruby_global_immutable_vars.i | 25 +++++++++ + .../ruby_global_immutable_vars_cpp.i | 23 +++++++++ + Source/Modules/ruby.cxx | 36 +++++++++---- + 12 files changed, 342 insertions(+), 10 deletions(-) + create mode 100644 Examples/test-suite/global_immutable_vars.i + create mode 100644 Examples/test-suite/global_immutable_vars_cpp.i + create mode 100644 Examples/test-suite/ruby/global_immutable_vars_cpp_runme.rb + create mode 100644 Examples/test-suite/ruby/global_immutable_vars_runme.rb + create mode 100644 Examples/test-suite/ruby/ruby_global_immutable_vars_cpp_runme.rb + create mode 100644 Examples/test-suite/ruby/ruby_global_immutable_vars_runme.rb + create mode 100644 Examples/test-suite/ruby_global_immutable_vars.i + create mode 100644 Examples/test-suite/ruby_global_immutable_vars_cpp.i + +diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html +index 3cfd1292c..6939a8a18 100644 +--- a/Doc/Manual/Ruby.html ++++ b/Doc/Manual/Ruby.html +@@ -615,6 +615,24 @@ directive. For example:

+ effect until it is explicitly disabled using %mutable. +

+ ++

Note: When SWIG is invoked with the -globalmodule option in ++effect, the C/C++ global variables will be translated into Ruby global ++variables. Type-checking and the optional read-only characteristic are ++available in the same way as described above. However the example would ++then have to be modified and executed in the following way: ++ ++

++
$ irb
++irb(main):001:0> require 'Example'
++true
++irb(main):002:0> $variable1 = 2
++2
++irb(main):003:0> $Variable2 = 4 * 10.3
++41.2
++irb(main):004:0> $Variable2
++41.2
++
++ +

34.3.4 Constants

+ + +diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk +index 5f7792810..008916a56 100644 +--- a/Examples/test-suite/common.mk ++++ b/Examples/test-suite/common.mk +@@ -250,6 +250,7 @@ CPP_TEST_CASES += \ + funcptr_cpp \ + functors \ + fvirtual \ ++ global_immutable_vars_cpp \ + global_namespace \ + global_ns_arg \ + global_scope_types \ +@@ -689,6 +690,7 @@ C_TEST_CASES += \ + funcptr \ + function_typedef \ + global_functions \ ++ global_immutable_vars \ + immutable_values \ + inctest \ + infinity \ +diff --git a/Examples/test-suite/global_immutable_vars.i b/Examples/test-suite/global_immutable_vars.i +new file mode 100644 +index 000000000..cd8cb184b +--- /dev/null ++++ b/Examples/test-suite/global_immutable_vars.i +@@ -0,0 +1,24 @@ ++%module global_immutable_vars ++ ++// Test immutable and mutable global variables, ++// see http://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables ++ ++%inline %{ ++ int default_mutable_var = 40; ++%} ++ ++%immutable; ++%feature("immutable", "0") specific_mutable_var; ++ ++%inline %{ ++ int global_immutable_var = 41; ++ int specific_mutable_var = 42; ++%} ++ ++%mutable; ++%immutable specific_immutable_var; ++%inline %{ ++ int global_mutable_var = 43; ++ int specific_immutable_var = 44; ++%} ++ +diff --git a/Examples/test-suite/global_immutable_vars_cpp.i b/Examples/test-suite/global_immutable_vars_cpp.i +new file mode 100644 +index 000000000..66eb8545d +--- /dev/null ++++ b/Examples/test-suite/global_immutable_vars_cpp.i +@@ -0,0 +1,24 @@ ++%module global_immutable_vars_cpp ++ ++// Test immutable and mutable global variables, ++// see http://www.swig.org/Doc4.0/SWIGDocumentation.html#SWIG_readonly_variables ++ ++%inline %{ ++ int default_mutable_var = 40; ++%} ++ ++%immutable; ++%feature("immutable", "0") specific_mutable_var; ++ ++%inline %{ ++ int global_immutable_var = 41; ++ int specific_mutable_var = 42; ++%} ++ ++%mutable; ++%immutable specific_immutable_var; ++%inline %{ ++ int global_mutable_var = 43; ++ int specific_immutable_var = 44; ++%} ++ +diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in +index d75cdb058..2c59029ec 100644 +--- a/Examples/test-suite/ruby/Makefile.in ++++ b/Examples/test-suite/ruby/Makefile.in +@@ -23,6 +23,7 @@ CPP_TEST_CASES = \ + li_std_wstring_inherit \ + primitive_types \ + ruby_alias_method \ ++ ruby_global_immutable_vars_cpp \ + ruby_keywords \ + ruby_minherit_shared_ptr \ + ruby_naming \ +@@ -48,6 +49,7 @@ C_TEST_CASES += \ + li_cstring \ + ruby_alias_global_function \ + ruby_alias_module_function \ ++ ruby_global_immutable_vars \ + ruby_manual_proxy \ + + include $(srcdir)/../common.mk +@@ -57,6 +59,8 @@ SWIGOPT += -w801 -noautorename -features autodoc=4 + + # Custom tests - tests with additional commandline options + ruby_alias_global_function.ctest: SWIGOPT += -globalmodule ++ruby_global_immutable_vars.ctest: SWIGOPT += -globalmodule ++ruby_global_immutable_vars_cpp.cpptest: SWIGOPT += -globalmodule + ruby_naming.cpptest: SWIGOPT += -autorename + + # Rules for the different types of tests +diff --git a/Examples/test-suite/ruby/global_immutable_vars_cpp_runme.rb b/Examples/test-suite/ruby/global_immutable_vars_cpp_runme.rb +new file mode 100644 +index 000000000..c40896a86 +--- /dev/null ++++ b/Examples/test-suite/ruby/global_immutable_vars_cpp_runme.rb +@@ -0,0 +1,47 @@ ++#!/usr/bin/env ruby ++# ++# C++ version of global_immutable_vars_runme.rb ++# ++ ++require 'swig_assert' ++ ++require 'global_immutable_vars_cpp' ++ ++# first check if all variables can be read ++swig_assert_each_line( < e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "Global_immutable_vars_cpp::global_immutable_var is writable (expected to be immutable)") ++ ++had_exception = false ++begin ++ Global_immutable_vars_cpp::specific_immutable_var = 81 ++rescue NoMethodError => e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "Global_immutable_vars_cpp::specific_immutable_var is writable (expected to be immutable)") ++ +diff --git a/Examples/test-suite/ruby/global_immutable_vars_runme.rb b/Examples/test-suite/ruby/global_immutable_vars_runme.rb +new file mode 100644 +index 000000000..af55cfeb3 +--- /dev/null ++++ b/Examples/test-suite/ruby/global_immutable_vars_runme.rb +@@ -0,0 +1,51 @@ ++#!/usr/bin/env ruby ++# ++# Here the proper generation of mutable and immutable variables is tested ++# in the target language. ++# Immutable variables do not have "=" methods generated by SWIG, ++# therefore trying to assign these variables shall throw a NoMethodError ++# exception. ++# ++ ++require 'swig_assert' ++ ++require 'global_immutable_vars' ++ ++# first check if all variables can be read ++swig_assert_each_line( < e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "Global_immutable_vars::global_immutable_var is writable (expected to be immutable)") ++ ++had_exception = false ++begin ++ Global_immutable_vars::specific_immutable_var = 81 ++rescue NoMethodError => e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "Global_immutable_vars::specific_immutable_var is writable (expected to be immutable)") ++ +diff --git a/Examples/test-suite/ruby/ruby_global_immutable_vars_cpp_runme.rb b/Examples/test-suite/ruby/ruby_global_immutable_vars_cpp_runme.rb +new file mode 100644 +index 000000000..8453254eb +--- /dev/null ++++ b/Examples/test-suite/ruby/ruby_global_immutable_vars_cpp_runme.rb +@@ -0,0 +1,47 @@ ++#!/usr/bin/env ruby ++# ++# C++ version of ruby_global_immutable_vars_runme.rb. ++# ++ ++require 'swig_assert' ++ ++require 'ruby_global_immutable_vars_cpp' ++ ++# first check if all variables can be read ++swig_assert_each_line( < e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "$global_immutable_var is writable (expected to be immutable)") ++ ++had_exception = false ++begin ++ $specific_immutable_var = 81 ++rescue NameError => e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "$specific_immutable_var is writable (expected to be immutable)") ++ +diff --git a/Examples/test-suite/ruby/ruby_global_immutable_vars_runme.rb b/Examples/test-suite/ruby/ruby_global_immutable_vars_runme.rb +new file mode 100644 +index 000000000..fda1ccf0f +--- /dev/null ++++ b/Examples/test-suite/ruby/ruby_global_immutable_vars_runme.rb +@@ -0,0 +1,51 @@ ++#!/usr/bin/env ruby ++# ++# This test program is similar to global_immutable_vars_runme.rb ++# with the difference that the global variables to check are also ++# Ruby global variables (SWIG Ruby option "-globalmodule"). ++# ++# Immutable global variables shall throw a NameError exception. ++# ++ ++require 'swig_assert' ++ ++require 'ruby_global_immutable_vars' ++ ++# first check if all variables can be read ++swig_assert_each_line( < e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "$global_immutable_var is writable (expected to be immutable)") ++ ++had_exception = false ++begin ++ $specific_immutable_var = 81 ++rescue NameError => e ++ had_exception = true ++end ++swig_assert(had_exception, nil, ++ "$specific_immutable_var is writable (expected to be immutable)") ++ +diff --git a/Examples/test-suite/ruby_global_immutable_vars.i b/Examples/test-suite/ruby_global_immutable_vars.i +new file mode 100644 +index 000000000..dc49cd946 +--- /dev/null ++++ b/Examples/test-suite/ruby_global_immutable_vars.i +@@ -0,0 +1,25 @@ ++%module ruby_global_immutable_vars ++ ++// This copy of global_immutable_vars.i shall be compiled with the ++// SWIG Ruby option "-globalmodule" in order to check the code path ++// for registering global methods (in contrast to module methods). ++ ++%inline %{ ++ int default_mutable_var = 40; ++%} ++ ++%immutable; ++%feature("immutable", "0") specific_mutable_var; ++ ++%inline %{ ++ int global_immutable_var = 41; ++ int specific_mutable_var = 42; ++%} ++ ++%mutable; ++%immutable specific_immutable_var; ++%inline %{ ++ int global_mutable_var = 43; ++ int specific_immutable_var = 44; ++%} ++ +diff --git a/Examples/test-suite/ruby_global_immutable_vars_cpp.i b/Examples/test-suite/ruby_global_immutable_vars_cpp.i +new file mode 100644 +index 000000000..cf3145e80 +--- /dev/null ++++ b/Examples/test-suite/ruby_global_immutable_vars_cpp.i +@@ -0,0 +1,23 @@ ++%module ruby_global_immutable_vars_cpp ++ ++// C++ version of ruby_global_immutable_vars.i ++ ++%inline %{ ++ int default_mutable_var = 40; ++%} ++ ++%immutable; ++%feature("immutable", "0") specific_mutable_var; ++ ++%inline %{ ++ int global_immutable_var = 41; ++ int specific_mutable_var = 42; ++%} ++ ++%mutable; ++%immutable specific_immutable_var; ++%inline %{ ++ int global_mutable_var = 43; ++ int specific_immutable_var = 44; ++%} ++ +diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx +index 6a1e16d5d..c8f582679 100644 +--- a/Source/Modules/ruby.cxx ++++ b/Source/Modules/ruby.cxx +@@ -2192,6 +2192,11 @@ public: + String *getfname, *setfname; + Wrapper *getf, *setf; + ++ // Determine whether virtual global variables shall be used ++ // which have different getter and setter signatures, ++ // see https://docs.ruby-lang.org/en/2.6.0/extension_rdoc.html#label-Global+Variables+Shared+Between+C+and+Ruby ++ const bool use_virtual_var = (current == NO_CPP && useGlobalModule); ++ + getf = NewWrapper(); + setf = NewWrapper(); + +@@ -2201,7 +2206,7 @@ public: + getfname = Swig_name_wrapper(getname); + Setattr(n, "wrap:name", getfname); + Printv(getf->def, "SWIGINTERN VALUE\n", getfname, "(", NIL); +- Printf(getf->def, "VALUE self"); ++ Printf(getf->def, (use_virtual_var) ? "ID id" : "VALUE self"); + Printf(getf->def, ") {"); + Wrapper_add_local(getf, "_val", "VALUE _val"); + +@@ -2235,8 +2240,12 @@ public: + String *setname = Swig_name_set(NSPACE_TODO, iname); + setfname = Swig_name_wrapper(setname); + Setattr(n, "wrap:name", setfname); +- Printv(setf->def, "SWIGINTERN VALUE\n", setfname, "(VALUE self, ", NIL); +- Printf(setf->def, "VALUE _val) {"); ++ Printf(setf->def, "SWIGINTERN "); ++ if (use_virtual_var) { ++ Printv(setf->def, "void\n", setfname, "(VALUE _val, ID id) {", NIL); ++ } else { ++ Printv(setf->def, "VALUE\n", setfname, "(VALUE self, VALUE _val) {", NIL); ++ } + tm = Swig_typemap_lookup("varin", n, name, 0); + if (tm) { + Replaceall(tm, "$input", "_val"); +@@ -2247,9 +2256,14 @@ public: + } else { + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s\n", SwigType_str(t, 0)); + } +- Printv(setf->code, tab4, "return _val;\n", NIL); +- Printf(setf->code, "fail:\n"); +- Printv(setf->code, tab4, "return Qnil;\n", NIL); ++ if (use_virtual_var) { ++ Printf(setf->code, "fail:\n"); ++ Printv(setf->code, tab4, "return;\n", NIL); ++ } else { ++ Printv(setf->code, tab4, "return _val;\n", NIL); ++ Printf(setf->code, "fail:\n"); ++ Printv(setf->code, tab4, "return Qnil;\n", NIL); ++ } + Printf(setf->code, "}\n"); + Wrapper_print(setf, f_wrappers); + Delete(setname); +@@ -2259,7 +2273,7 @@ public: + if (CPlusPlus) { + Insert(getfname, 0, "VALUEFUNC("); + Append(getfname, ")"); +- Insert(setfname, 0, "VALUEFUNC("); ++ Insert(setfname, 0, (use_virtual_var) ? "(void (*)(ANYARGS))(" : "VALUEFUNC("); + Append(setfname, ")"); + } + +@@ -2283,9 +2297,11 @@ public: + Printv(s, tab4, "rb_define_singleton_method(", modvar, ", \"", iname, "=\", ", setfname, ", 1);\n", NIL); + } + } else { +- Printv(s, tab4, "rb_define_global_method(\"", iname, "\", ", getfname, ", 0);\n", NIL); +- if (!GetFlag(n, "feature:immutable")) { +- Printv(s, tab4, "rb_define_global_method(\"", iname, "=\", ", setfname, ", 1);\n", NIL); ++ Printv(s, tab4, "rb_define_virtual_variable(\"$", iname, "\", ", getfname, ", ", NIL); ++ if (GetFlag(n, "feature:immutable")) { ++ Printv(s, tab4, "0);\n", NIL); ++ } else { ++ Printv(s, tab4, setfname, ");\n", NIL); + } + } + Printv(f_init, s, NIL); +-- +2.21.1 + diff --git a/swig-4.0.1-Fix-crash-in-Python-backend-when-using-empty-docstrings.patch b/swig-4.0.1-Fix-crash-in-Python-backend-when-using-empty-docstrings.patch new file mode 100644 index 0000000..c9b5ce7 --- /dev/null +++ b/swig-4.0.1-Fix-crash-in-Python-backend-when-using-empty-docstrings.patch @@ -0,0 +1,88 @@ +From e14532ce52a654768cc4010e9e18e1a0a4d965db Mon Sep 17 00:00:00 2001 +From: Vadim Zeitlin +Date: Sat, 25 Jan 2020 17:06:20 +0100 +Subject: [PATCH] Fix crash in Python backend when using empty docstrings + +Due to confusion in build_combined_docstring(), we could call +DohDelete() on the "feature:docstring" string, which resulted in a crash +when trying to use it later. + +Fix this and simplify the code at the same time by ensuring that we +always use a copy of "feature:docstring" if it's not empty or don't use +it at all if it's empty -- like this we don't have to check for its +length each time before using it. + +Closes #1648. +--- + Examples/test-suite/autodoc.i | 9 +++++++++ + Examples/test-suite/python/autodoc_runme.py | 2 ++ + Source/Modules/python.cxx | 15 +++++++++++---- + 3 files changed, 22 insertions(+), 4 deletions(-) + +diff --git a/Examples/test-suite/autodoc.i b/Examples/test-suite/autodoc.i +index 9f4365ee1c..efc7201553 100644 +--- a/Examples/test-suite/autodoc.i ++++ b/Examples/test-suite/autodoc.i +@@ -183,3 +183,12 @@ const int PROCESS_DEFAULT_VALUE = 17; + typedef long int some_type; + int process_complex_defval(int val = PROCESS_DEFAULT_VALUE, int factor = some_type(-1)) { return val*factor; } + %} ++ ++// Test for empty docstring, which should be ignored. ++%feature("docstring") "" ++ ++%inline %{ ++struct a_structure{ ++ char my_array[1]; ++}; ++%} +diff --git a/Examples/test-suite/python/autodoc_runme.py b/Examples/test-suite/python/autodoc_runme.py +index 6002d49fec..7bc918644d 100644 +--- a/Examples/test-suite/python/autodoc_runme.py ++++ b/Examples/test-suite/python/autodoc_runme.py +@@ -279,3 +279,5 @@ def check(got, expected, expected_builtin=None, skip=False): + check(inspect.getdoc(process4), "process4(int _from=0, int _in=1, int var=2) -> int") + + check(inspect.getdoc(process_complex_defval), "process_complex_defval(val=PROCESS_DEFAULT_VALUE, factor=some_type(-1)) -> int") ++ ++check(inspect.getdoc(a_structure.__init__), "__init__(a_structure self) -> a_structure", None, skip) +diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx +index 1dbedad26a..f6b47be244 100644 +--- a/Source/Modules/python.cxx ++++ b/Source/Modules/python.cxx +@@ -1484,8 +1484,15 @@ class PYTHON:public Language { + + String *build_combined_docstring(Node *n, autodoc_t ad_type, const String *indent = "", bool low_level = false) { + String *docstr = Getattr(n, "feature:docstring"); +- if (docstr && Len(docstr)) { +- docstr = Copy(docstr); ++ if (docstr) { ++ // Simplify the code below by just ignoring empty docstrings. ++ if (!Len(docstr)) ++ docstr = NULL; ++ else ++ docstr = Copy(docstr); ++ } ++ ++ if (docstr) { + char *t = Char(docstr); + if (*t == '{') { + Delitem(docstr, 0); +@@ -1496,7 +1503,7 @@ class PYTHON:public Language { + if (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")) { + String *autodoc = make_autodoc(n, ad_type, low_level); + if (autodoc && Len(autodoc) > 0) { +- if (docstr && Len(docstr)) { ++ if (docstr) { + Append(autodoc, "\n"); + Append(autodoc, docstr); + } +@@ -1509,7 +1516,7 @@ class PYTHON:public Language { + Delete(autodoc); + } + +- if (!docstr || !Len(docstr)) { ++ if (!docstr) { + if (doxygen) { + docstr = Getattr(n, "python:docstring"); + if (!docstr && doxygenTranslator->hasDocumentation(n)) { diff --git a/swig-4.0.1-ruby27-minimum.patch b/swig-4.0.1-ruby27-minimum.patch new file mode 100644 index 0000000..4370b35 --- /dev/null +++ b/swig-4.0.1-ruby27-minimum.patch @@ -0,0 +1,11 @@ +--- swig-4.0.1/Lib/ruby/rubytracking.swg.orig 2019-08-21 06:34:03.000000000 +0900 ++++ swig-4.0.1/Lib/ruby/rubytracking.swg 2020-01-18 18:32:38.909450596 +0900 +@@ -69,7 +69,7 @@ SWIGRUNTIME void SWIG_RubyInitializeTrac + swig_ruby_trackings = (st_table*)NUM2SWIG(trackings_value); + } + +- rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", swig_ruby_trackings_count, NULL); ++ rb_define_virtual_variable("SWIG_TRACKINGS_COUNT", (rb_gvar_getter_t *)swig_ruby_trackings_count, (rb_gvar_setter_t *)NULL); + } + + /* Add a Tracking from a C/C++ struct to a Ruby object */ diff --git a/swig-python-Python-3.14-support.patch b/swig-python-Python-3.14-support.patch deleted file mode 100644 index ceee305..0000000 --- a/swig-python-Python-3.14-support.patch +++ /dev/null @@ -1,153 +0,0 @@ -From 50e1cc8bc0d090164762ec166439f8b0f3855308 Mon Sep 17 00:00:00 2001 -From: Julien Schueller -Date: Thu, 10 Apr 2025 17:22:15 +0200 -Subject: [PATCH 1/3] Python: Handle __package__ removal - -Closes #2967 ---- - Doc/Manual/Python.html | 6 +++--- - Source/Modules/python.cxx | 8 +++++--- - 2 files changed, 8 insertions(+), 6 deletions(-) - -diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html -index 23587e5dbcc..01fc449a68a 100644 ---- a/Doc/Manual/Python.html -+++ b/Doc/Manual/Python.html -@@ -6552,7 +6552,7 @@

33.11.6.1 Both modules - -

- In this configuration, the pure Python module, foo.py, tries to load the C/C++ module, _foo, from the same package foo.py is --located in. The package name is determined from the __package__ -+located in. The package name is determined from the __spec__.parent (or __package__ before Python 3.4) - attribute if available, see PEP 366. Otherwise it is derived from the __name__ - attribute given to foo.py by the Python loader that imported foo.py. - The interface file for this configuration would contain: -@@ -6675,7 +6675,7 @@

33.11.6.4 More on customizing the modu - -
-
--if __package__ or '.' in __name__:
-+if getattr(__spec__, "parent", None) or '.' in __name__:
-     from . import _foo
- else:
-     import _foo
-@@ -6760,7 +6760,7 @@ 

33.11.6.4 More on customizing the modu - -
-
--if __package__ or '.' in __name__:
-+if getattr(__spec__, "parent", None) or '.' in __name__:
-     from ._foo import *
- else:
-     from _foo import *
-diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
-index 86daf131c8b..a71fc3cdb25 100644
---- a/Source/Modules/python.cxx
-+++ b/Source/Modules/python.cxx
-@@ -703,20 +703,22 @@ class PYTHON:public Language {
- 	 * onwards (implicit relative imports raised a DeprecationWarning in 2.6,
- 	 * and fail in 2.7 onwards).
- 	 *
--	 * First check for __package__ which is available from 2.6 onwards, see PEP366.
-+	 * First check for __spec__.parent which is available from 3.4 onwards,
-+	 * see https://docs.python.org/3/reference/import.html#spec. If not,
-+	 * check for __package__, which was set before 3.14.
- 	 * Next try determine the shadow wrapper's package based on the __name__ it
- 	 * was given by the importer that loaded it.
- 	 * If the module is in a package, load the low-level C/C++ module from the
- 	 * same package, otherwise load it as a global module.
- 	 */
-         Printv(default_import_code, "# Import the low-level C/C++ module\n", NULL);
--        Printv(default_import_code, "if __package__ or \".\" in __name__:\n", NULL);
-+        Printv(default_import_code, "if getattr(globals().get(\"__spec__\"), \"parent\", None) or globals().get(\"__package__\") or \".\" in __name__:\n", NULL);
-         Printv(default_import_code, tab4, "from . import ", module, "\n", NULL);
-         Printv(default_import_code, "else:\n", NULL);
-         Printv(default_import_code, tab4, "import ", module, "\n", NULL);
-       } else {
-         Printv(default_import_code, "# Pull in all the attributes from the low-level C/C++ module\n", NULL);
--        Printv(default_import_code, "if __package__ or \".\" in __name__:\n", NULL);
-+        Printv(default_import_code, "if getattr(globals().get(\"__spec__\"), \"parent\", None) or globals().get(\"__package__\") or \".\" in __name__:\n", NULL);
-         Printv(default_import_code, tab4, "from .", module, " import *\n", NULL);
-         Printv(default_import_code, "else:\n", NULL);
-         Printv(default_import_code, tab4, "from ", module, " import *\n", NULL);
-
-From 3bfdf13c602f877860a9949ba751a5b5a9ba70aa Mon Sep 17 00:00:00 2001
-From: Julien Schueller 
-Date: Thu, 10 Apr 2025 18:35:25 +0200
-Subject: [PATCH 2/3] Python: Add ht_token
-
----
- Source/Modules/python.cxx | 5 +++++
- 1 file changed, 5 insertions(+)
-
-diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
-index a71fc3cdb25..3070a94face 100644
---- a/Source/Modules/python.cxx
-+++ b/Source/Modules/python.cxx
-@@ -4374,6 +4374,11 @@ class PYTHON:public Language {
-     Printv(f, "#if PY_VERSION_HEX >= 0x030b0000\n", NIL);
-     printSlot(f, getSlot(n, "feature:python:_ht_tpname"), "_ht_tpname", "char *");
- 
-+    // void *ht_token;
-+    Printv(f, "#if PY_VERSION_HEX >= 0x030e0000\n", NIL);
-+    printSlot(f, getSlot(n, "feature:python:ht_token"), "ht_token", "void *");
-+    Printv(f, "#endif\n", NIL);
-+
-     // struct _specialization_cache _spec_cache;
-     Printf(f, "  {\n");
-     printSlot(f, getSlot(n, "feature:python:getitem"), "getitem", "PyObject *");
-
-From 55237efa7219f65a04e0ffc69a81c574b5f5e162 Mon Sep 17 00:00:00 2001
-From: Julien Schueller 
-Date: Thu, 10 Apr 2025 17:47:59 +0200
-Subject: [PATCH 3/3] Python: Amend annotations test
-
----
- .../python_annotations_variable_c_runme.py    | 24 +++++++++++++------
- 1 file changed, 17 insertions(+), 7 deletions(-)
-
-diff --git a/Examples/test-suite/python/python_annotations_variable_c_runme.py b/Examples/test-suite/python/python_annotations_variable_c_runme.py
-index 153852d05e6..d1f359bbbd0 100644
---- a/Examples/test-suite/python/python_annotations_variable_c_runme.py
-+++ b/Examples/test-suite/python/python_annotations_variable_c_runme.py
-@@ -1,4 +1,17 @@
- import sys
-+import inspect
-+
-+
-+def get_annotations(cls):
-+    # Python >=3.14 removed the __annotations__ attribute
-+    # retrieve it via inspect (see also annotationlib)
-+    if hasattr(inspect, "get_annotations"):
-+        # Python >=3.10
-+        return inspect.get_annotations(cls)
-+    else:
-+        # Python <3.10
-+        return getattr(cls, "__annotations__", {})
-+
- 
- # Variable annotations for properties is only supported in python-3.6 and later (PEP 526)
- if sys.version_info[0:2] >= (3, 6):
-@@ -8,17 +21,14 @@
-     annotations_supported = not(is_python_builtin() or is_python_fastproxy())
- 
-     if annotations_supported:
--        ts = TemplateShort()
--        anno = ts.__annotations__
-+        anno = get_annotations(TemplateShort)
-         if anno != {'member_variable': 'int'}:
-             raise RuntimeError("annotations mismatch: {}".format(anno))
- 
--        ts = StructWithVar()
--        anno = ts.__annotations__
-+        anno = get_annotations(StructWithVar)
-         if anno != {'member_variable': 'int'}:
-             raise RuntimeError("annotations mismatch: {}".format(anno))
- 
--        ts = StructWithVarNotAnnotated()
--        if getattr(ts, "__annotations__", None) != None:
--            anno = ts.__annotations__
-+        anno = get_annotations(StructWithVarNotAnnotated)
-+        if anno != {}:
-             raise RuntimeError("annotations mismatch: {}".format(anno))
-
diff --git a/swig.spec b/swig.spec
index 0b7b0f9..996ead8 100644
--- a/swig.spec
+++ b/swig.spec
@@ -3,64 +3,48 @@
 
 %if %{without testsuite}
 %global tcl 0
-%global guile 0
 %global lualang 0
-%global perllang 0
 %global phplang 0
 %global rubylang 0
+%global python2lang 0
 %global python3lang 0
 %global golang 0
 %global octave 0
 %global Rlang 0
 %global javalang 0
-%global ocamllang 0
 %endif
 
 %{!?tcl:%global tcl 1}
+%{!?guile:%global guile 0}
 %{!?lualang:%global lualang 1}
-%{!?perllang:%global perllang 1}
-%{!?rubylang:%global rubylang 1}
-%{!?python3lang:%global python3lang 1}
-
-# PHP drop support for 32-bit builds since Fedora 41.
-%if 0%{?fedora} >= 41 || 0%{?rhel} >= 11
-%ifarch %{ix86}
-%global phplang 0
-%endif
-%endif
 %{!?phplang:%global phplang 1}
-
-# OCaml packages not built on i686 since OCaml 5 / Fedora 39.
-%ifarch %{ix86}
-%{!?ocamllang:%global ocamllang 0}
+# Disable Ruby test failed with swig 4.0.0 on s390
+%ifarch s390x
+%{!?rubylang:%global rubylang 0}
 %else
-%{!?ocamllang:%global ocamllang 1}
+%{!?rubylang:%global rubylang 1}
 %endif
+%{!?python2lang:%global python2lang 1}
+%{!?python3lang:%global python3lang 1}
 
 %if 0%{?rhel}
 %{!?golang:%global golang 0}
-%{!?guile:%global guile 0}
 %{!?octave:%global octave 0}
 %{!?Rlang:%global Rlang 0}
 %bcond_with build_ccache_swig
 %else
-%{!?guile:%global guile 1}
 %{!?octave:%global octave 1}
-# R-core requires tcl < 9.0.0
-%{!?Rlang:%global Rlang 0}
+%{!?Rlang:%global Rlang 1}
 %bcond_without build_ccache_swig
 %endif
-
-%ifarch %{ix86}
+%ifarch aarch64 %{arm} %{mips} ppc64le ppc %{power64} s390 s390x
 %{!?javalang:%global javalang 0}
 %else
-# Temporary disable java tests, because they doesn't pass with java-21-openjdk
-# https://github.com/swig/swig/issues/2767
 %{!?javalang:%global javalang 1}
 %endif
 
-# Do not run Go tests, they failed with 4.0.0 on ppc64le, s390
-%ifarch x86_64 %{arm} aarch64
+# Do not run Go tests, they failed with 4.0.0 on ppc64le
+%ifarch %{ix86} x86_64 %{arm} aarch64
 %{!?golang:%global golang 1}
 %else
 %{!?golang:%global golang 0}
@@ -68,10 +52,10 @@
 
 Summary: Connects C/C++/Objective C to some high-level programming languages
 Name:    swig
-Version: 4.4.1
-Release: 1%{?dist}
-License: GPL-3.0-or-later AND BSD-3-Clause
-URL:     https://www.swig.org/
+Version: 4.0.1
+Release: 7%{?dist}
+License: GPLv3+ and BSD
+URL:     http://swig.sourceforge.net/
 Source0: http://downloads.sourceforge.net/project/swig/swig/swig-%{version}/swig-%{version}.tar.gz
 # Define the part of man page sections
 Source1: description.h2m
@@ -81,15 +65,25 @@ Source3: ccache-swig.sh
 Source4: ccache-swig.csh
 %endif
 
-BuildRequires: coreutils
-BuildRequires: findutils
-BuildRequires: make
-BuildRequires: perl-interpreter, pcre2-devel
+Patch0:  swig308-Do-not-use-isystem.patch
+# Fix code generated for Ruby global variables
+# https://github.com/swig/swig/issues/1668
+Patch1:  swig-4.0.1-Fix-code-generated-for-Ruby-global-variables.patch
+# Add support for Ruby 2.7
+# https://github.com/swig/swig/pull/1692
+Patch2:  swig-4.0.1-Add-support-for-Ruby-2.7.patch
+# Fix crash in Python backend when using empty docstrings
+# https://github.com/swig/swig/pull/1710
+Patch3: swig-4.0.1-Fix-crash-in-Python-backend-when-using-empty-docstrings.patch
+
+BuildRequires: perl-interpreter, pcre-devel
+%if %{python2lang}
+BuildRequires: python2-devel
+%endif
 BuildRequires: python%{python3_pkgversion}-devel
 BuildRequires: autoconf, automake, gawk, dos2unix
 BuildRequires: gcc-c++
 BuildRequires: help2man
-BuildRequires: sed
 BuildRequires: perl-devel
 BuildRequires: perl(base)
 BuildRequires: perl(Config)
@@ -105,7 +99,7 @@ BuildRequires: boost-devel
 # Need when Source/CParse/parser.y is patched
 BuildRequires: bison
 %if %{tcl}
-BuildRequires: tcl-devel >= 9.0.0
+BuildRequires: tcl-devel
 %endif
 %if %{guile}
 BuildRequires: guile-devel
@@ -116,9 +110,7 @@ BuildRequires: octave-devel
 %if %{golang}
 BuildRequires: golang
 BuildRequires: golang-bin
-%ifnarch s390x
 BuildRequires: golang-shared
-%endif
 BuildRequires: golang-src
 %endif
 %if %{lualang}
@@ -136,10 +128,6 @@ BuildRequires: java, java-devel
 %if %{phplang}
 BuildRequires: php, php-devel
 %endif
-%if %{ocamllang}
-BuildRequires: ocaml
-BuildRequires: ocaml-findlib
-%endif
 
 %description
 Simplified Wrapper and Interface Generator (SWIG) is a software
@@ -157,7 +145,7 @@ testing and prototyping C/C++ software.
 %if %{with build_ccache_swig}
 %package -n ccache-swig
 Summary:   Fast compiler cache
-License:   GPL-2.0-or-later
+License:   GPLv2+
 Requires:  swig
 Conflicts: swig < 3.0.8-2
 
@@ -169,7 +157,7 @@ being done again. ccache-swig is ccache plus support for SWIG.
 
 %package doc
 Summary:   Documentation files for SWIG
-License:   BSD-3-Clause
+License:   BSD
 BuildArch: noarch
 
 %description doc
@@ -177,7 +165,7 @@ This package contains documentation for SWIG and useful examples
 
 %package gdb
 Summary:   Commands for easier debugging of SWIG
-License:   BSD-3-Clause
+License:   BSD
 Requires:  swig
 
 %description gdb
@@ -185,7 +173,12 @@ This package contains file with commands for easier debugging of SWIG
 in gdb.
 
 %prep
-%autosetup -p1
+%setup -q -n swig-%{version}
+
+%patch0 -p1 -b .isystem
+%patch1 -p1 -b .global
+%patch2 -p1 -b .ruby27
+%patch3 -p1 -b .python
 
 for all in CHANGES README; do
     iconv -f ISO88591 -t UTF8 < $all > $all.new
@@ -200,24 +193,22 @@ done
 # code produces lots of the warnings demanded by strict ISO C and ISO C++.
 # It causes that log had more then 600M.
 %configure \
-%if %{ocamllang}
-  --with-ocaml \
-%else
   --without-ocaml \
+%if %{python2lang}
+  --with-python=%__python2\
+%else
+  --without-python \
 %endif
 %if %{python3lang}
-  --with-python3=python3 \
+  --with-python3=%__python3 \
 %else
   --without-python3 \
 %endif
 %if %{phplang}
-  --with-php \
+  --with-php=%{__php} \
 %else
   --without-php \
 %endif
-%if ! %{perllang}
-  --without-perl5 \
-%endif
 %if ! %{tcl}
   --without-tcl \
 %endif
@@ -230,22 +221,19 @@ done
 %if ! %{golang}
   --without-go \
 %endif
-%if ! %{guile}
-  --without-guile \
-%endif
 %if %{octave}
-  --with-octave=%{_bindir}/octave \
+  --with-octave=/usr/bin/octave \
   --without-maximum-compile-warnings \
 %endif
 %if %{without build_ccache_swig}
   --disable-ccache \
 %endif
 ;
-%{make_build}
+make %{?_smp_mflags}
 
 %if %{with testsuite}
 # Test suite
-make check PY3=1
+make check
 %endif
 
 %install
@@ -268,7 +256,7 @@ for all in `find -type f`; do
 done
 popd
 
-%{make_install}
+make DESTDIR=%{buildroot} install
 
 #################################################
 # Use help output for generating of man page swig
@@ -363,190 +351,6 @@ install -pm 644 Tools/swig.gdb %{buildroot}%{_datadir}/%{name}/gdb
 %{_datadir}/%{name}/gdb
 
 %changelog
-* Mon Dec 08 2025 Jitka Plesnikova  - 4.4.1-1
-- 4.4.1 bump (rhbz#2419819, rhbz#2415440)
-
-* Tue Oct 21 2025 Jitka Plesnikova  - 4.4.0-1
-- 4.4.0 bump (rhbz#2405182)
-
-* Mon Oct 13 2025 Richard W.M. Jones  - 4.3.1-6
-- OCaml 5.4.0 rebuild
-
-* Thu Aug 07 2025 Orion Poplawski  - 4.3.1-5
-- Rebuild for Octave 10.2
-
-* Thu Jul 31 2025 Jitka Plesnikova  - 4.3.1-4
-- Fix Python DeprecationWarning
-
-* Fri Jul 25 2025 Fedora Release Engineering  - 4.3.1-3
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild
-
-* Wed Jun 25 2025 Yaakov Selkowitz  - 4.3.1-2
-- Add Python 3.14 support
-
-* Wed Apr 16 2025 Jitka Plesnikova  - 4.3.1-1
-- 4.3.1 bump (rhbz#2360009)
-
-* Mon Feb 17 2025 Jitka Plesnikova  - 4.3.0-5
-- Disable R tests, because they need tcl < 9
-
-* Sun Jan 19 2025 Fedora Release Engineering  - 4.3.0-4
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild
-
-* Thu Nov 14 2024 Orion Poplawski  - 4.3.0-3
-- Rebuild for octave 9.2
-
-* Tue Oct 29 2024 Jitka Plesnikova  - 4.3.0-2
-- Fix precedence of casts
-
-* Mon Oct 21 2024 Jitka Plesnikova  - 4.3.0-1
-- 4.3.0 bump (rhbz#2320047)
-
-* Sat Jul 20 2024 Fedora Release Engineering  - 4.2.1-8
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild
-
-* Sun Jun 23 2024 Yaakov Selkowitz  - 4.2.1-7
-- Rebuild for Python 3.13
-
-* Wed Jun 19 2024 Richard W.M. Jones  - 4.2.1-6
-- OCaml 5.2.0 ppc64le fix
-
-* Wed May 29 2024 Richard W.M. Jones  - 4.2.1-5
-- OCaml 5.2.0 for Fedora 41
-
-* Mon Apr 29 2024 Jitka Plesnikova  - 4.2.1-4
-- Fix gcc's -Wformat-security warning in R Raise function (rhbz#2277767)
-
-* Fri Apr 12 2024 Remi Collet  - 4.2.1-3
-- disable PHP support on 32-bit
-  https://fedoraproject.org/wiki/Changes/php_no_32_bit
-
-* Tue Feb 27 2024 Jiri Vanek  - 4.2.1-2
-- Rebuilt for java-21-openjdk as system jdk
-- Temporary disable java tests (rhbz#2266693)
-
-* Mon Feb 26 2024 Jitka Plesnikova  - 4.2.1-1
-- 4.2.1 bump (rhbz#2265786)
-
-* Tue Jan 23 2024 Jitka Plesnikova  - 4.2.0-1
-- 4.2.0 bump
-
-* Mon Dec 18 2023 Richard W.M. Jones  - 4.1.1-15
-- OCaml 5.1.1 + s390x code gen fix for Fedora 40
-
-* Tue Dec 12 2023 Richard W.M. Jones  - 4.1.1-14
-- OCaml 5.1.1 rebuild for Fedora 40
-
-* Thu Dec 07 2023 Jitka Plesnikova  - 4.1.1-13
-- Fix PHP director_classes testcase failures on x86
-
-* Fri Oct 20 2023 Jitka Plesnikova  - 4.1.1-12
-- Stop using Python's 2to3
-
-* Wed Oct 11 2023 Jitka Plesnikova  - 4.1.1-11
-- Fix PHP test, it fails with PHP 8.3
-
-* Thu Oct 05 2023 Richard W.M. Jones  - 4.1.1-10
-- OCaml 5.1 rebuild for Fedora 40
-
-* Sat Jul 22 2023 Fedora Release Engineering  - 4.1.1-9
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
-
-* Wed Jul 12 2023 Jerry James  - 4.1.1-8
-- Add patch for python 3.12
-
-* Tue Jul 11 2023 Richard W.M. Jones  - 4.1.1-8
-- OCaml 5.0 rebuild for Fedora 39
-
-* Tue Jun 20 2023 Jerry James  - 4.1.1-7
-- Enable OCaml support
-- Add patch for OCaml 5.0.0
-
-* Sat Apr 08 2023 Orion Poplawski  - 4.1.1-6
-- Rebuild with octave 8.1.0
-
-* Thu Mar 16 2023 Orion Poplawski  - 4.1.1-5
-- Add patch to support octave 8.1
-
-* Thu Feb 02 2023 Jitka Plesnikova  - 4.1.1-4
-- Disable PHP test on i686
-
-* Sat Jan 21 2023 Fedora Release Engineering  - 4.1.1-3
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
-
-* Thu Jan 12 2023 Florian Weimer  - 4.1.1-2
-- Port configure script to C99
-
-* Thu Dec 01 2022 Jitka Plesnikova  - 4.1.1-1
-- Update to 4.1.1
-
-* Tue Oct 25 2022 Jitka Plesnikova  - 4.1.0-1
-- Update to 4.1.0
-
-* Thu Jul 21 2022 Maxwell G  - 4.0.2-18
-- Exclude golang extension from i686
-
-* Tue Jul 19 2022 Maxwell G  - 4.0.2-17
-- Rebuild for CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in
-  golang
-
-* Sat Jun 18 2022 Robert-André Mauchin  - 4.0.2-16
-- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327, CVE-2022-27191,
-  CVE-2022-29526, CVE-2022-30629
-
-* Wed Jun 01 2022 Orion Poplawski  - 4.0.2-15
-- Rebuild for octave 7.1
-
-* Thu Feb 24 2022 Jitka Plesnikova  - 4.0.2-14
-- Disable Java tests
-
-* Sat Jan 22 2022 Jitka Plesnikova  - 4.0.2-13
-- Fix tests against GCC12, enable Guile tests
-
-* Sat Jan 22 2022 Fedora Release Engineering  - 4.0.2-12
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
-
-* Wed Nov 24 2021 Jitka Plesnikova  - 4.0.2-11
-- Disable PHP test, it fails with PHP 8.1
-
-* Thu Oct 07 2021 Jitka Plesnikova  - 4.0.2-10
-- Enable Python tests
-
-* Tue Aug 10 2021 Orion Poplawski  - 4.0.2-9
-- Rebuild for octave 6.3.0
-
-* Fri Jul 23 2021 Fedora Release Engineering  - 4.0.2-8
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
-
-* Thu Jul 15 2021 Jitka Plesnikova  - 4.0.2-7
-- Disable Python tests, they fail with 3.10.0~b2
-
-* Mon May 31 2021 Orion Poplawski  - 4.0.2-6
-- Add patch for octave 6 support (bz#1919617)
-
-* Fri Mar 05 2021 Jitka Plesnikova  - 4.0.2-5
-- Backport support of PHP8 from upstream
-
-* Wed Jan 27 2021 Fedora Release Engineering  - 4.0.2-4
-- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
-
-* Fri Aug 28 2020 Jitka Plesnikova  - 4.0.2-3
-- Enable tests for Python 3
-
-* Wed Jul 29 2020 Tom Stellard  - 4.0.2-2
-- Use make macros
-  https://fedoraproject.org/wiki/Changes/UseMakeBuildInstallMacro
-- Disable Go tests
-
-* Mon Jun 08 2020 Jitka Plesnikova  - 4.0.2-1
-- Update to 4.0.2
-
-* Fri Mar 06 2020 Jitka Plesnikova  - 4.0.1-9
-- Remove BR for Python 2 (bug#1807547)
-
-* Tue Feb 25 2020 Peter Robinson  - 4.0.1-8
-- Add fix for newer NodeJS version
-
 * Tue Feb 04 2020 Michael Jeanson  - 4.0.1-7
 - Fix crash in Python backend when using empty docstrings
 
diff --git a/swig308-Do-not-use-isystem.patch b/swig308-Do-not-use-isystem.patch
new file mode 100644
index 0000000..efd0312
--- /dev/null
+++ b/swig308-Do-not-use-isystem.patch
@@ -0,0 +1,13 @@
+diff -up swig-3.0.8/configure.ac.orig swig-3.0.8/configure.ac
+--- swig-3.0.8/configure.ac.orig	2016-02-02 16:01:09.094852303 +0100
++++ swig-3.0.8/configure.ac	2016-02-02 16:01:42.096702679 +0100
+@@ -118,7 +118,8 @@ AC_SUBST(BOOST_CPPFLAGS)
+ dnl How to specify include directories that may be system directories.
+ # -I should not be used on system directories (GCC)
+ if test "$GCC" = yes; then
+-    ISYSTEM="-isystem "
++#    ISYSTEM="-isystem "
++    ISYSTEM="-I"
+ else
+     ISYSTEM="-I"
+ fi