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 though 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
47
SWIG_InitializeModule(void *clientdata) {
48
swig_type_info *type, *ret;
51
swig_module_info *module_head;
52
static int init_run = 0;
54
clientdata = clientdata;
59
/* Initialize the swig_module */
60
swig_module.type_initial = swig_type_initial;
61
swig_module.cast_initial = swig_cast_initial;
63
/* Try and load any already created modules */
64
module_head = SWIG_GetModule(clientdata);
66
swig_module.next = module_head->next;
67
module_head->next = &swig_module;
69
/* This is the first module loaded */
70
swig_module.next = &swig_module;
71
SWIG_SetModule(clientdata, &swig_module);
74
/* Now work on filling in swig_module.types */
75
for (i = 0; i < swig_module.size; ++i) {
78
/* if there is another module already loaded */
79
if (swig_module.next != &swig_module) {
80
type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
83
/* Overwrite clientdata field */
84
if (swig_module.type_initial[i]->clientdata) type->clientdata = swig_module.type_initial[i]->clientdata;
86
type = swig_module.type_initial[i];
89
/* Insert casting types */
90
cast = swig_module.cast_initial[i];
93
/* Don't need to add information already in the list */
95
if (swig_module.next != &swig_module) {
96
ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
98
if (ret && type == swig_module.type_initial[i]) {
105
type->cast->prev = cast;
106
cast->next = type->cast;
114
/* Set entry in modules->types array equal to the type */
115
swig_module.types[i] = type;
117
swig_module.types[i] = 0;
120
/* This function will propagate the clientdata field of type to
121
* any new swig_type_info structures that have been added into the list
122
* of equivalent types. It is like calling
123
* SWIG_TypeClientData(type, clientdata) a second time.
126
SWIG_PropagateClientData(void) {
128
swig_cast_info *equiv;
129
static int init_run = 0;
131
if (init_run) return;
134
for (i = 0; i < swig_module.size; i++) {
135
if (swig_module.types[i]->clientdata) {
136
equiv = swig_module.types[i]->cast;
138
if (!equiv->converter) {
139
if (equiv->type && !equiv->type->clientdata)
140
SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);