1 /* -----------------------------------------------------------------------------
3 * This problem is tough by the requirement that no dynamic
4 * memory is used. Also, since swig_type_info structures store pointers to
5 * swig_cast_info structures and swig_cast_info structures store pointers back
6 * to swig_type_info structures, we need some lookup code at initialization.
7 * The idea is that swig generates all the structures that are needed.
8 * The runtime then collects these partially filled structures.
9 * The SWIG_InitializeModule function takes these initial arrays out of
10 * swig_module, and does all the lookup, filling in the swig_module.types
11 * array with the correct data and linking the correct swig_cast_info
12 * structures together.
14 * The generated swig_type_info structures are assigned staticly to an initial
15 * array. We just loop through that array, and handle each type individually.
16 * First we lookup if this type has been already loaded, and if so, use the
17 * loaded structure instead of the generated one. Then we have to fill in the
18 * cast linked list. The cast data is initially stored in something like a
19 * two-dimensional array. Each row corresponds to a type (there are the same
20 * number of rows as there are in the swig_type_initial array). Each entry in
21 * a column is one of the swig_cast_info structures for that type.
22 * The cast_initial array is actually an array of arrays, because each row has
23 * a variable number of columns. So to actually build the cast linked list,
24 * we find the array of casts associated with the type, and loop through it
25 * adding the casts to the list. The one last trick we need to do is making
26 * sure the type pointer in the swig_cast_info struct is correct.
28 * First off, we lookup the cast->type name to see if it is already loaded.
29 * There are three cases to handle:
30 * 1) If the cast->type has already been loaded AND the type we are adding
31 * casting info to has not been loaded (it is in this module), THEN we
32 * replace the cast->type pointer with the type pointer that has already
34 * 2) If BOTH types (the one we are adding casting info to, and the
35 * cast->type) are loaded, THEN the cast info has already been loaded by
36 * the previous module so we just ignore it.
37 * 3) Finally, if cast->type has not already been loaded, then we add that
38 * swig_cast_info to the linked list (because the cast->type) pointer will
40 * ----------------------------------------------------------------------------- */
50 #define SWIGRUNTIME_DEBUG
55 SWIG_InitializeModule(void *clientdata) {
57 swig_module_info *module_head, *iter;
60 clientdata = clientdata;
62 /* check to see if the circular list has been setup, if not, set it up */
63 if (swig_module.next==0) {
64 /* Initialize the swig_module */
65 swig_module.type_initial = swig_type_initial;
66 swig_module.cast_initial = swig_cast_initial;
67 swig_module.next = &swig_module;
73 /* Try and load any already created modules */
74 module_head = SWIG_GetModule(clientdata);
76 /* This is the first module loaded for this interpreter */
77 /* so set the swig module into the interpreter */
78 SWIG_SetModule(clientdata, &swig_module);
79 module_head = &swig_module;
81 /* the interpreter has loaded a SWIG module, but has it loaded this one? */
85 if (iter==&swig_module) {
90 } while (iter!= module_head);
92 /* if the is found in the list, then all is done and we may leave */
94 /* otherwise we must add out module into the list */
95 swig_module.next = module_head->next;
96 module_head->next = &swig_module;
99 /* When multiple interpeters are used, a module could have already been initialized in
100 a different interpreter, but not yet have a pointer in this interpreter.
101 In this case, we do not want to continue adding types... everything should be
103 if (init == 0) return;
105 /* Now work on filling in swig_module.types */
106 #ifdef SWIGRUNTIME_DEBUG
107 printf("SWIG_InitializeModule: size %d\n", swig_module.size);
109 for (i = 0; i < swig_module.size; ++i) {
110 swig_type_info *type = 0;
112 swig_cast_info *cast;
114 #ifdef SWIGRUNTIME_DEBUG
115 printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
118 /* if there is another module already loaded */
119 if (swig_module.next != &swig_module) {
120 type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
123 /* Overwrite clientdata field */
124 #ifdef SWIGRUNTIME_DEBUG
125 printf("SWIG_InitializeModule: found type %s\n", type->name);
127 if (swig_module.type_initial[i]->clientdata) {
128 type->clientdata = swig_module.type_initial[i]->clientdata;
129 #ifdef SWIGRUNTIME_DEBUG
130 printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
134 type = swig_module.type_initial[i];
137 /* Insert casting types */
138 cast = swig_module.cast_initial[i];
141 /* Don't need to add information already in the list */
143 #ifdef SWIGRUNTIME_DEBUG
144 printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
146 if (swig_module.next != &swig_module) {
147 ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
148 #ifdef SWIGRUNTIME_DEBUG
149 if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
153 if (type == swig_module.type_initial[i]) {
154 #ifdef SWIGRUNTIME_DEBUG
155 printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
160 /* Check for casting already in the list */
161 swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
162 #ifdef SWIGRUNTIME_DEBUG
163 if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
170 #ifdef SWIGRUNTIME_DEBUG
171 printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
174 type->cast->prev = cast;
175 cast->next = type->cast;
181 /* Set entry in modules->types array equal to the type */
182 swig_module.types[i] = type;
184 swig_module.types[i] = 0;
186 #ifdef SWIGRUNTIME_DEBUG
187 printf("**** SWIG_InitializeModule: Cast List ******\n");
188 for (i = 0; i < swig_module.size; ++i) {
190 swig_cast_info *cast = swig_module.cast_initial[i];
191 printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
193 printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
197 printf("---- Total casts: %d\n",j);
199 printf("**** SWIG_InitializeModule: Cast List ******\n");
203 /* This function will propagate the clientdata field of type to
204 * any new swig_type_info structures that have been added into the list
205 * of equivalent types. It is like calling
206 * SWIG_TypeClientData(type, clientdata) a second time.
209 SWIG_PropagateClientData(void) {
211 swig_cast_info *equiv;
212 static int init_run = 0;
214 if (init_run) return;
217 for (i = 0; i < swig_module.size; i++) {
218 if (swig_module.types[i]->clientdata) {
219 equiv = swig_module.types[i]->cast;
221 if (!equiv->converter) {
222 if (equiv->type && !equiv->type->clientdata)
223 SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);