Merge branch 'OCaml-caml_named_value-const'
* OCaml-caml_named_value-const:
[OCaml] Fix compilation errors with OCaml 4.09.0
diff --git a/.travis.yml b/.travis.yml
index 72ede27..32c6656 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -54,7 +54,12 @@
dist: xenial
- compiler: gcc
os: linux
- env: SWIGLANG=d
+ env: SWIGLANG=d VER=2.066.0
+ sudo: required
+ dist: xenial
+ - compiler: gcc
+ os: linux
+ env: SWIGLANG=d VER=2.086.1
sudo: required
dist: xenial
- compiler: gcc
@@ -204,6 +209,11 @@
dist: xenial
- compiler: gcc
os: linux
+ env: SWIGLANG=python PY3=3 VER=3.8
+ sudo: required
+ dist: xenial
+ - compiler: gcc
+ os: linux
env: SWIGLANG=python SWIG_FEATURES=-builtin
sudo: required
dist: xenial
@@ -217,7 +227,7 @@
sudo: required
dist: xenial
- os: linux
- env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1 PY3=3 VER=3.7
+ env: SWIGLANG=python SWIG_FEATURES=-builtin GCC=6 CPP11=1 PY3=3 VER=3.8
sudo: required
dist: xenial
- compiler: gcc
@@ -237,12 +247,17 @@
dist: xenial
- compiler: gcc
os: linux
- env: SWIGLANG=python SWIG_FEATURES="-builtin -O" PY3=3 VER=3.7
+ env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.8
sudo: required
dist: xenial
- compiler: gcc
os: linux
- env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.7 SWIGOPTPY3=
+ env: SWIGLANG=python SWIG_FEATURES="-builtin -O" PY3=3 VER=3.8
+ sudo: required
+ dist: xenial
+ - compiler: gcc
+ os: linux
+ env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3 VER=3.8 SWIGOPTPY3=
sudo: required
dist: xenial
- compiler: gcc
@@ -252,7 +267,7 @@
dist: xenial
- compiler: gcc
os: linux
- env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.7
+ env: SWIGLANG=python SWIG_FEATURES=-O PY3=3 VER=3.8
sudo: required
dist: xenial
- compiler: gcc
@@ -302,6 +317,11 @@
dist: xenial
- compiler: gcc
os: linux
+ env: SWIGLANG=ruby VER=2.7
+ sudo: required
+ dist: xenial
+ - compiler: gcc
+ os: linux
env: SWIGLANG=scilab
sudo: required
dist: xenial
@@ -379,7 +399,7 @@
sudo: required
dist: xenial
- os: linux
- env: SWIGLANG=python GCC=8 CPP17=1 PY3=3 VER=3.7
+ env: SWIGLANG=python GCC=8 CPP17=1 PY3=3 VER=3.8
sudo: required
dist: xenial
- os: linux
@@ -391,7 +411,7 @@
sudo: required
dist: xenial
- os: linux
- env: SWIGLANG=python GCC=9 CPP17=1 PY3=3 VER=3.7
+ env: SWIGLANG=python GCC=9 CPP17=1 PY3=3 VER=3.8
sudo: required
dist: xenial
- compiler: gcc
@@ -443,6 +463,12 @@
osx_image: xcode10.2
allow_failures:
+ # Newer version of D not yet working/supported
+ - compiler: gcc
+ os: linux
+ env: SWIGLANG=d VER=2.086.1
+ sudo: required
+ dist: xenial
# seg fault in director_basic testcase
- compiler: gcc
os: linux
diff --git a/CHANGES.current b/CHANGES.current
index 9c1e8a2..4180d2c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -7,6 +7,27 @@
Version 4.0.2 (in progress)
===========================
+2020-01-13: wsfulton
+ [Python] #1595 Python -builtin constructors silently ignored keyword arguments.
+ Instead of silenty ignoring them, now a "TypeError: f() takes no keyword arguments"
+ exception is thrown if keyword arguments are used. Hence constructors and normal methods/
+ functions behave in the same way. Note, -keyword should be used with -builtin to obtain
+ keyword argument support.
+
+2020-01-05: jschueller shadchin
+ [Python] #1670 #1696 Add missing field initializers introduced in python 3.8:
+ tp_vectorcall and tp_print.
+
+2020-01-05: friedrichatgc
+ [Octave] #1688 Change swig_this() to use size_t instead of long for compatibility
+ with Windows 64 bit.
+
+2020-01-05: treitmayr
+ [Ruby] #1692 #1689 Add support for Ruby 2.7
+
+2019-12-30: treitmayr
+ [Ruby] #1653 #1668 Fix code generated when using -globalmodule option.
+
2019-12-29: ZackerySpytz
[OCaml] #1686 Fix compilation errors with OCaml 4.09.0.
diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html
index 3cfd129..6939a8a 100644
--- a/Doc/Manual/Ruby.html
+++ b/Doc/Manual/Ruby.html
@@ -615,6 +615,24 @@
effect until it is explicitly disabled using <tt>%mutable</tt>.
</p>
+<p>Note: When SWIG is invoked with the <tt>-globalmodule</tt> 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:
+
+<div class="code targetlang">
+<pre>$ <b>irb</b>
+irb(main):001:0> <b>require 'Example'</b>
+true
+irb(main):002:0> <b>$variable1 = 2</b>
+2
+irb(main):003:0> <b>$Variable2 = 4 * 10.3</b>
+41.2
+irb(main):004:0> <b>$Variable2</b>
+41.2</pre>
+</div>
+
<H3><a name="Ruby_nn15">34.3.4 Constants</a></H3>
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index c817bdf..5f6de1b 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -159,6 +159,7 @@
cpp_enum \
cpp_namespace \
cpp_nodefault \
+ cpp_parameters \
cpp_static \
cpp_typedef \
cpp14_binary_integer_literals \
@@ -250,6 +251,7 @@
funcptr_cpp \
functors \
fvirtual \
+ global_immutable_vars_cpp \
global_namespace \
global_ns_arg \
global_scope_types \
@@ -692,6 +694,7 @@
funcptr \
function_typedef \
global_functions \
+ global_immutable_vars \
immutable_values \
inctest \
infinity \
diff --git a/Examples/test-suite/cpp_parameters.i b/Examples/test-suite/cpp_parameters.i
new file mode 100644
index 0000000..e8a4c94
--- /dev/null
+++ b/Examples/test-suite/cpp_parameters.i
@@ -0,0 +1,46 @@
+%module cpp_parameters
+
+%{
+// For Perl
+#ifdef Zero
+#undef Zero
+#endif
+%}
+%inline %{
+
+// Zero arguments
+struct Zero {
+ Zero() {}
+ int zero() { return 0; }
+ static int stat_zero() { return 0; }
+};
+// One mandatory argument
+struct One {
+ One(int a) {}
+ int one(int a) { return a; }
+ static int stat_one(int a) { return a; }
+};
+// Two mandatory arguments
+struct Two {
+ Two(int a, int b) {}
+ int two(int a, int b) { return a + b; }
+ static int stat_two(int a, int b) { return a + b; }
+};
+// Single optional argument
+struct Single {
+ Single(int a=0) {}
+ int single(int a=0) { return a; }
+ static int stat_single(int a=0) { return a; }
+};
+
+int global_zero() { return 0; }
+int global_one(int a) { return a; }
+int global_two(int a, int b) { return a + b; }
+int global_single(int a=0) { return a; }
+
+#ifdef SWIGPYTHON_BUILTIN
+bool is_python_builtin() { return true; }
+#else
+bool is_python_builtin() { return false; }
+#endif
+%}
diff --git a/Examples/test-suite/global_immutable_vars.i b/Examples/test-suite/global_immutable_vars.i
new file mode 100644
index 0000000..ab0d4f7
--- /dev/null
+++ b/Examples/test-suite/global_immutable_vars.i
@@ -0,0 +1,33 @@
+%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;
+
+ int check_values(int default_mutable, int global_immutable, int specific_mutable, int global_mutable, int specific_immutable) {
+ return
+ default_mutable == default_mutable_var &&
+ global_immutable == global_immutable_var &&
+ specific_mutable == specific_mutable_var &&
+ global_mutable == global_mutable_var &&
+ specific_immutable == specific_immutable_var;
+ }
+%}
+
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 0000000..40cc08e
--- /dev/null
+++ b/Examples/test-suite/global_immutable_vars_cpp.i
@@ -0,0 +1,33 @@
+%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;
+
+ int check_values(int default_mutable, int global_immutable, int specific_mutable, int global_mutable, int specific_immutable) {
+ return
+ default_mutable == default_mutable_var &&
+ global_immutable == global_immutable_var &&
+ specific_mutable == specific_mutable_var &&
+ global_mutable == global_mutable_var &&
+ specific_immutable == specific_immutable_var;
+ }
+%}
+
diff --git a/Examples/test-suite/python/cpp_parameters_runme.py b/Examples/test-suite/python/cpp_parameters_runme.py
new file mode 100644
index 0000000..99d14ad
--- /dev/null
+++ b/Examples/test-suite/python/cpp_parameters_runme.py
@@ -0,0 +1,296 @@
+from cpp_parameters import *
+
+# Testing correct and incorrect parameter counts being passed (kwargs and non-kwargs)
+# Note that the implementation depends a lot on whether zero, one, two or more args are being wrapped
+
+def is_python_fastproxy():
+ """Return True if SWIG is generating Python code using -fastproxy."""
+ import cpp_parameters
+ # Note: _swig_new_instance_method is only generated when using -fastproxy
+ return hasattr(cpp_parameters, "_swig_new_instance_method")
+
+# Zero parameters expected
+x = Zero()
+try:
+ x = Zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Zero.stat_zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Zero.stat_zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_zero(z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_zero(0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# One mandatory parameter expected
+x = One(1)
+try:
+ x = One(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = One(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ One.stat_one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ One.stat_one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_one(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_one(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Two mandatory parameters expected
+x = Two(1, 2)
+try:
+ x = Two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Two.stat_two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Two.stat_two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_two(a=1, b=2, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_two(1, 2, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Single optional parameter expected
+x = Single(1)
+try:
+ x = Single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x = Single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ x.single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ x.single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ Single.stat_single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ Single.stat_single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+try:
+ global_single(a=1, z=0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+try:
+ global_single(1, 0)
+ raise RuntimeError("Missed throw")
+except TypeError:
+ pass
+
+# Test that -builtin option throws TypeError if kwargs are used even when they look like they should work, kwargs are not supported unless using -keyword.
+# Also same for -fastproxy option except that kwargs are supported by default for constructors. TODO: Fix inconsistency.
+
+if is_python_builtin() or is_python_fastproxy():
+ # One mandatory parameter in API
+ x = One(1)
+ if is_python_fastproxy():
+ x = One(a=1)
+ else:
+ try:
+ x = One(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ One.stat_one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_one(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+ # Two mandatory parameters in API
+ x = Two(1, 2)
+ if is_python_fastproxy():
+ x = Two(a=1, b=2)
+ else:
+ try:
+ x = Two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ Two.stat_two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_two(a=1, b=2)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+ # Single optional parameter in API
+ x = Single(1)
+ if is_python_fastproxy():
+ x = Single(a=1)
+ else:
+ try:
+ x = Single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ x.single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ Single.stat_single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+ try:
+ global_single(a=1)
+ raise RuntimeError("Missed throw")
+ except TypeError:
+ pass
+
+else:
+ # Non-builtin should work as expected
+ # One mandatory parameter in API
+ x = One(a=1)
+ x.one(a=1)
+ One.stat_one(a=1)
+ global_one(a=1)
+
+ # Two mandatory parameters in API
+ x = Two(a=1, b=2)
+ x.two(a=1, b=2)
+ Two.stat_two(a=1, b=2)
+ global_two(a=1, b=2)
+
+ # Single optional parameter in API
+ x = Single(a=1)
+ x.single(a=1)
+ Single.stat_single(a=1)
+ global_single(a=1)
diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in
index d75cdb0..2c59029 100644
--- a/Examples/test-suite/ruby/Makefile.in
+++ b/Examples/test-suite/ruby/Makefile.in
@@ -23,6 +23,7 @@
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 @@
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 @@
# 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 0000000..7897f7d
--- /dev/null
+++ b/Examples/test-suite/ruby/global_immutable_vars_cpp_runme.rb
@@ -0,0 +1,48 @@
+#!/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( <<EOF )
+Global_immutable_vars_cpp::default_mutable_var == 40
+Global_immutable_vars_cpp::global_immutable_var == 41
+Global_immutable_vars_cpp::specific_mutable_var == 42
+Global_immutable_vars_cpp::global_mutable_var == 43
+Global_immutable_vars_cpp::specific_immutable_var == 44
+EOF
+
+# check that all mutable variables can be modified
+swig_assert_each_line( <<EOF )
+Global_immutable_vars_cpp::default_mutable_var = 80
+Global_immutable_vars_cpp::default_mutable_var == 80
+Global_immutable_vars_cpp::specific_mutable_var = 82
+Global_immutable_vars_cpp::specific_mutable_var == 82
+Global_immutable_vars_cpp::global_mutable_var = 83
+Global_immutable_vars_cpp::global_mutable_var == 83
+EOF
+
+# now check that immutable variables cannot be modified
+had_exception = false
+begin
+ Global_immutable_vars_cpp::global_immutable_var = 81
+rescue NoMethodError => 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)")
+
+swig_assert(Global_immutable_vars_cpp::check_values(80, 41, 82, 83, 44) == 1, nil, "Check values failed")
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 0000000..ffbea27
--- /dev/null
+++ b/Examples/test-suite/ruby/global_immutable_vars_runme.rb
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+#
+# Here the proper generation of mutable and immutable variables is tested
+# in the target language.
+# Immutable variables do not have "<var>=" 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( <<EOF )
+Global_immutable_vars::default_mutable_var == 40
+Global_immutable_vars::global_immutable_var == 41
+Global_immutable_vars::specific_mutable_var == 42
+Global_immutable_vars::global_mutable_var == 43
+Global_immutable_vars::specific_immutable_var == 44
+EOF
+
+# check that all mutable variables can be modified
+swig_assert_each_line( <<EOF )
+Global_immutable_vars::default_mutable_var = 80
+Global_immutable_vars::default_mutable_var == 80
+Global_immutable_vars::specific_mutable_var = 82
+Global_immutable_vars::specific_mutable_var == 82
+Global_immutable_vars::global_mutable_var = 83
+Global_immutable_vars::global_mutable_var == 83
+EOF
+
+# now check that immutable variables cannot be modified
+had_exception = false
+begin
+ Global_immutable_vars::global_immutable_var = 81
+rescue NoMethodError => 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)")
+
+swig_assert(Global_immutable_vars::check_values(80, 41, 82, 83, 44) == 1, nil, "Check values failed")
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 0000000..5523b59
--- /dev/null
+++ b/Examples/test-suite/ruby/ruby_global_immutable_vars_cpp_runme.rb
@@ -0,0 +1,48 @@
+#!/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( <<EOF )
+$default_mutable_var == 40
+$global_immutable_var == 41
+$specific_mutable_var == 42
+$global_mutable_var == 43
+$specific_immutable_var == 44
+EOF
+
+# check that all mutable variables can be modified
+swig_assert_each_line( <<EOF )
+$default_mutable_var = 80
+$default_mutable_var == 80
+$specific_mutable_var = 82
+$specific_mutable_var == 82
+$global_mutable_var = 83
+$global_mutable_var == 83
+EOF
+
+# now check that immutable variables cannot be modified
+had_exception = false
+begin
+ $global_immutable_var = 81
+rescue NameError => 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)")
+
+swig_assert(check_values(80, 41, 82, 83, 44) == 1, nil, "Check values failed")
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 0000000..45a8506
--- /dev/null
+++ b/Examples/test-suite/ruby/ruby_global_immutable_vars_runme.rb
@@ -0,0 +1,52 @@
+#!/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( <<EOF )
+$default_mutable_var == 40
+$global_immutable_var == 41
+$specific_mutable_var == 42
+$global_mutable_var == 43
+$specific_immutable_var == 44
+EOF
+
+# check that all mutable variables can be modified
+swig_assert_each_line( <<EOF )
+$default_mutable_var = 80
+$default_mutable_var == 80
+$specific_mutable_var = 82
+$specific_mutable_var == 82
+$global_mutable_var = 83
+$global_mutable_var == 83
+EOF
+
+# now check that immutable variables cannot be modified
+had_exception = false
+begin
+ $global_immutable_var = 81
+rescue NameError => 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)")
+
+swig_assert(check_values(80, 41, 82, 83, 44) == 1, nil, "Check values failed")
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 0000000..6f067d2
--- /dev/null
+++ b/Examples/test-suite/ruby_global_immutable_vars.i
@@ -0,0 +1,34 @@
+%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;
+
+ int check_values(int default_mutable, int global_immutable, int specific_mutable, int global_mutable, int specific_immutable) {
+ return
+ default_mutable == default_mutable_var &&
+ global_immutable == global_immutable_var &&
+ specific_mutable == specific_mutable_var &&
+ global_mutable == global_mutable_var &&
+ specific_immutable == specific_immutable_var;
+ }
+%}
+
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 0000000..511390e
--- /dev/null
+++ b/Examples/test-suite/ruby_global_immutable_vars_cpp.i
@@ -0,0 +1,32 @@
+%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;
+
+ int check_values(int default_mutable, int global_immutable, int specific_mutable, int global_mutable, int specific_immutable) {
+ return
+ default_mutable == default_mutable_var &&
+ global_immutable == global_immutable_var &&
+ specific_mutable == specific_mutable_var &&
+ global_mutable == global_mutable_var &&
+ specific_immutable == specific_immutable_var;
+ }
+%}
+
diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg
index ff614e6..325a4cc 100644
--- a/Lib/octave/octrun.swg
+++ b/Lib/octave/octrun.swg
@@ -507,10 +507,10 @@
delete this;
}
- long swig_this() const {
+ size_t swig_this() const {
if (!types.size())
- return (long) this;
- return (long) types[0].second.ptr;
+ return (size_t) this;
+ return (size_t) types[0].second.ptr;
}
const char* help_text() const {
if (!types.size())
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 28051e6..5308748 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -256,6 +256,12 @@
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -334,6 +340,12 @@
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index dfbf40b..a6d609d 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -186,6 +186,12 @@
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 82859b8..d6eeda9 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -183,6 +183,19 @@
}
}
+SWIGINTERN int
+SWIG_Python_CheckNoKeywords(PyObject *kwargs, const char *name) {
+ int no_kwargs = 1;
+ if (kwargs) {
+ assert(PyDict_Check(kwargs));
+ if (PyDict_Size(kwargs) > 0) {
+ PyErr_Format(PyExc_TypeError, "%s() does not take keyword arguments", name);
+ no_kwargs = 0;
+ }
+ }
+ return no_kwargs;
+}
+
/* A functor is a function object with one single object argument */
#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL);
@@ -696,6 +709,12 @@
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
@@ -857,6 +876,12 @@
#if PY_VERSION_HEX >= 0x03040000
0, /* tp_finalize */
#endif
+#if PY_VERSION_HEX >= 0x03080000
+ 0, /* tp_vectorcall */
+#endif
+#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)
+ 0, /* tp_print */
+#endif
#ifdef COUNT_ALLOCS
0, /* tp_allocs */
0, /* tp_frees */
diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg
index f7b51bd..b345fce 100644
--- a/Lib/ruby/rubyclasses.swg
+++ b/Lib/ruby/rubyclasses.swg
@@ -174,7 +174,7 @@
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 @@
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 @@
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 @@
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 90f07cf..bf4e362 100644
--- a/Lib/ruby/rubyhead.swg
+++ b/Lib/ruby/rubyhead.swg
@@ -98,38 +98,46 @@
/*
- * Need to be very careful about how these macros are defined, especially
- * when compiling C++ code or C code with an ANSI C compiler.
+ * The following macros are used for providing the correct type of a
+ * function pointer to the Ruby C API.
+ * Starting with Ruby 2.7 (corresponding to RB_METHOD_DEFINITION_DECL being
+ * defined) these macros act transparently due to Ruby's moving away from
+ * ANYARGS and instead employing strict function signatures.
*
- * VALUEFUNC(f) is a macro used to typecast a C function that implements
- * a Ruby method so that it can be passed as an argument to API functions
- * like rb_define_method() and rb_define_singleton_method().
+ * Note: In case of C (not C++) the macros are transparent even before
+ * Ruby 2.7 due to the fact that the Ruby C API used function declarators
+ * with empty parentheses, which allows for an unspecified number of
+ * arguments.
*
- * VOIDFUNC(f) is a macro used to typecast a C function that implements
- * either the "mark" or "free" stuff for a Ruby Data object, so that it
- * can be passed as an argument to API functions like Data_Wrap_Struct()
+ * PROTECTFUNC(f) is used for the function pointer argument of the Ruby
+ * C API function rb_protect().
+ *
+ * VALUEFUNC(f) is used for the function pointer argument(s) of Ruby C API
+ * functions like rb_define_method() and rb_define_singleton_method().
+ *
+ * VOIDFUNC(f) is used to typecast a C function that implements either
+ * the "mark" or "free" stuff for a Ruby Data object, so that it can be
+ * passed as an argument to Ruby C API functions like Data_Wrap_Struct()
* and Data_Make_Struct().
+ *
+ * SWIG_RUBY_VOID_ANYARGS_FUNC(f) is used for the function pointer
+ * argument(s) of Ruby C API functions like rb_define_virtual_variable().
+ *
+ * SWIG_RUBY_INT_ANYARGS_FUNC(f) is used for the function pointer
+ * argument(s) of Ruby C API functions like st_foreach().
*/
-
-#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 SWIG_RUBY_VOID_ANYARGS_FUNC(f) ((void (*)(ANYARGS))(f))
+# define SWIG_RUBY_INT_ANYARGS_FUNC(f) ((int (*)(ANYARGS))(f))
#else
+# define PROTECTFUNC(f) (f)
# define VALUEFUNC(f) (f)
# define VOIDFUNC(f) (f)
+# define SWIG_RUBY_VOID_ANYARGS_FUNC(f) (f)
+# define SWIG_RUBY_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 3a84819..4b078de 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 @@
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 @@
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 @@
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 @@
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 @@
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 b9fb249..1edcc56 100644
--- a/Lib/ruby/rubytracking.swg
+++ b/Lib/ruby/rubytracking.swg
@@ -32,7 +32,7 @@
*/
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,9 @@
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),
+ SWIG_RUBY_VOID_ANYARGS_FUNC((rb_gvar_setter_t*)NULL));
}
/* Add a Tracking from a C/C++ struct to a Ruby object */
@@ -118,13 +120,15 @@
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,
+ SWIG_RUBY_INT_ANYARGS_FUNC(swig_ruby_internal_iterate_callback),
+ (st_data_t)meth);
}
#ifdef __cplusplus
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 4792090..1dbedad 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -2493,7 +2493,7 @@
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
- const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
+ const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
Wrapper_add_local(f, "argc", "Py_ssize_t argc");
@@ -2503,6 +2503,9 @@
if (!fastunpack) {
Wrapper_add_local(f, "ii", "Py_ssize_t ii");
+ if (builtin_ctor)
+ Printf(f->code, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", symname);
+
if (maxargs - (add_self ? 1 : 0) > 0) {
Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
Append(f->code, "argc = PyObject_Length(args);\n");
@@ -2518,8 +2521,9 @@
if (add_self)
Append(f->code, "argc++;\n");
} else {
- String *iname = Getattr(n, "sym:name");
- Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args, \"%s\", 0, %d, argv%s))) SWIG_fail;\n", iname, maxargs, add_self ? "+1" : "");
+ if (builtin_ctor)
+ Printf(f->code, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", symname);
+ Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args, \"%s\", 0, %d, argv%s))) SWIG_fail;\n", symname, maxargs, add_self ? "+1" : "");
if (add_self)
Append(f->code, "argv[0] = self;\n");
else
@@ -2713,7 +2717,7 @@
Append(wname, overname);
}
- const char *builtin_kwargs = builtin_ctor ? ", PyObject *SWIGUNUSEDPARM(kwargs)" : "";
+ const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
if (!allow_kwargs || overname) {
if (!varargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
@@ -2886,6 +2890,7 @@
funpack = 0;
} else {
Clear(parse_args);
+
if (funpack) {
Clear(f->def);
if (overname) {
@@ -2898,6 +2903,8 @@
} else {
int is_tp_call = Equal(Getattr(n, "feature:python:slot"), "tp_call");
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
+ if (builtin_ctor)
+ Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (onearg && !builtin_ctor && !is_tp_call) {
Printf(parse_args, "if (!args) SWIG_fail;\n");
Append(parse_args, "swig_obj[0] = args;\n");
@@ -2908,6 +2915,8 @@
}
}
} else {
+ if (builtin_ctor)
+ Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (builtin && in_class && tuple_arguments == 0) {
Printf(parse_args, " if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, \"%s takes no arguments\");\n", iname);
} else {
@@ -4134,6 +4143,13 @@
Printv(f, "#if PY_VERSION_HEX >= 0x03040000\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_finalize"), "tp_finalize", "destructor");
Printv(f, "#endif\n", NIL);
+ Printv(f, "#if PY_VERSION_HEX >= 0x03080000\n", NIL);
+ printSlot(f, getSlot(n, "feature:python:tp_vectorcall"), "tp_vectorcall", "vectorcallfunc");
+ Printv(f, "#endif\n", NIL);
+ Printv(f, "#if (PY_VERSION_HEX >= 0x03080000) && (PY_VERSION_HEX < 0x03090000)\n", NIL);
+ printSlot(f, getSlot(), "tp_print");
+ Printv(f, "#endif\n", NIL);
+
Printv(f, "#ifdef COUNT_ALLOCS\n", NIL);
printSlot(f, getSlot(n, "feature:python:tp_allocs"), "tp_allocs", "Py_ssize_t");
printSlot(f, getSlot(n, "feature:python:tp_frees"), "tp_frees", "Py_ssize_t");
diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx
index 6a1e16d..48b0efa 100644
--- a/Source/Modules/ruby.cxx
+++ b/Source/Modules/ruby.cxx
@@ -2191,6 +2191,12 @@
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,
+ // 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 +2207,7 @@
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 *data" : "VALUE self");
Printf(getf->def, ") {");
Wrapper_add_local(getf, "_val", "VALUE _val");
@@ -2224,8 +2230,8 @@
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);
@@ -2235,8 +2241,12 @@
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, VALUE *data) {", 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,28 +2257,31 @@
} 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);
}
- /* define accessor method */
- if (CPlusPlus) {
- Insert(getfname, 0, "VALUEFUNC(");
- Append(getfname, ")");
- Insert(setfname, 0, "VALUEFUNC(");
- Append(setfname, ")");
- }
+ /* define accessor methods */
+ Insert(getfname, 0, "VALUEFUNC(");
+ Append(getfname, ")");
+ Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
+ Append(setfname, ")");
String *s = NewString("");
switch (current) {
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);
@@ -2279,14 +2292,11 @@
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_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, ", ", setfname, ");\n", NIL);
}
Printv(f_init, s, NIL);
Delete(s);
diff --git a/Tools/travis-linux-install.sh b/Tools/travis-linux-install.sh
index e902137..c8347d2 100755
--- a/Tools/travis-linux-install.sh
+++ b/Tools/travis-linux-install.sh
@@ -23,8 +23,8 @@
travis_retry sudo apt-get -qq install mono-devel
;;
"d")
- travis_retry wget http://downloads.dlang.org/releases/2014/dmd_2.066.0-0_amd64.deb
- travis_retry sudo dpkg -i dmd_2.066.0-0_amd64.deb
+ travis_retry wget http://downloads.dlang.org/releases/2.x/${VER}/dmd_${VER}-0_amd64.deb
+ travis_retry sudo dpkg -i dmd_${VER}-0_amd64.deb
;;
"go")
if [[ "$VER" ]]; then
@@ -95,6 +95,12 @@
travis_retry sudo apt-get -qq install r-base
;;
"ruby")
+ if [[ "$VER" == "2.7" ]]; then
+ # Ruby 2.7 support is currently only rvm master (30 Dec 2019)
+ travis_retry rvm get master
+ rvm reload
+ rvm list known
+ fi
if [[ "$VER" ]]; then
travis_retry rvm install $VER
fi