Polymorphism in R wrappers fixed for C++ structs

This commit is contained in:
William S Fulton 2022-10-24 08:41:42 +01:00
parent cfd2557cda
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)
===========================
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.

View File

@ -28,4 +28,9 @@ func main() {
if x != "Grok::blah" {
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);
if (x != "Grok::blah")
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");
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")
;;

View File

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

View File

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

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"
puts "Whoa! Bad return #{x}"
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() {
return (char *) "Spam::blah";
}
virtual char *blah() {
return (char *) "Spam::blah";
}
const char *far() {
return "Spam::far";
}
} Spam;
struct Grok : public Spam {

View File

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