aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2013-12-12 07:59:47 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2013-12-12 09:00:16 +0000
commite95ac8265154e1f3f9f05406c7f800182f1350b9 (patch)
treed6a648cb99b324f6d74d52d516c05fb0f9d06916 /Source
parentcf3696e8f905ae4e67340a839f8f17cda4549271 (diff)
downloadswig-e95ac8265154e1f3f9f05406c7f800182f1350b9.tar.gz
Nested C class setters restored in c++out mode for Octave
Suitable casts are required so that assignment of instances of nested classes work as the nested class is duplicated in the global namespace, eg: struct Outer { struct Nested { int bar; } bar_instance; }; Outer.bar_instance can now be assigned to.
Diffstat (limited to 'Source')
-rw-r--r--Source/CParse/parser.y4
-rw-r--r--Source/Swig/cwrap.c21
2 files changed, 22 insertions, 3 deletions
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 0124ad25a..8e34833e2 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -3513,7 +3513,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
while (p) {
Setattr(p, "storage", $1);
Setattr(p, "type" ,ty);
- if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
+ if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name"))) {
SetFlag(p, "hasconsttype");
SetFlag(p, "feature:immutable");
}
@@ -3674,7 +3674,7 @@ cpp_class_decl : storage_class cpptype idcolon inherit LBRACE {
while (n) {
Setattr(n,"storage",$1);
Setattr(n, "type", ty);
- if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name") || CPlusPlusOut)) {
+ if (!cparse_cplusplus && currentOuterClass && (!Getattr(currentOuterClass, "name"))) {
SetFlag(n,"hasconsttype");
SetFlag(n,"feature:immutable");
}
diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
index 6f8fa39e9..03020bb72 100644
--- a/Source/Swig/cwrap.c
+++ b/Source/Swig/cwrap.c
@@ -15,6 +15,7 @@
#include "swig.h"
extern int cparse_cplusplus;
+extern int CPlusPlusOut;
static const char *cresult_variable_name = "result";
static Parm *nonvoid_parms(Parm *p) {
@@ -775,7 +776,25 @@ String *Swig_cmemberset_call(const_String_or_char_ptr name, SwigType *type, Stri
if (SwigType_type(type) != T_ARRAY) {
if (!Strstr(type, "enum $unnamed")) {
String *dref = Swig_wrapped_var_deref(type, pname1, varcref);
- Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
+ int extra_cast = 0;
+ if (CPlusPlusOut) {
+ /* Required for C nested structs compiled as C++ as a duplicate of the nested struct is put into the global namespace.
+ * We could improve this by adding the extra casts just for nested structs rather than all structs. */
+ String *base = SwigType_base(type);
+ extra_cast = SwigType_isclass(base);
+ Delete(base);
+ }
+ if (extra_cast) {
+ String *lstr;
+ SwigType *ptype = Copy(type);
+ SwigType_add_pointer(ptype);
+ lstr = SwigType_lstr(ptype, 0);
+ Printf(func, "if (%s) *(%s)&%s%s = %s", pname0, lstr, self, name, dref);
+ Delete(lstr);
+ Delete(ptype);
+ } else {
+ Printf(func, "if (%s) %s%s = %s", pname0, self, name, dref);
+ }
Delete(dref);
} else {
Printf(func, "if (%s && sizeof(int) == sizeof(%s%s)) *(int*)(void*)&(%s%s) = %s", pname0, self, name, self, name, pname1);