mirror of https://github.com/swig/swig
Redundant code removal in nested.cxx
c96c04c5ae
Replicate changes in this commit to add_symbols() for add_symbols_c().
Setting feature:immutable is now done in Allocate:cDeclaration.
Setting hasconsttype for static const variables (or constexpr) doesn't
look possible in this situation (C code for anonymous structs) - no
valid C syntax that I can figure out.
Anonymous nested structs are necessarily read-only (and set as
immutable in Swig_nested_name_unnamed_c_structs).
From https://sourceforge.net/p/swig/bugs/793/ ...
The union variable intRep below has a named type IntRepType.
typedef struct Object {
int objtype;
union IntRepType {
double dvalue;
} intRep;
} Object;
void tester() {
/* approach (1) */
obj.intRep.dvalue = 1.23;
/* approach (2) */
union IntRepType irt;
irt.dvalue = 2.34;
obj.intRep = irt;
}
Using C code there are two approaches to setting a value in intRep. Equivalents in perl are:
my $obj = example::Object->new();
# approach (1)
$obj->{intRep}->{dvalue} = 3.45;
# approach (2)
my $irt = example::IntRepType->new();
$irt->{dvalue} = 4.56;
$obj->{intRep} = $irt;
An Object_intRep_set wrapper is generated which takes type IntRepType as desired.
However, with an anonymous union:
typedef struct Object {
int objtype;
union IntRepType {
double dvalue;
} intRep;
} Object;
intRep does not have any named type name and is anonymous. It is thus not possible to create a type outside of Object to assign to intRep.
Only approach (1) is available in C and so SWIG can only provide approach (1) via wrappers too.
There is no Object_intRep_set wrapper, intRep is immutable.
This commit is contained in:
parent
790f36c28b
commit
a28b8cfed4
|
@ -58,22 +58,6 @@ static void add_symbols_c(Node *n) {
|
|||
if (value && Len(value)) {
|
||||
Setattr(n, "hasvalue", "1");
|
||||
}
|
||||
if (type) {
|
||||
SwigType *ty;
|
||||
SwigType *tmp = 0;
|
||||
if (decl) {
|
||||
ty = tmp = Copy(type);
|
||||
SwigType_push(ty, decl);
|
||||
} else {
|
||||
ty = type;
|
||||
}
|
||||
if (!SwigType_ismutable(ty)) {
|
||||
SetFlag(n, "hasconsttype");
|
||||
SetFlag(n, "feature:immutable");
|
||||
}
|
||||
if (tmp)
|
||||
Delete(tmp);
|
||||
}
|
||||
if (!type) {
|
||||
Printf(stderr, "notype name %s\n", name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue