diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-10-24 08:41:42 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-10-24 08:56:55 +0100 |
commit | 1d73341aa424ebcf39caab86defff5ea8f0ee5ac (patch) | |
tree | 4529d11a19e6deb02175684a887f5b3014da2642 | |
parent | cfd2557cdaf6205219036585d9cacfbbe0ccead0 (diff) | |
download | swig-1d73341aa424ebcf39caab86defff5ea8f0ee5ac.tar.gz |
Polymorphism in R wrappers fixed for C++ structs
-rw-r--r-- | CHANGES.current | 4 | ||||
-rw-r--r-- | Examples/test-suite/go/typedef_inherit_runme.go | 5 | ||||
-rw-r--r-- | Examples/test-suite/javascript/typedef_inherit_runme.js | 4 | ||||
-rw-r--r-- | Examples/test-suite/ocaml/typedef_inherit_runme.ml | 3 | ||||
-rw-r--r-- | Examples/test-suite/octave/typedef_inherit_runme.m | 5 | ||||
-rw-r--r-- | Examples/test-suite/python/typedef_inherit_runme.py | 4 | ||||
-rw-r--r-- | Examples/test-suite/r/typedef_inherit_runme.R | 29 | ||||
-rw-r--r-- | Examples/test-suite/ruby/typedef_inherit_runme.rb | 6 | ||||
-rw-r--r-- | Examples/test-suite/typedef_inherit.i | 10 | ||||
-rw-r--r-- | Source/Modules/r.cxx | 6 |
10 files changed, 68 insertions, 8 deletions
diff --git a/CHANGES.current b/CHANGES.current index ffebbac46..e5971db72 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-10-24: wsfulton + [R] Polymorphism in the wrappers was only working for C++ classes, + now this works for C++ structs too. + 2022-10-19: olly [Lua] #2126 Fix type resolution between multiple SWIG-wrapped modules. diff --git a/Examples/test-suite/go/typedef_inherit_runme.go b/Examples/test-suite/go/typedef_inherit_runme.go index f2dbb3263..eef3ef47a 100644 --- a/Examples/test-suite/go/typedef_inherit_runme.go +++ b/Examples/test-suite/go/typedef_inherit_runme.go @@ -28,4 +28,9 @@ func main() { if x != "Grok::blah" { panic(x) } + + x = d.Far() + if x != "Spam::far" { + panic(x) + } } diff --git a/Examples/test-suite/javascript/typedef_inherit_runme.js b/Examples/test-suite/javascript/typedef_inherit_runme.js index 7590e1e6e..1ebb128da 100644 --- a/Examples/test-suite/javascript/typedef_inherit_runme.js +++ b/Examples/test-suite/javascript/typedef_inherit_runme.js @@ -21,3 +21,7 @@ if (x != "Spam::blah") x = typedef_inherit.do_blah2(d); if (x != "Grok::blah") print ("Whoa! Bad return" + x); + +x = d.far(); +if (x != "Spam::far") + print ("Whoa! Bad return" + x); diff --git a/Examples/test-suite/ocaml/typedef_inherit_runme.ml b/Examples/test-suite/ocaml/typedef_inherit_runme.ml index 6352fd4ad..a5feb7c3f 100644 --- a/Examples/test-suite/ocaml/typedef_inherit_runme.ml +++ b/Examples/test-suite/ocaml/typedef_inherit_runme.ml @@ -7,5 +7,6 @@ let _ = assert (_do_blah (b) as string = "Bar::blah"); let c = new_Spam '() and d = new_Grok '() in assert (_do_blah2 (c) as string = "Spam::blah"); - assert (_do_blah2 (d) as string = "Grok::blah") + assert (_do_blah2 (d) as string = "Grok::blah"); + assert (d -> far() as string = "Spam::far") ;; diff --git a/Examples/test-suite/octave/typedef_inherit_runme.m b/Examples/test-suite/octave/typedef_inherit_runme.m index fbe5436d1..b562e3125 100644 --- a/Examples/test-suite/octave/typedef_inherit_runme.m +++ b/Examples/test-suite/octave/typedef_inherit_runme.m @@ -30,3 +30,8 @@ x = typedef_inherit.do_blah2(d); if (!strcmp(x,"Grok::blah")) error("Whoa! Bad return", x) endif + +x = d.far(); +if (!strcmp(x,"Spam::far")) + error("Whoa! Bad return", x) +endif diff --git a/Examples/test-suite/python/typedef_inherit_runme.py b/Examples/test-suite/python/typedef_inherit_runme.py index 3c552ec65..020e4cc5e 100644 --- a/Examples/test-suite/python/typedef_inherit_runme.py +++ b/Examples/test-suite/python/typedef_inherit_runme.py @@ -21,3 +21,7 @@ if x != "Spam::blah": x = typedef_inherit.do_blah2(d) if x != "Grok::blah": raise RuntimeError("Whoa! Bad return {}".format(x)) + +x = d.far() +if x != "Spam::far": + raise RuntimeError("Whoa! Bad return {}".format(x)) diff --git a/Examples/test-suite/r/typedef_inherit_runme.R b/Examples/test-suite/r/typedef_inherit_runme.R new file mode 100644 index 000000000..3589f93b9 --- /dev/null +++ b/Examples/test-suite/r/typedef_inherit_runme.R @@ -0,0 +1,29 @@ +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + +dyn.load(paste("typedef_inherit", .Platform$dynlib.ext, sep="")) +source("typedef_inherit.R") +cacheMetaData(1) + + +a <- Foo() +b <- Bar() + +x <- do_blah(a) +unittest(x, "Foo::blah") + +x <- do_blah(b) +unittest(x, "Bar::blah") + +c <- Spam() +d <- Grok() + +x <- do_blah2(c) +unittest(x, "Spam::blah") + +x <- do_blah2(d) +unittest(x, "Grok::blah") + +unittest(d$far(), "Spam::far") + +q(save="no") diff --git a/Examples/test-suite/ruby/typedef_inherit_runme.rb b/Examples/test-suite/ruby/typedef_inherit_runme.rb index 029b80c70..10f155b3b 100644 --- a/Examples/test-suite/ruby/typedef_inherit_runme.rb +++ b/Examples/test-suite/ruby/typedef_inherit_runme.rb @@ -36,3 +36,9 @@ x = Typedef_inherit.do_blah2(d) if x != "Grok::blah" puts "Whoa! Bad return #{x}" end + +x = d.far +if x != "Spam::far" + puts "Whoa! Bad return #{x}" +end + diff --git a/Examples/test-suite/typedef_inherit.i b/Examples/test-suite/typedef_inherit.i index 48821a146..54968b81b 100644 --- a/Examples/test-suite/typedef_inherit.i +++ b/Examples/test-suite/typedef_inherit.i @@ -30,9 +30,13 @@ typedef struct spam { { } - virtual char *blah() { - return (char *) "Spam::blah"; - } + virtual char *blah() { + return (char *) "Spam::blah"; + } + + const char *far() { + return "Spam::far"; + } } Spam; struct Grok : public Spam { diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 526d959f4..2256610d5 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -215,8 +215,7 @@ public: int typedefHandler(Node *n); - static List *Swig_overload_rank(Node *n, - bool script_lang_wrapping); + static List *Swig_overload_rank(Node *n, bool script_lang_wrapping); int memberfunctionHandler(Node *n) { if (debugMode) @@ -2295,7 +2294,6 @@ int R::outputRegistrationRoutines(File *out) { void R::registerClass(Node *n) { String *name = Getattr(n, "name"); - String *kind = Getattr(n, "kind"); if (debugMode) Swig_print_node(n); @@ -2304,7 +2302,7 @@ void R::registerClass(Node *n) { Setattr(SClassDefs, sname, sname); String *base; - if(Strcmp(kind, "class") == 0) { + if (CPlusPlus && (Strcmp(nodeType(n), "class") == 0)) { base = NewString(""); List *l = Getattr(n, "bases"); if(Len(l)) { |