From 781379351167f11873bf15feb78ed500795aecda Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Mon, 31 Jan 2022 12:05:09 +1300 Subject: [PATCH] [R] Fix CopyToR() generated for struct in namespace Fixes https://sourceforge.net/p/swig/bugs/1147/ --- CHANGES.current | 4 ++++ Examples/test-suite/common.mk | 1 + Examples/test-suite/namespace_struct.i | 8 ++++++++ Examples/test-suite/r/namespace_struct_runme.R | 11 +++++++++++ Source/Modules/r.cxx | 2 +- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/namespace_struct.i create mode 100644 Examples/test-suite/r/namespace_struct_runme.R diff --git a/CHANGES.current b/CHANGES.current index 3fd325490..3b1dba0e7 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-01-31: mreeez + https://sourceforge.net/p/swig/bugs/1147/ + Fix copyToR() generated for a struct in a namespace. + 2022-01-29: fschlimb #655 Better handling of using declarations. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 86f052de5..d06766b34 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -315,6 +315,7 @@ CPP_TEST_CASES += \ namespace_forward_declaration \ namespace_nested \ namespace_spaces \ + namespace_struct \ namespace_template \ namespace_typedef_class \ namespace_typemap \ diff --git a/Examples/test-suite/namespace_struct.i b/Examples/test-suite/namespace_struct.i new file mode 100644 index 000000000..2d2bf555a --- /dev/null +++ b/Examples/test-suite/namespace_struct.i @@ -0,0 +1,8 @@ +%module namespace_struct + +%inline %{ + +// SWIG/R generated bad code for copyToR for a struct in a namespace in SWIG < 4.1.0 +namespace X { struct Y { int x, y; }; } + +%} diff --git a/Examples/test-suite/r/namespace_struct_runme.R b/Examples/test-suite/r/namespace_struct_runme.R new file mode 100644 index 000000000..f84ef3054 --- /dev/null +++ b/Examples/test-suite/r/namespace_struct_runme.R @@ -0,0 +1,11 @@ +clargs <- commandArgs(trailing=TRUE) +source(file.path(clargs[1], "unittest.R")) + +dyn.load(paste("namespace_struct", .Platform$dynlib.ext, sep="")) +source("namespace_struct.R") +cacheMetaData(1) + +xy = Y() +xy$x = as.integer(2) +xy$y = as.integer(4) +copyToR(xy) diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx index 99db2275f..ca9ce649c 100644 --- a/Source/Modules/r.cxx +++ b/Source/Modules/r.cxx @@ -2569,7 +2569,7 @@ int R::generateCopyRoutines(Node *n) { Printf(sfile, "# Start definition of copy methods for %s\n", rclassName); - Printf(sfile, "setMethod('copyToR', '_p_%s', CopyToR%s);\n", rclassName, + Printf(sfile, "setMethod('copyToR', '_p%s', CopyToR%s);\n", mangledName, mangledName); Printf(sfile, "setMethod('copyToC', '%s', CopyToC%s);\n\n", rclassName, mangledName);