1 %module derived_byvalue
2 
3 #ifdef SWIGOCAML
4 %warnfilter(SWIGWARN_PARSE_KEYWORD) method;
5 #endif
6 
7 %inline %{
8 
9 struct Foo {
10   int x;
11 
12   // this works
rmethodFoo13   int rmethod(const Foo& f) { return f.x; }
14 
15   // this doesn't when DerFoo (below) is introduced
methodFoo16   int method(Foo f) { return f.x; }
17 };
18 
19 struct Bar {
20    Foo   a;
21    struct Foo b;
22 };
23 
24 /*
25   When the next derived class is declared, the
26   following bad method is generated
27 
28   static void *_DerFooTo_Foo(void *x) {   // **** bad ****
29     return (void *)((Foo)  ((DerFoo) x));
30   }
31 
32   static void *_p_DerFooTo_p_Foo(void *x) {   // *** good ***
33     return (void *)((Foo *)  ((DerFoo *) x));
34   }
35 
36   if the derived class is deleted, it works again
37 
38   if the previous Foo::method is deleted, it works again
39 
40  */
41 struct DerFoo : Foo {
42 };
43 
44 /*
45   The problem is caused by accidentally remembering a object value type
46   instead of an object pointer type.
47   During the course of SWIGing a file, several calls to SwigType_remember()
48   or SwigType_remember_clientdata() will be made.
49   When the SwigType_emit_type_table() function is called it emits all the
50   type conversion functions.
51 
52   If a object type exists in the SwigType table, you get this error.
53 
54   You can view the SwigType table, with a #define DEBUG at the top of
55   Source/Swig/typesys.c
56 
57   When run you get an output like this:
58 
59 ---r_mangled---
60 Hash {
61     '_p_Bar' : Hash {
62         'p.Bar' : _p_Bar,
63     }
64 ,
65     '_p_DerFoo' : Hash {
66         'p.DerFoo' : _p_DerFoo,
67     }
68 ,
69     '_p_Foo' : Hash {
70         'r.Foo' : _p_Foo,
71         'p.Foo' : _p_Foo,
72     }
73 ,
74     '_Foo' : Hash {
75         'Foo' : _Foo,
76     }
77 ,
78 }
79 ....
80 
81   The last field ('_Foo') is an object type and caused the error.
82   It can be fixed either by checking all the calls to SwigType_remember()
83   and by checking the typemaps.
84   The typemap code also calls SwigType_remember(), if your typemaps
85   defined an object type, it will be added into the SwigType table.
86   its normally a
87     SWIG_ConvertPtr(....$descriptor...)
88   when it should have been a $&descriptor or $*descriptor
89 
90   Commenting out all your object typemaps (and typecheck fns) may help
91   isolate it.
92 
93 */
94 #
95 %}
96