|
From: William S F. <no...@gi...> - 2023-09-10 12:06:52
|
Branch: refs/heads/master Home: https://github.com/swig/swig Commit: a28b8cfed4ed09eee17ade562bd112cf02717673 https://github.com/swig/swig/commit/a28b8cfed4ed09eee17ade562bd112cf02717673 Author: William S Fulton <ws...@fu...> Date: 2023-09-10 (Sun, 10 Sep 2023) Changed paths: M Source/Modules/nested.cxx Log Message: ----------- Redundant code removal in nested.cxx c96c04c5aef0a3d2aa9c12da4bafff0053fca482 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. |