~ubuntu-branches/ubuntu/edgy/swig1.3/edgy

« back to all changes in this revision

Viewing changes to Lib/swiginit.swg

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:16:04 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205011604-ygx904it6413k3go
Tags: 1.3.27-1ubuntu1
Resynchronise with Debian again, for the new subversion packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 * Type initialization:
 
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.
 
13
 
 
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.
 
27
 
 
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
 
33
 *     been loaded.
 
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
 
39
 *     be correct.
 
40
**/
 
41
 
 
42
#ifdef __cplusplus
 
43
extern "C" {
 
44
#endif
 
45
 
 
46
SWIGRUNTIME void
 
47
SWIG_InitializeModule(void *clientdata) {
 
48
  swig_type_info *type, *ret;
 
49
  swig_cast_info *cast;
 
50
  size_t i;
 
51
  swig_module_info *module_head;
 
52
  static int init_run = 0;
 
53
 
 
54
  clientdata = clientdata;
 
55
 
 
56
  if (init_run) return;
 
57
  init_run = 1;
 
58
 
 
59
  /* Initialize the swig_module */
 
60
  swig_module.type_initial = swig_type_initial;
 
61
  swig_module.cast_initial = swig_cast_initial;
 
62
 
 
63
  /* Try and load any already created modules */
 
64
  module_head = SWIG_GetModule(clientdata);
 
65
  if (module_head) {
 
66
    swig_module.next = module_head->next;
 
67
    module_head->next = &swig_module;
 
68
  } else {
 
69
    /* This is the first module loaded */
 
70
    swig_module.next = &swig_module;
 
71
    SWIG_SetModule(clientdata, &swig_module);
 
72
  }
 
73
                 
 
74
  /* Now work on filling in swig_module.types */
 
75
  for (i = 0; i < swig_module.size; ++i) {
 
76
    type = 0;
 
77
 
 
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);
 
81
    }
 
82
    if (type) {
 
83
      /* Overwrite clientdata field */
 
84
      if (swig_module.type_initial[i]->clientdata) type->clientdata = swig_module.type_initial[i]->clientdata;
 
85
    } else {
 
86
      type = swig_module.type_initial[i];
 
87
    }
 
88
 
 
89
    /* Insert casting types */
 
90
    cast = swig_module.cast_initial[i];
 
91
    while (cast->type) {
 
92
    
 
93
      /* Don't need to add information already in the list */
 
94
      ret = 0;
 
95
      if (swig_module.next != &swig_module) {
 
96
        ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
 
97
      }
 
98
      if (ret && type == swig_module.type_initial[i]) {
 
99
        cast->type = ret;
 
100
        ret = 0;
 
101
      }
 
102
      
 
103
      if (!ret) {
 
104
        if (type->cast) {
 
105
          type->cast->prev = cast;
 
106
          cast->next = type->cast;
 
107
        }
 
108
        type->cast = cast;
 
109
      }
 
110
 
 
111
      cast++;
 
112
    }
 
113
 
 
114
    /* Set entry in modules->types array equal to the type */
 
115
    swig_module.types[i] = type;
 
116
  }
 
117
  swig_module.types[i] = 0;
 
118
}
 
119
 
 
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.
 
124
*/
 
125
SWIGRUNTIME void
 
126
SWIG_PropagateClientData(void) {
 
127
  size_t i;
 
128
  swig_cast_info *equiv;
 
129
  static int init_run = 0;
 
130
 
 
131
  if (init_run) return;
 
132
  init_run = 1;
 
133
 
 
134
  for (i = 0; i < swig_module.size; i++) {
 
135
    if (swig_module.types[i]->clientdata) {
 
136
      equiv = swig_module.types[i]->cast;
 
137
      while (equiv) {
 
138
        if (!equiv->converter) {
 
139
          if (equiv->type && !equiv->type->clientdata)
 
140
            SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
 
141
        }
 
142
        equiv = equiv->next;
 
143
      }
 
144
    }
 
145
  }
 
146
}
 
147
 
 
148
#ifdef __cplusplus
 
149
}
 
150
#endif