diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CParse/parser.y | 4 | ||||
-rw-r--r-- | Source/Swig/cwrap.c | 21 |
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); |