Skip to content

Commit 1d73341

Browse files
committed
Polymorphism in R wrappers fixed for C++ structs
1 parent cfd2557 commit 1d73341

File tree

10 files changed

+68
-8
lines changed

10 files changed

+68
-8
lines changed

CHANGES.current

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
77
Version 4.1.0 (in progress)
88
===========================
99

10+
2022-10-24: wsfulton
11+
[R] Polymorphism in the wrappers was only working for C++ classes,
12+
now this works for C++ structs too.
13+
1014
2022-10-19: olly
1115
[Lua] #2126 Fix type resolution between multiple SWIG-wrapped
1216
modules.

Examples/test-suite/go/typedef_inherit_runme.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ func main() {
2828
if x != "Grok::blah" {
2929
panic(x)
3030
}
31+
32+
x = d.Far()
33+
if x != "Spam::far" {
34+
panic(x)
35+
}
3136
}

Examples/test-suite/javascript/typedef_inherit_runme.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ if (x != "Spam::blah")
2121
x = typedef_inherit.do_blah2(d);
2222
if (x != "Grok::blah")
2323
print ("Whoa! Bad return" + x);
24+
25+
x = d.far();
26+
if (x != "Spam::far")
27+
print ("Whoa! Bad return" + x);

Examples/test-suite/ocaml/typedef_inherit_runme.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ let _ =
77
assert (_do_blah (b) as string = "Bar::blah");
88
let c = new_Spam '() and d = new_Grok '() in
99
assert (_do_blah2 (c) as string = "Spam::blah");
10-
assert (_do_blah2 (d) as string = "Grok::blah")
10+
assert (_do_blah2 (d) as string = "Grok::blah");
11+
assert (d -> far() as string = "Spam::far")
1112
;;

Examples/test-suite/octave/typedef_inherit_runme.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@
3030
if (!strcmp(x,"Grok::blah"))
3131
error("Whoa! Bad return", x)
3232
endif
33+
34+
x = d.far();
35+
if (!strcmp(x,"Spam::far"))
36+
error("Whoa! Bad return", x)
37+
endif

Examples/test-suite/python/typedef_inherit_runme.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@
2121
x = typedef_inherit.do_blah2(d)
2222
if x != "Grok::blah":
2323
raise RuntimeError("Whoa! Bad return {}".format(x))
24+
25+
x = d.far()
26+
if x != "Spam::far":
27+
raise RuntimeError("Whoa! Bad return {}".format(x))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
clargs <- commandArgs(trailing=TRUE)
2+
source(file.path(clargs[1], "unittest.R"))
3+
4+
dyn.load(paste("typedef_inherit", .Platform$dynlib.ext, sep=""))
5+
source("typedef_inherit.R")
6+
cacheMetaData(1)
7+
8+
9+
a <- Foo()
10+
b <- Bar()
11+
12+
x <- do_blah(a)
13+
unittest(x, "Foo::blah")
14+
15+
x <- do_blah(b)
16+
unittest(x, "Bar::blah")
17+
18+
c <- Spam()
19+
d <- Grok()
20+
21+
x <- do_blah2(c)
22+
unittest(x, "Spam::blah")
23+
24+
x <- do_blah2(d)
25+
unittest(x, "Grok::blah")
26+
27+
unittest(d$far(), "Spam::far")
28+
29+
q(save="no")

Examples/test-suite/ruby/typedef_inherit_runme.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@
3636
if x != "Grok::blah"
3737
puts "Whoa! Bad return #{x}"
3838
end
39+
40+
x = d.far
41+
if x != "Spam::far"
42+
puts "Whoa! Bad return #{x}"
43+
end
44+

Examples/test-suite/typedef_inherit.i

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ typedef struct spam {
3030
{
3131
}
3232

33-
virtual char *blah() {
34-
return (char *) "Spam::blah";
35-
}
33+
virtual char *blah() {
34+
return (char *) "Spam::blah";
35+
}
36+
37+
const char *far() {
38+
return "Spam::far";
39+
}
3640
} Spam;
3741

3842
struct Grok : public Spam {

Source/Modules/r.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ class R : public Language {
215215

216216
int typedefHandler(Node *n);
217217

218-
static List *Swig_overload_rank(Node *n,
219-
bool script_lang_wrapping);
218+
static List *Swig_overload_rank(Node *n, bool script_lang_wrapping);
220219

221220
int memberfunctionHandler(Node *n) {
222221
if (debugMode)
@@ -2295,7 +2294,6 @@ int R::outputRegistrationRoutines(File *out) {
22952294

22962295
void R::registerClass(Node *n) {
22972296
String *name = Getattr(n, "name");
2298-
String *kind = Getattr(n, "kind");
22992297

23002298
if (debugMode)
23012299
Swig_print_node(n);
@@ -2304,7 +2302,7 @@ void R::registerClass(Node *n) {
23042302
Setattr(SClassDefs, sname, sname);
23052303
String *base;
23062304

2307-
if(Strcmp(kind, "class") == 0) {
2305+
if (CPlusPlus && (Strcmp(nodeType(n), "class") == 0)) {
23082306
base = NewString("");
23092307
List *l = Getattr(n, "bases");
23102308
if(Len(l)) {

0 commit comments

Comments
 (0)