Polymorphism in R wrappers fixed for C++ structs

This commit is contained in:
William S Fulton 2022-10-24 08:41:42 +01:00
commit 1d73341aa4
10 changed files with 68 additions and 8 deletions

View file

@ -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) 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 2022-10-19: olly
[Lua] #2126 Fix type resolution between multiple SWIG-wrapped [Lua] #2126 Fix type resolution between multiple SWIG-wrapped
modules. modules.

View file

@ -28,4 +28,9 @@ func main() {
if x != "Grok::blah" { if x != "Grok::blah" {
panic(x) panic(x)
} }
x = d.Far()
if x != "Spam::far" {
panic(x)
}
} }

View file

@ -21,3 +21,7 @@ if (x != "Spam::blah")
x = typedef_inherit.do_blah2(d); x = typedef_inherit.do_blah2(d);
if (x != "Grok::blah") if (x != "Grok::blah")
print ("Whoa! Bad return" + x); print ("Whoa! Bad return" + x);
x = d.far();
if (x != "Spam::far")
print ("Whoa! Bad return" + x);

View file

@ -7,5 +7,6 @@ let _ =
assert (_do_blah (b) as string = "Bar::blah"); assert (_do_blah (b) as string = "Bar::blah");
let c = new_Spam '() and d = new_Grok '() in let c = new_Spam '() and d = new_Grok '() in
assert (_do_blah2 (c) as string = "Spam::blah"); 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")
;; ;;

View file

@ -30,3 +30,8 @@ x = typedef_inherit.do_blah2(d);
if (!strcmp(x,"Grok::blah")) if (!strcmp(x,"Grok::blah"))
error("Whoa! Bad return", x) error("Whoa! Bad return", x)
endif endif
x = d.far();
if (!strcmp(x,"Spam::far"))
error("Whoa! Bad return", x)
endif

View file

@ -21,3 +21,7 @@ if x != "Spam::blah":
x = typedef_inherit.do_blah2(d) x = typedef_inherit.do_blah2(d)
if x != "Grok::blah": if x != "Grok::blah":
raise RuntimeError("Whoa! Bad return {}".format(x)) raise RuntimeError("Whoa! Bad return {}".format(x))
x = d.far()
if x != "Spam::far":
raise RuntimeError("Whoa! Bad return {}".format(x))

View file

@ -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")

View file

@ -36,3 +36,9 @@ x = Typedef_inherit.do_blah2(d)
if x != "Grok::blah" if x != "Grok::blah"
puts "Whoa! Bad return #{x}" puts "Whoa! Bad return #{x}"
end end
x = d.far
if x != "Spam::far"
puts "Whoa! Bad return #{x}"
end

View file

@ -30,9 +30,13 @@ typedef struct spam {
{ {
} }
virtual char *blah() { virtual char *blah() {
return (char *) "Spam::blah"; return (char *) "Spam::blah";
} }
const char *far() {
return "Spam::far";
}
} Spam; } Spam;
struct Grok : public Spam { struct Grok : public Spam {

View file

@ -215,8 +215,7 @@ public:
int typedefHandler(Node *n); int typedefHandler(Node *n);
static List *Swig_overload_rank(Node *n, static List *Swig_overload_rank(Node *n, bool script_lang_wrapping);
bool script_lang_wrapping);
int memberfunctionHandler(Node *n) { int memberfunctionHandler(Node *n) {
if (debugMode) if (debugMode)
@ -2295,7 +2294,6 @@ int R::outputRegistrationRoutines(File *out) {
void R::registerClass(Node *n) { void R::registerClass(Node *n) {
String *name = Getattr(n, "name"); String *name = Getattr(n, "name");
String *kind = Getattr(n, "kind");
if (debugMode) if (debugMode)
Swig_print_node(n); Swig_print_node(n);
@ -2304,7 +2302,7 @@ void R::registerClass(Node *n) {
Setattr(SClassDefs, sname, sname); Setattr(SClassDefs, sname, sname);
String *base; String *base;
if(Strcmp(kind, "class") == 0) { if (CPlusPlus && (Strcmp(nodeType(n), "class") == 0)) {
base = NewString(""); base = NewString("");
List *l = Getattr(n, "bases"); List *l = Getattr(n, "bases");
if(Len(l)) { if(Len(l)) {