Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.9 KiB

  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 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.
  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. #ifdef __cplusplus
  42. extern "C" {
  43. #if 0
  44. } /* c-mode */
  45. #endif
  46. #endif
  47. #if 0
  48. #define SWIGRUNTIME_DEBUG
  49. #endif
  50. SWIGRUNTIME void
  51. SWIG_InitializeModule(void *clientdata) {
  52. size_t i;
  53. swig_module_info *module_head, *iter;
  54. int found, init;
  55. clientdata = clientdata;
  56. /* check to see if the circular list has been setup, if not, set it up */
  57. if (swig_module.next==0) {
  58. /* Initialize the swig_module */
  59. swig_module.type_initial = swig_type_initial;
  60. swig_module.cast_initial = swig_cast_initial;
  61. swig_module.next = &swig_module;
  62. init = 1;
  63. } else {
  64. init = 0;
  65. }
  66. /* Try and load any already created modules */
  67. module_head = SWIG_GetModule(clientdata);
  68. if (!module_head) {
  69. /* This is the first module loaded for this interpreter */
  70. /* so set the swig module into the interpreter */
  71. SWIG_SetModule(clientdata, &swig_module);
  72. module_head = &swig_module;
  73. } else {
  74. /* the interpreter has loaded a SWIG module, but has it loaded this one? */
  75. found=0;
  76. iter=module_head;
  77. do {
  78. if (iter==&swig_module) {
  79. found=1;
  80. break;
  81. }
  82. iter=iter->next;
  83. } while (iter!= module_head);
  84. /* if the is found in the list, then all is done and we may leave */
  85. if (found) return;
  86. /* otherwise we must add out module into the list */
  87. swig_module.next = module_head->next;
  88. module_head->next = &swig_module;
  89. }
  90. /* When multiple interpeters are used, a module could have already been initialized in
  91. a different interpreter, but not yet have a pointer in this interpreter.
  92. In this case, we do not want to continue adding types... everything should be
  93. set up already */
  94. if (init == 0) return;
  95. /* Now work on filling in swig_module.types */
  96. #ifdef SWIGRUNTIME_DEBUG
  97. printf("SWIG_InitializeModule: size %d\n", swig_module.size);
  98. #endif
  99. for (i = 0; i < swig_module.size; ++i) {
  100. swig_type_info *type = 0;
  101. swig_type_info *ret;
  102. swig_cast_info *cast;
  103. #ifdef SWIGRUNTIME_DEBUG
  104. printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
  105. #endif
  106. /* if there is another module already loaded */
  107. if (swig_module.next != &swig_module) {
  108. type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name);
  109. }
  110. if (type) {
  111. /* Overwrite clientdata field */
  112. #ifdef SWIGRUNTIME_DEBUG
  113. printf("SWIG_InitializeModule: found type %s\n", type->name);
  114. #endif
  115. if (swig_module.type_initial[i]->clientdata) {
  116. type->clientdata = swig_module.type_initial[i]->clientdata;
  117. #ifdef SWIGRUNTIME_DEBUG
  118. printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name);
  119. #endif
  120. }
  121. } else {
  122. type = swig_module.type_initial[i];
  123. }
  124. /* Insert casting types */
  125. cast = swig_module.cast_initial[i];
  126. while (cast->type) {
  127. /* Don't need to add information already in the list */
  128. ret = 0;
  129. #ifdef SWIGRUNTIME_DEBUG
  130. printf("SWIG_InitializeModule: look cast %s\n", cast->type->name);
  131. #endif
  132. if (swig_module.next != &swig_module) {
  133. ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name);
  134. #ifdef SWIGRUNTIME_DEBUG
  135. if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name);
  136. #endif
  137. }
  138. if (ret) {
  139. if (type == swig_module.type_initial[i]) {
  140. #ifdef SWIGRUNTIME_DEBUG
  141. printf("SWIG_InitializeModule: skip old type %s\n", ret->name);
  142. #endif
  143. cast->type = ret;
  144. ret = 0;
  145. } else {
  146. /* Check for casting already in the list */
  147. swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type);
  148. #ifdef SWIGRUNTIME_DEBUG
  149. if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name);
  150. #endif
  151. if (!ocast) ret = 0;
  152. }
  153. }
  154. if (!ret) {
  155. #ifdef SWIGRUNTIME_DEBUG
  156. printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name);
  157. #endif
  158. if (type->cast) {
  159. type->cast->prev = cast;
  160. cast->next = type->cast;
  161. }
  162. type->cast = cast;
  163. }
  164. cast++;
  165. }
  166. /* Set entry in modules->types array equal to the type */
  167. swig_module.types[i] = type;
  168. }
  169. swig_module.types[i] = 0;
  170. #ifdef SWIGRUNTIME_DEBUG
  171. printf("**** SWIG_InitializeModule: Cast List ******\n");
  172. for (i = 0; i < swig_module.size; ++i) {
  173. int j = 0;
  174. swig_cast_info *cast = swig_module.cast_initial[i];
  175. printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name);
  176. while (cast->type) {
  177. printf("SWIG_InitializeModule: cast type %s\n", cast->type->name);
  178. cast++;
  179. ++j;
  180. }
  181. printf("---- Total casts: %d\n",j);
  182. }
  183. printf("**** SWIG_InitializeModule: Cast List ******\n");
  184. #endif
  185. }
  186. /* This function will propagate the clientdata field of type to
  187. * any new swig_type_info structures that have been added into the list
  188. * of equivalent types. It is like calling
  189. * SWIG_TypeClientData(type, clientdata) a second time.
  190. */
  191. SWIGRUNTIME void
  192. SWIG_PropagateClientData(void) {
  193. size_t i;
  194. swig_cast_info *equiv;
  195. static int init_run = 0;
  196. if (init_run) return;
  197. init_run = 1;
  198. for (i = 0; i < swig_module.size; i++) {
  199. if (swig_module.types[i]->clientdata) {
  200. equiv = swig_module.types[i]->cast;
  201. while (equiv) {
  202. if (!equiv->converter) {
  203. if (equiv->type && !equiv->type->clientdata)
  204. SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata);
  205. }
  206. equiv = equiv->next;
  207. }
  208. }
  209. }
  210. }
  211. #ifdef __cplusplus
  212. #if 0
  213. { /* c-mode */
  214. #endif
  215. }
  216. #endif