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.

511 lines
15 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * mzrun.swg
  6. * ----------------------------------------------------------------------------- */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <limits.h>
  11. #include <escheme.h>
  12. #include <assert.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /* Common SWIG API */
  17. #define SWIG_ConvertPtr(s, result, type, flags) \
  18. SWIG_MzScheme_ConvertPtr(s, result, type, flags)
  19. #define SWIG_NewPointerObj(ptr, type, owner) \
  20. SWIG_MzScheme_NewPointerObj((void *)ptr, type, owner)
  21. #define SWIG_MustGetPtr(s, type, argnum, flags) \
  22. SWIG_MzScheme_MustGetPtr(s, type, argnum, flags, FUNC_NAME, argc, argv)
  23. #define SWIG_contract_assert(expr,msg) \
  24. if (!(expr)) { \
  25. char *m=(char *) scheme_malloc(strlen(msg)+1000); \
  26. sprintf(m,"SWIG contract, assertion failed: function=%s, message=%s", \
  27. (char *) FUNC_NAME,(char *) msg); \
  28. scheme_signal_error(m); \
  29. }
  30. /* Runtime API */
  31. #define SWIG_GetModule(clientdata) SWIG_MzScheme_GetModule((Scheme_Env *)(clientdata))
  32. #define SWIG_SetModule(clientdata, pointer) SWIG_MzScheme_SetModule((Scheme_Env *) (clientdata), pointer)
  33. #define SWIG_MODULE_CLIENTDATA_TYPE Scheme_Env *
  34. /* MzScheme-specific SWIG API */
  35. #define SWIG_malloc(size) SWIG_MzScheme_Malloc(size, FUNC_NAME)
  36. #define SWIG_free(mem) free(mem)
  37. #define SWIG_NewStructFromPtr(ptr,type) \
  38. _swig_convert_struct_##type##(ptr)
  39. #define MAXVALUES 6
  40. #define swig_make_boolean(b) (b ? scheme_true : scheme_false)
  41. static long
  42. SWIG_convert_integer(Scheme_Object *o,
  43. long lower_bound, long upper_bound,
  44. const char *func_name, int argnum, int argc,
  45. Scheme_Object **argv)
  46. {
  47. long value;
  48. int status = scheme_get_int_val(o, &value);
  49. if (!status)
  50. scheme_wrong_type(func_name, "integer", argnum, argc, argv);
  51. if (value < lower_bound || value > upper_bound)
  52. scheme_wrong_type(func_name, "integer", argnum, argc, argv);
  53. return value;
  54. }
  55. static int
  56. SWIG_is_integer(Scheme_Object *o)
  57. {
  58. long value;
  59. return scheme_get_int_val(o, &value);
  60. }
  61. static unsigned long
  62. SWIG_convert_unsigned_integer(Scheme_Object *o,
  63. unsigned long lower_bound, unsigned long upper_bound,
  64. const char *func_name, int argnum, int argc,
  65. Scheme_Object **argv)
  66. {
  67. unsigned long value;
  68. int status = scheme_get_unsigned_int_val(o, &value);
  69. if (!status)
  70. scheme_wrong_type(func_name, "integer", argnum, argc, argv);
  71. if (value < lower_bound || value > upper_bound)
  72. scheme_wrong_type(func_name, "integer", argnum, argc, argv);
  73. return value;
  74. }
  75. static int
  76. SWIG_is_unsigned_integer(Scheme_Object *o)
  77. {
  78. unsigned long value;
  79. return scheme_get_unsigned_int_val(o, &value);
  80. }
  81. /* -----------------------------------------------------------------------
  82. * mzscheme 30X support code
  83. * Contributed by Hans Oesterholt
  84. * ----------------------------------------------------------------------- */
  85. #ifndef SCHEME_STR_VAL
  86. #define MZSCHEME30X 1
  87. #endif
  88. #ifdef MZSCHEME30X
  89. /*
  90. * This is MZSCHEME 299.100 or higher (30x). From version 299.100 of
  91. * mzscheme upwards, strings are in unicode. These functions convert
  92. * to and from utf8 encodings of these strings. NB! strlen(s) will be
  93. * the size in bytes of the string, not the actual length.
  94. */
  95. #define SCHEME_STR_VAL(obj) SCHEME_BYTE_STR_VAL(scheme_char_string_to_byte_string(obj))
  96. #define SCHEME_STRLEN_VAL(obj) SCHEME_BYTE_STRLEN_VAL(scheme_char_string_to_byte_string(obj))
  97. #define SCHEME_STRINGP(obj) SCHEME_CHAR_STRINGP(obj)
  98. #define scheme_make_string(s) scheme_make_utf8_string(s)
  99. #define scheme_make_sized_string(s,l) scheme_make_sized_utf8_string(s,l)
  100. #define scheme_make_sized_offset_string(s,d,l) \
  101. scheme_make_sized_offset_utf8_string(s,d,l)
  102. #define SCHEME_MAKE_STRING(s) scheme_make_utf8_string(s)
  103. #else
  104. #define SCHEME_MAKE_STRING(s) scheme_make_string_without_copying(s)
  105. #endif
  106. /* -----------------------------------------------------------------------
  107. * End of mzscheme 30X support code
  108. * ----------------------------------------------------------------------- */
  109. struct swig_mz_proxy {
  110. Scheme_Type mztype;
  111. swig_type_info *type;
  112. void *object;
  113. };
  114. static Scheme_Type swig_type;
  115. static void
  116. mz_free_swig(void *p, void *data) {
  117. struct swig_mz_proxy *proxy = (struct swig_mz_proxy *) p;
  118. if (SCHEME_NULLP((Scheme_Object*)p) || SCHEME_TYPE((Scheme_Object*)p) != swig_type)
  119. return;
  120. if (proxy->type) {
  121. if (proxy->type->clientdata) {
  122. ((Scheme_Prim *)proxy->type->clientdata)(1, (Scheme_Object **)&proxy);
  123. }
  124. }
  125. }
  126. static Scheme_Object *
  127. SWIG_MzScheme_NewPointerObj(void *ptr, swig_type_info *type, int owner) {
  128. struct swig_mz_proxy *new_proxy;
  129. new_proxy = (struct swig_mz_proxy *) scheme_malloc(sizeof(struct swig_mz_proxy));
  130. new_proxy->mztype = swig_type;
  131. new_proxy->type = type;
  132. new_proxy->object = ptr;
  133. if (owner) {
  134. scheme_add_finalizer(new_proxy, mz_free_swig, NULL);
  135. }
  136. return (Scheme_Object *) new_proxy;
  137. }
  138. static int
  139. SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, int flags) {
  140. swig_cast_info *cast;
  141. if (SCHEME_NULLP(s)) {
  142. *result = NULL;
  143. return 0;
  144. } else if (SCHEME_TYPE(s) == swig_type) {
  145. struct swig_mz_proxy *proxy = (struct swig_mz_proxy *) s;
  146. if (type) {
  147. cast = SWIG_TypeCheckStruct(proxy->type, type);
  148. if (cast) {
  149. int newmemory = 0;
  150. *result = SWIG_TypeCast(cast, proxy->object, &newmemory);
  151. assert(!newmemory); /* newmemory handling not yet implemented */
  152. return 0;
  153. } else {
  154. return 1;
  155. }
  156. } else {
  157. *result = proxy->object;
  158. return 0;
  159. }
  160. }
  161. return 1;
  162. }
  163. static SWIGINLINE void *
  164. SWIG_MzScheme_MustGetPtr(Scheme_Object *s, swig_type_info *type,
  165. int argnum, int flags, const char *func_name,
  166. int argc, Scheme_Object **argv) {
  167. void *result;
  168. if (SWIG_MzScheme_ConvertPtr(s, &result, type, flags)) {
  169. scheme_wrong_type(func_name, type->str ? type->str : "void *", argnum - 1, argc, argv);
  170. }
  171. return result;
  172. }
  173. static SWIGINLINE void *
  174. SWIG_MzScheme_Malloc(size_t size, const char *func_name) {
  175. void *p = malloc(size);
  176. if (p == NULL) {
  177. scheme_signal_error("swig-memory-error");
  178. } else return p;
  179. }
  180. static Scheme_Object *
  181. SWIG_MzScheme_PackageValues(int num, Scheme_Object **values) {
  182. /* ignore first value if void */
  183. if (num > 0 && SCHEME_VOIDP(values[0]))
  184. num--, values++;
  185. if (num == 0) return scheme_void;
  186. else if (num == 1) return values[0];
  187. else return scheme_values(num, values);
  188. }
  189. #ifndef scheme_make_inspector
  190. #define scheme_make_inspector(x,y) \
  191. _scheme_apply(scheme_builtin_value("make-inspector"), x, y)
  192. #endif
  193. /* Function to create a new struct. */
  194. static Scheme_Object *
  195. SWIG_MzScheme_new_scheme_struct (Scheme_Env* env, const char* basename,
  196. int num_fields, char** field_names)
  197. {
  198. Scheme_Object *new_type;
  199. int count_out, i;
  200. Scheme_Object **struct_names;
  201. Scheme_Object **vals;
  202. Scheme_Object **a = (Scheme_Object**) \
  203. scheme_malloc(num_fields*sizeof(Scheme_Object*));
  204. for (i=0; i<num_fields; ++i) {
  205. a[i] = (Scheme_Object*) scheme_intern_symbol(field_names[i]);
  206. }
  207. new_type = scheme_make_struct_type(scheme_intern_symbol(basename),
  208. NULL /*super_type*/,
  209. scheme_make_inspector(0, NULL),
  210. num_fields,
  211. 0 /* auto_fields */,
  212. NULL /* auto_val */,
  213. NULL /* properties */
  214. #ifdef MZSCHEME30X
  215. ,NULL /* Guard */
  216. #endif
  217. );
  218. struct_names = scheme_make_struct_names(scheme_intern_symbol(basename),
  219. scheme_build_list(num_fields,a),
  220. 0 /*flags*/, &count_out);
  221. vals = scheme_make_struct_values(new_type, struct_names, count_out, 0);
  222. for (i = 0; i < count_out; i++)
  223. scheme_add_global_symbol(struct_names[i], vals[i],env);
  224. return new_type;
  225. }
  226. /*** DLOPEN PATCH ******************************************************
  227. * Contributed by Hans Oesterholt-Dijkema (jan. 2006)
  228. ***********************************************************************/
  229. #if defined(_WIN32) || defined(__WIN32__)
  230. #define __OS_WIN32
  231. #endif
  232. #ifdef __OS_WIN32
  233. #include <windows.h>
  234. #else
  235. #include <dlfcn.h>
  236. #endif
  237. static char **mz_dlopen_libraries=NULL;
  238. static void **mz_libraries=NULL;
  239. static char **mz_dynload_libpaths=NULL;
  240. static void mz_set_dlopen_libraries(const char *_libs)
  241. {
  242. int i,k,n;
  243. int mz_dynload_debug=(1==0);
  244. char *extra_paths[1000];
  245. char *EP;
  246. {
  247. char *dbg=getenv("MZ_DYNLOAD_DEBUG");
  248. if (dbg!=NULL) {
  249. mz_dynload_debug=atoi(dbg);
  250. }
  251. }
  252. {
  253. char *ep=getenv("MZ_DYNLOAD_LIBPATH");
  254. int i,k,j;
  255. k=0;
  256. if (ep!=NULL) {
  257. EP=strdup(ep);
  258. for(i=0,j=0;EP[i]!='\0';i++) {
  259. if (EP[i]==':') {
  260. EP[i]='\0';
  261. extra_paths[k++]=&EP[j];
  262. j=i+1;
  263. }
  264. }
  265. if (j!=i) {
  266. extra_paths[k++]=&EP[j];
  267. }
  268. }
  269. else {
  270. EP=strdup("");
  271. }
  272. extra_paths[k]=NULL;
  273. k+=1;
  274. if (mz_dynload_debug) {
  275. fprintf(stderr,"SWIG:mzscheme:MZ_DYNLOAD_LIBPATH=%s\n",(ep==NULL) ? "(null)" : ep);
  276. fprintf(stderr,"SWIG:mzscheme:extra_paths[%d]\n",k-1);
  277. for(i=0;i<k-1;i++) {
  278. fprintf(stderr,"SWIG:mzscheme:extra_paths[%d]=%s\n",i,extra_paths[i]);
  279. }
  280. }
  281. mz_dynload_libpaths=(char **) malloc(sizeof(char *)*k);
  282. for(i=0;i<k;i++) {
  283. if (extra_paths[i]!=NULL) {
  284. mz_dynload_libpaths[i]=strdup(extra_paths[i]);
  285. }
  286. else {
  287. mz_dynload_libpaths[i]=NULL;
  288. }
  289. }
  290. if (mz_dynload_debug) {
  291. int i;
  292. for(i=0;extra_paths[i]!=NULL;i++) {
  293. fprintf(stderr,"SWIG:mzscheme:%s\n",extra_paths[i]);
  294. }
  295. }
  296. }
  297. {
  298. #ifdef MZ_DYNLOAD_LIBS
  299. char *libs=(char *) malloc((strlen(MZ_DYNLOAD_LIBS)+1)*sizeof(char));
  300. strcpy(libs,MZ_DYNLOAD_LIBS);
  301. #else
  302. char *libs=(char *) malloc((strlen(_libs)+1)*sizeof(char));
  303. strcpy(libs,_libs);
  304. #endif
  305. for(i=0,n=strlen(libs),k=0;i<n;i++) {
  306. if (libs[i]==',') { k+=1; }
  307. }
  308. k+=1;
  309. mz_dlopen_libraries=(char **) malloc(sizeof(char *)*(k+1));
  310. mz_dlopen_libraries[0]=libs;
  311. for(i=0,k=1,n=strlen(libs);i<n;i++) {
  312. if (libs[i]==',') {
  313. libs[i]='\0';
  314. mz_dlopen_libraries[k++]=&libs[i+1];
  315. i+=1;
  316. }
  317. }
  318. if (mz_dynload_debug) {
  319. fprintf(stderr,"k=%d\n",k);
  320. }
  321. mz_dlopen_libraries[k]=NULL;
  322. free(EP);
  323. }
  324. }
  325. static void *mz_load_function(char *function)
  326. {
  327. int mz_dynload_debug=(1==0);
  328. {
  329. char *dbg=getenv("MZ_DYNLOAD_DEBUG");
  330. if (dbg!=NULL) {
  331. mz_dynload_debug=atoi(dbg);
  332. }
  333. }
  334. if (mz_dlopen_libraries==NULL) {
  335. return NULL;
  336. }
  337. else {
  338. if (mz_libraries==NULL) {
  339. int i,n;
  340. for(n=0;mz_dlopen_libraries[n]!=NULL;n++);
  341. if (mz_dynload_debug) {
  342. fprintf(stderr,"SWIG:mzscheme:n=%d\n",n);
  343. }
  344. mz_libraries=(void **) malloc(sizeof(void*)*n);
  345. for(i=0;i<n;i++) {
  346. if (mz_dynload_debug) {
  347. fprintf(stderr,"SWIG:mzscheme:loading %s\n",mz_dlopen_libraries[i]);
  348. }
  349. #ifdef __OS_WIN32
  350. mz_libraries[i]=(void *) LoadLibrary(mz_dlopen_libraries[i]);
  351. #else
  352. mz_libraries[i]=(void *) dlopen(mz_dlopen_libraries[i],RTLD_LAZY);
  353. #endif
  354. if (mz_libraries[i]==NULL) {
  355. int k;
  356. char *libp;
  357. for(k=0;mz_dynload_libpaths[k]!=NULL && mz_libraries[i]==NULL;k++) {
  358. int L=strlen(mz_dynload_libpaths[k])+strlen("\\")+strlen(mz_dlopen_libraries[i])+1;
  359. libp=(char *) malloc(L*sizeof(char));
  360. #ifdef __OS_WIN32
  361. sprintf(libp,"%s\\%s",mz_dynload_libpaths[k],mz_dlopen_libraries[i]);
  362. mz_libraries[i]=(void *) LoadLibrary(libp);
  363. #else
  364. sprintf(libp,"%s/%s",mz_dynload_libpaths[k],mz_dlopen_libraries[i]);
  365. mz_libraries[i]=(void *) dlopen(libp,RTLD_LAZY);
  366. #endif
  367. if (mz_dynload_debug) {
  368. fprintf(stderr,"SWIG:mzscheme:trying %s --> %p\n",libp,mz_libraries[i]);
  369. }
  370. free(libp);
  371. }
  372. }
  373. }
  374. }
  375. {
  376. int i;
  377. void *func=NULL;
  378. for(i=0;mz_dlopen_libraries[i]!=NULL && func==NULL;i++) {
  379. if (mz_libraries[i]!=NULL) {
  380. #ifdef __OS_WIN32
  381. func=GetProcAddress(mz_libraries[i],function);
  382. #else
  383. func=dlsym(mz_libraries[i],function);
  384. #endif
  385. }
  386. if (mz_dynload_debug) {
  387. fprintf(stderr,
  388. "SWIG:mzscheme:library:%s;dlopen=%p,function=%s,func=%p\n",
  389. mz_dlopen_libraries[i],mz_libraries[i],function,func
  390. );
  391. }
  392. }
  393. return func;
  394. }
  395. }
  396. }
  397. /*** DLOPEN PATCH ******************************************************
  398. * Contributed by Hans Oesterholt-Dijkema (jan. 2006)
  399. ***********************************************************************/
  400. /* The interpreter will store a pointer to this structure in a global
  401. variable called swig-runtime-data-type-pointer. The instance of this
  402. struct is only used if no other module has yet been loaded */
  403. struct swig_mzscheme_runtime_data {
  404. swig_module_info *module_head;
  405. Scheme_Type type;
  406. };
  407. static struct swig_mzscheme_runtime_data swig_mzscheme_runtime_data;
  408. static swig_module_info *
  409. SWIG_MzScheme_GetModule(Scheme_Env *env) {
  410. Scheme_Object *pointer, *symbol;
  411. struct swig_mzscheme_runtime_data *data;
  412. /* first check if pointer already created */
  413. symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
  414. pointer = scheme_lookup_global(symbol, env);
  415. if (pointer && SCHEME_CPTRP(pointer)) {
  416. data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer);
  417. swig_type = data->type;
  418. return data->module_head;
  419. } else {
  420. return NULL;
  421. }
  422. }
  423. static void
  424. SWIG_MzScheme_SetModule(Scheme_Env *env, swig_module_info *module) {
  425. Scheme_Object *pointer, *symbol;
  426. struct swig_mzscheme_runtime_data *data;
  427. /* first check if pointer already created */
  428. symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
  429. pointer = scheme_lookup_global(symbol, env);
  430. if (pointer && SCHEME_CPTRP(pointer)) {
  431. data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer);
  432. swig_type = data->type;
  433. data->module_head = module;
  434. } else {
  435. /* create a new type for wrapped pointer values */
  436. swig_type = scheme_make_type((char *)"swig");
  437. swig_mzscheme_runtime_data.module_head = module;
  438. swig_mzscheme_runtime_data.type = swig_type;
  439. /* create a new pointer */
  440. #ifndef MZSCHEME30X
  441. pointer = scheme_make_cptr((void *) &swig_mzscheme_runtime_data, "swig_mzscheme_runtime_data");
  442. #else
  443. pointer = scheme_make_cptr((void *) &swig_mzscheme_runtime_data,
  444. scheme_make_byte_string("swig_mzscheme_runtime_data"));
  445. #endif
  446. scheme_add_global_symbol(symbol, pointer, env);
  447. }
  448. }
  449. #ifdef __cplusplus
  450. }
  451. #endif