File: nested_structs.i

package info (click to toggle)
renderdoc 1.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 79,584 kB
  • sloc: cpp: 491,671; ansic: 285,823; python: 12,617; java: 11,345; cs: 7,181; makefile: 6,703; yacc: 5,682; ruby: 4,648; perl: 3,461; php: 2,119; sh: 2,068; lisp: 1,835; tcl: 1,068; ml: 747; xml: 137
file content (58 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%module nested_structs

#if defined(SWIG_JAVASCRIPT_V8)

%inline %{
#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
/* for nested C class wrappers compiled as C++ code */
/* dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] */
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
%}

#endif

// bug #491476
%inline %{
struct Outer {
  struct {
    int val;
  } inner1, inner2, *inner3, inner4[1], **inner5;
  struct Named {
    int val;
  } inside1, inside2, *inside3, inside4[1], **inside5;
} outer;

void setValues(struct Outer *outer, int val) {
  outer->inner1.val = val;
  outer->inner2.val = val * 2;
  outer->inner3 = &outer->inner2;
  outer->inner4[0].val = val * 4;
  outer->inner5 = &outer->inner3;

  val = val * 10;
  outer->inside1.val = val;
  outer->inside2.val = val * 2;
  outer->inside3 = &outer->inside2;
  outer->inside4[0].val = val * 4;
  outer->inside5 = &outer->inside3;
}

int getInside1Val(struct Outer *n) { return n->inside1.val; }
%}

/* 
Below was causing problems in Octave as wrappers were compiled as C++.
Solution requires regenerating the inner struct into
the global C++ namespace (which is where it is intended to be in C).
See cparse_cplusplusout / Swig_cparse_cplusplusout in the Source.
*/
%inline %{
int nestedByVal(struct Named s);
int nestedByPtr(struct Named *s);
%}
%{
int nestedByVal(struct Named s) { return s.val; }
int nestedByPtr(struct Named *s) { return s->val; }
%}