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.

773 lines
22 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. * chicken.swg
  6. *
  7. * CHICKEN configuration module.
  8. * ----------------------------------------------------------------------------- */
  9. /* chicken.h has to appear first. */
  10. %insert(runtime) %{
  11. #include <chicken.h>
  12. %}
  13. %insert(runtime) "swigrun.swg"; // Common C API type-checking code
  14. %insert(runtime) "chickenrun.swg"; // CHICKEN run-time code
  15. /* -----------------------------------------------------------------------------
  16. * standard typemaps
  17. * ----------------------------------------------------------------------------- */
  18. /*
  19. CHICKEN: C
  20. ----------
  21. fixnum: int, short, unsigned int, unsigned short, unsigned char,
  22. signed char
  23. char: char
  24. bool: bool
  25. flonum: float, double, long, long long, unsigned long, unsigned long
  26. long
  27. */
  28. /* --- Primitive types --- */
  29. %define SIMPLE_TYPEMAP(type_, from_scheme, to_scheme, checker, convtype, storage_)
  30. %typemap(in) type_
  31. %{ if (!checker ($input)) {
  32. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
  33. }
  34. $1 = ($1_ltype) from_scheme ($input); %}
  35. /* Const primitive references. Passed by value */
  36. %typemap(in) const type_ & ($*1_ltype temp)
  37. %{ if (!checker ($input)) {
  38. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'type_'");
  39. }
  40. temp = ($*1_ltype) from_scheme ($input);
  41. $1 = &temp; %}
  42. /* --- Variable input --- */
  43. %typemap(varin) type_
  44. %{ if (!checker ($input)) {
  45. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use '$1_ltype' for variable '$name' of type 'type_'");
  46. }
  47. $1 = ($1_ltype) from_scheme ($input); %}
  48. #if "storage_" == "0"
  49. %typemap(out) type_
  50. %{
  51. $result = to_scheme (convtype ($1));
  52. %}
  53. /* References to primitive types. Return by value */
  54. %typemap(out) const type_ &
  55. %{
  56. $result = to_scheme (convtype (*$1));
  57. %}
  58. /* --- Variable output --- */
  59. %typemap(varout) type_
  60. %{
  61. $result = to_scheme (convtype ($varname));
  62. %}
  63. %typemap(throws) type_
  64. %{
  65. SWIG_Chicken_ThrowException(to_scheme ( convtype ($1)));
  66. %}
  67. #else
  68. %typemap(out) type_
  69. %{
  70. {
  71. C_word *space = C_alloc(storage_);
  72. $result = to_scheme (&space, convtype ($1));
  73. }
  74. %}
  75. /* References to primitive types. Return by value */
  76. %typemap(out) const type_ &
  77. %{
  78. {
  79. C_word *space = C_alloc(storage_);
  80. $result = to_scheme (&space, convtype (*$1));
  81. }
  82. %}
  83. /* --- Variable output --- */
  84. %typemap(varout) type_
  85. %{
  86. {
  87. C_word *space = C_alloc(storage_);
  88. $result = to_scheme (&space, convtype ($varname));
  89. }
  90. %}
  91. %typemap(throws) type_
  92. %{
  93. {
  94. C_word *space = C_alloc(storage_);
  95. SWIG_Chicken_ThrowException(to_scheme (&space, convtype ($1)));
  96. }
  97. %}
  98. #endif
  99. /* --- Constants --- */
  100. %typemap(constcode) type_
  101. "static const $1_type $result = $value;"
  102. %enddef
  103. SIMPLE_TYPEMAP(int, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
  104. //SIMPLE_TYPEMAP(enum SWIGTYPE, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
  105. SIMPLE_TYPEMAP(short, C_num_to_int, C_fix, C_swig_is_number, (int), 0);
  106. SIMPLE_TYPEMAP(long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
  107. SIMPLE_TYPEMAP(long long, C_num_to_long, C_long_to_num, C_swig_is_long, (long), C_SIZEOF_FLONUM);
  108. SIMPLE_TYPEMAP(unsigned int, C_num_to_unsigned_int, C_unsigned_int_to_num, C_swig_is_number, (unsigned int), C_SIZEOF_FLONUM);
  109. SIMPLE_TYPEMAP(unsigned short, C_num_to_unsigned_int, C_fix, C_swig_is_number, (unsigned int), 0);
  110. SIMPLE_TYPEMAP(unsigned long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
  111. SIMPLE_TYPEMAP(unsigned long long, C_num_to_unsigned_long, C_unsigned_long_to_num, C_swig_is_long, (unsigned long), C_SIZEOF_FLONUM);
  112. SIMPLE_TYPEMAP(unsigned char, C_character_code, C_make_character, C_swig_is_char, (unsigned int), 0);
  113. SIMPLE_TYPEMAP(signed char, C_character_code, C_make_character, C_swig_is_char, (int), 0);
  114. SIMPLE_TYPEMAP(char, C_character_code, C_make_character, C_swig_is_char, (char), 0);
  115. SIMPLE_TYPEMAP(bool, C_truep, C_mk_bool, C_swig_is_bool, (bool), 0);
  116. SIMPLE_TYPEMAP(float, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
  117. SIMPLE_TYPEMAP(double, C_c_double, C_flonum, C_swig_is_number, (double), C_SIZEOF_FLONUM);
  118. /* enum SWIGTYPE */
  119. %apply int { enum SWIGTYPE };
  120. %apply const int& { const enum SWIGTYPE& };
  121. %typemap(varin) enum SWIGTYPE
  122. {
  123. if (!C_swig_is_fixnum($input) && sizeof(int) != sizeof($1)) {
  124. swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "enum variable '$name' can not be set");
  125. }
  126. *((int *)(void *)&$1) = C_unfix($input);
  127. }
  128. /* --- Input arguments --- */
  129. /* Strings */
  130. %typemap(in) char *
  131. { if ($input == C_SCHEME_FALSE) {
  132. $1 = NULL;
  133. }
  134. else {
  135. if (!C_swig_is_string ($input)) {
  136. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'char *'");
  137. }
  138. $1 = ($ltype) SWIG_MakeString ($input);
  139. }
  140. }
  141. %typemap(freearg) char * "if ($1 != NULL) { free ($1); }"
  142. /* Pointers, references, and arrays */
  143. %typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *, SWIGTYPE [], SWIGTYPE & {
  144. $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, $disown);
  145. }
  146. %typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE *DISOWN {
  147. $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_DISOWN);
  148. }
  149. /* Void pointer. Accepts any kind of pointer */
  150. %typemap(in) void * {
  151. $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0);
  152. }
  153. %typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE * {
  154. $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, SWIG_POINTER_DISOWN);
  155. }
  156. %typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE & {
  157. $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0));
  158. }
  159. %typemap(varin) SWIGTYPE [] {
  160. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "Type error");
  161. }
  162. %typemap(varin) SWIGTYPE [ANY] {
  163. void *temp;
  164. int ii;
  165. $1_basetype *b = 0;
  166. temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0);
  167. b = ($1_basetype *) $1;
  168. for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii);
  169. }
  170. %typemap(varin) void * {
  171. $1 = SWIG_MustGetPtr($input, NULL, 1, 0);
  172. }
  173. %typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
  174. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  175. $result = SWIG_NewPointerObj($1, $descriptor, $owner);
  176. }
  177. %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
  178. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  179. swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
  180. $result = SWIG_NewPointerObj($1, ty, $owner);
  181. }
  182. %typemap(varout) SWIGTYPE *, SWIGTYPE [] {
  183. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  184. $result = SWIG_NewPointerObj($varname, $descriptor, 0);
  185. }
  186. %typemap(varout) SWIGTYPE & {
  187. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  188. $result = SWIG_NewPointerObj((void *) &$varname, $1_descriptor, 0);
  189. }
  190. /* special typemaps for class pointers */
  191. %typemap(in) SWIGTYPE (CLASS::*) {
  192. char err_msg[256];
  193. if (C_swig_is_pair($input)) {
  194. /* try and convert pointer object */
  195. void *result;
  196. if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
  197. C_word ptr = C_block_item($input,0);
  198. if (C_swig_is_string(ptr)) {
  199. SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type));
  200. } else {
  201. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
  202. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  203. }
  204. } else {
  205. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
  206. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  207. }
  208. } else {
  209. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", $argnum, ($descriptor->str ? $descriptor->str : $descriptor->name));
  210. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  211. }
  212. }
  213. %typemap(out) SWIGTYPE (CLASS::*) {
  214. size_t ptr_size = sizeof($type);
  215. C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER);
  216. char *temp = (char *)malloc(2*ptr_size);
  217. C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0);
  218. SWIG_PackData(temp, (void *) &$1, ptr_size);
  219. $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr);
  220. free(temp);
  221. }
  222. %typemap(varin) SWIGTYPE (CLASS::*) {
  223. char err_msg[256];
  224. if (C_swig_is_pair($input)) {
  225. /* try and convert pointer object */
  226. void *result;
  227. if (!SWIG_ConvertPtr(C_block_item($input,1), &result, $descriptor, 0)) {
  228. C_word ptr = C_block_item($input,0);
  229. if (C_swig_is_string(ptr)) {
  230. SWIG_UnpackData(C_c_string(ptr), (void *) &$1, sizeof($type));
  231. } else {
  232. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
  233. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  234. }
  235. } else {
  236. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
  237. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  238. }
  239. } else {
  240. snprintf(err_msg, sizeof(err_msg), "Type error in argument #%i: expected %s", 1, ($descriptor->str ? $descriptor->str : $descriptor->name));
  241. SWIG_Chicken_Barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, err_msg);
  242. }
  243. }
  244. %typemap(varout) SWIGTYPE (CLASS::*) {
  245. size_t ptr_size = sizeof($type);
  246. C_word *known_space = C_alloc(C_SIZEOF_PAIR + C_SIZEOF_STRING(2*ptr_size) + C_SIZEOF_SWIG_POINTER);
  247. char *temp = (char *)malloc(2*ptr_size);
  248. C_word ptr = SWIG_NewPointerObj((void *) known_space, $descriptor, 0);
  249. SWIG_PackData(temp, (void *) &$varname, ptr_size);
  250. $result = C_pair(&known_space, C_string(&known_space, 2*ptr_size, temp), ptr);
  251. free(temp);
  252. }
  253. /* Pass-by-value */
  254. %typemap(in,closcode="(slot-ref $input 'swig-this)") SWIGTYPE($&1_ltype argp) {
  255. argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
  256. $1 = *argp;
  257. }
  258. %typemap(varin,closcode="(slot-ref $input 'swig-this)") SWIGTYPE {
  259. $&1_ltype argp;
  260. argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, 1, 0);
  261. $1 = *argp;
  262. }
  263. %typemap(out) SWIGTYPE
  264. #ifdef __cplusplus
  265. {
  266. $&1_ltype resultptr;
  267. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  268. resultptr = new $1_ltype(($1_ltype &) $1);
  269. $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
  270. }
  271. #else
  272. {
  273. $&1_ltype resultptr;
  274. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  275. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  276. memmove(resultptr, &$1, sizeof($1_type));
  277. $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1);
  278. }
  279. #endif
  280. %typemap(varout) SWIGTYPE
  281. #ifdef __cplusplus
  282. {
  283. $&1_ltype resultptr;
  284. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  285. resultptr = new $1_ltype(($1_ltype&) $1);
  286. $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
  287. }
  288. #else
  289. {
  290. $&1_ltype resultptr;
  291. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  292. resultptr = ($&1_ltype) malloc(sizeof($1_type));
  293. memmove(resultptr, &$1, sizeof($1_type));
  294. $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0);
  295. }
  296. #endif
  297. /* --- Output values --- */
  298. /* Strings */
  299. %typemap(out)
  300. char *
  301. { char *s = (char*) $1;
  302. if ($1 == NULL) {
  303. $result = C_SCHEME_FALSE;
  304. }
  305. else {
  306. int string_len = strlen ((char *) ($1));
  307. C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
  308. $result = C_string (&string_space, string_len, s);
  309. }
  310. }
  311. %typemap(varout)
  312. char *
  313. { char *s = (char*) $varname;
  314. if ($varname == NULL) {
  315. $result = C_SCHEME_FALSE;
  316. }
  317. else {
  318. int string_len = strlen ($varname);
  319. C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
  320. $result = C_string (&string_space, string_len, s);
  321. }
  322. }
  323. %typemap(throws) char *
  324. {
  325. if ($1 == NULL) {
  326. SWIG_Chicken_ThrowException(C_SCHEME_FALSE);
  327. } else {
  328. int string_len = strlen($1);
  329. C_word *string_space = C_alloc(C_SIZEOF_STRING(string_len));
  330. SWIG_Chicken_ThrowException(C_string(&string_space, string_len, (char *) $1));
  331. }
  332. }
  333. /* Void */
  334. %typemap(out) void
  335. %{
  336. $result = C_SCHEME_UNDEFINED;
  337. %}
  338. /* Special typemap for character array return values */
  339. %typemap(out)
  340. char [ANY], const char [ANY]
  341. %{ if ($1 == NULL) {
  342. $result = C_SCHEME_FALSE;
  343. }
  344. else {
  345. const int string_len = strlen ($1);
  346. C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
  347. $result = C_string (&string_space, string_len, $1);
  348. } %}
  349. /* Primitive types--return by value */
  350. /* --- Variable input --- */
  351. /* A string */
  352. #ifdef __cplusplus
  353. %typemap(varin) char * {
  354. if ($input == C_SCHEME_FALSE) {
  355. $1 = NULL;
  356. }
  357. else if (!C_swig_is_string ($input)) {
  358. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
  359. }
  360. else {
  361. char *temp = C_c_string ($input);
  362. int len = C_header_size ($input);
  363. if ($1) delete [] $1;
  364. $1 = ($type) new char[len+1];
  365. strncpy((char*)$1, temp, len);
  366. ((char*)$1) [len] = 0;
  367. }
  368. }
  369. %typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
  370. if ($input == C_SCHEME_FALSE) {
  371. $1 = NULL;
  372. }
  373. else if (!C_swig_is_string ($input)) {
  374. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
  375. }
  376. else {
  377. char *temp = C_c_string ($input);
  378. int len = C_header_size ($input);
  379. $1 = ($type) new char[len+1];
  380. strncpy((char*)$1,temp,len);
  381. ((char*)$1) [len] = 0;
  382. }
  383. }
  384. #else
  385. %typemap(varin) char * {
  386. if ($input == C_SCHEME_FALSE) {
  387. $1 = NULL;
  388. }
  389. else if (!C_swig_is_string ($input)) {
  390. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
  391. }
  392. else {
  393. char *temp = C_c_string ($input);
  394. int len = C_header_size ($input);
  395. if ($1) free((char*) $1);
  396. $1 = ($type) malloc(len+1);
  397. strncpy((char*)$1,temp,len);
  398. ((char*)$1) [len] = 0;
  399. }
  400. }
  401. %typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
  402. if ($input == C_SCHEME_FALSE) {
  403. $1 = NULL;
  404. }
  405. else if (!C_swig_is_string ($input)) {
  406. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
  407. }
  408. else {
  409. char *temp = C_c_string ($input);
  410. int len = C_header_size ($input);
  411. $1 = ($type) malloc(len+1);
  412. strncpy((char*)$1,temp,len);
  413. ((char*)$1) [len] = 0;
  414. }
  415. }
  416. #endif
  417. %typemap(varin) char [] {
  418. swig_barf(SWIG_BARF1_BAD_ARGUMENT_TYPE, "C/C++ variable '$name' is read-only");
  419. }
  420. /* Special case for string array variables */
  421. %typemap(varin) char [ANY] {
  422. if ($input == C_SCHEME_FALSE) {
  423. memset($1,0,$1_dim0*sizeof(char));
  424. }
  425. else if (!C_swig_is_string ($input)) {
  426. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "C variable '$name ($1_ltype)'");
  427. }
  428. else {
  429. char *temp = C_c_string ($input);
  430. strncpy($1,temp,$1_dim0*sizeof(char));
  431. }
  432. }
  433. /* --- Variable output --- */
  434. /* Void */
  435. %typemap(varout) void "$result = C_SCHEME_UNDEFINED;";
  436. /* Special typemap for character array return values */
  437. %typemap(varout) char [ANY], const char [ANY]
  438. %{ if ($varname == NULL) {
  439. $result = C_SCHEME_FALSE;
  440. }
  441. else {
  442. const int string_len = strlen ($varname);
  443. C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
  444. $result = C_string (&string_space, string_len, (char *) $varname);
  445. }
  446. %}
  447. /* --- Constants --- */
  448. %typemap(constcode) char *
  449. "static const char *$result = $value;"
  450. %typemap(constcode) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
  451. "static const void *$result = (void*) $value;"
  452. /* ------------------------------------------------------------
  453. * String & length
  454. * ------------------------------------------------------------ */
  455. %typemap(in) (char *STRING, int LENGTH) {
  456. if ($input == C_SCHEME_FALSE) {
  457. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Cannot use a null/#f string for a char*, int arguments");
  458. }
  459. else if (C_swig_is_string ($input)) {
  460. $1 = ($1_ltype) C_c_string ($input);
  461. $2 = ($2_ltype) C_header_size ($input);
  462. }
  463. else {
  464. swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument #$argnum is not of type 'string'");
  465. }
  466. }
  467. /* ------------------------------------------------------------
  468. * CHICKEN types
  469. * ------------------------------------------------------------ */
  470. %typemap(in) C_word "$1 = $input;";
  471. %typemap(out) C_word "$result = $1;";
  472. /* ------------------------------------------------------------
  473. * Typechecking rules
  474. * ------------------------------------------------------------ */
  475. %typecheck(SWIG_TYPECHECK_INTEGER)
  476. bool, const bool &
  477. {
  478. $1 = C_swig_is_bool ($input);
  479. }
  480. %typecheck(SWIG_TYPECHECK_INTEGER)
  481. int, short,
  482. unsigned int, unsigned short,
  483. signed char, unsigned char,
  484. const int &, const short &,
  485. const unsigned int &, const unsigned short &,
  486. enum SWIGTYPE
  487. {
  488. $1 = C_swig_is_fixnum ($input);
  489. }
  490. %typecheck(SWIG_TYPECHECK_INTEGER)
  491. long,
  492. unsigned long,
  493. long long, unsigned long long,
  494. const long &,
  495. const unsigned long &,
  496. const long long &, const unsigned long long &
  497. {
  498. $1 = (C_swig_is_bool ($input) ||
  499. C_swig_is_fixnum ($input) ||
  500. C_swig_is_flonum ($input)) ? 1 : 0;
  501. }
  502. %typecheck(SWIG_TYPECHECK_DOUBLE)
  503. float, double,
  504. const float &, const double &
  505. {
  506. $1 = C_swig_is_flonum ($input);
  507. }
  508. %typecheck(SWIG_TYPECHECK_CHAR) char {
  509. $1 = C_swig_is_string ($input);
  510. }
  511. %typecheck(SWIG_TYPECHECK_STRING) char * {
  512. $1 = C_swig_is_string ($input);
  513. }
  514. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
  515. void *ptr;
  516. $1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0);
  517. }
  518. %typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
  519. void *ptr;
  520. $1 = !SWIG_ConvertPtr($input, &ptr, 0, 0);
  521. }
  522. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
  523. {
  524. void *ptr = 0;
  525. if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0)) {
  526. /* error */
  527. $1 = 0;
  528. } else {
  529. $1 = (ptr != 0);
  530. }
  531. }
  532. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
  533. {
  534. void *ptr = 0;
  535. if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0)) {
  536. /* error */
  537. $1 = 0;
  538. } else {
  539. $1 = (ptr != 0);
  540. }
  541. }
  542. /* ------------------------------------------------------------
  543. * Exception handling
  544. * ------------------------------------------------------------ */
  545. /* ------------------------------------------------------------
  546. * --- Exception handling ---
  547. * ------------------------------------------------------------ */
  548. %typemap(throws) SWIGTYPE {
  549. $&ltype temp = new $ltype($1);
  550. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  551. C_word ptr = SWIG_NewPointerObj(temp, $&descriptor,1);
  552. SWIG_Chicken_ThrowException(ptr);
  553. }
  554. %typemap(throws) SWIGTYPE * {
  555. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  556. C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
  557. SWIG_Chicken_ThrowException(ptr);
  558. }
  559. %typemap(throws) SWIGTYPE [ANY] {
  560. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  561. C_word ptr = SWIG_NewPointerObj((void *) $1, $descriptor, 0);
  562. SWIG_Chicken_ThrowException(ptr);
  563. }
  564. %typemap(throws) SWIGTYPE & {
  565. C_word *known_space = C_alloc(C_SIZEOF_SWIG_POINTER);
  566. C_word ptr = SWIG_NewPointerObj((void *)&($1),$descriptor,0);
  567. SWIG_Chicken_ThrowException(ptr);
  568. }
  569. /* ------------------------------------------------------------
  570. * ANSI C typemaps
  571. * ------------------------------------------------------------ */
  572. %apply unsigned long { size_t };
  573. /* ------------------------------------------------------------
  574. * Overloaded operator support
  575. * ------------------------------------------------------------ */
  576. #ifdef __cplusplus
  577. %rename(__add__) *::operator+;
  578. %rename(__pos__) *::operator+();
  579. %rename(__pos__) *::operator+() const;
  580. %rename(__sub__) *::operator-;
  581. %rename(__neg__) *::operator-();
  582. %rename(__neg__) *::operator-() const;
  583. %rename(__mul__) *::operator*;
  584. %rename(__div__) *::operator/;
  585. %rename(__mod__) *::operator%;
  586. %rename(__lshift__) *::operator<<;
  587. %rename(__rshift__) *::operator>>;
  588. %rename(__and__) *::operator&;
  589. %rename(__or__) *::operator|;
  590. %rename(__xor__) *::operator^;
  591. %rename(__invert__) *::operator~;
  592. %rename(__iadd__) *::operator+=;
  593. %rename(__isub__) *::operator-=;
  594. %rename(__imul__) *::operator*=;
  595. %rename(__idiv__) *::operator/=;
  596. %rename(__imod__) *::operator%=;
  597. %rename(__ilshift__) *::operator<<=;
  598. %rename(__irshift__) *::operator>>=;
  599. %rename(__iand__) *::operator&=;
  600. %rename(__ior__) *::operator|=;
  601. %rename(__ixor__) *::operator^=;
  602. %rename(__lt__) *::operator<;
  603. %rename(__le__) *::operator<=;
  604. %rename(__gt__) *::operator>;
  605. %rename(__ge__) *::operator>=;
  606. %rename(__eq__) *::operator==;
  607. %rename(__ne__) *::operator!=;
  608. /* Special cases */
  609. %rename(__call__) *::operator();
  610. #endif
  611. /* Warnings for certain CHICKEN keywords */
  612. %include <chickenkw.swg>
  613. /* TinyCLOS <--> Low-level CHICKEN */
  614. %typemap("clos_in") SIMPLE_CLOS_OBJECT * "(slot-ref $input (quote this))"
  615. %typemap("clos_out") SIMPLE_CLOS_OBJECT * "(make $class (quote this) $1)"
  616. %insert(header) %{
  617. #ifdef __cplusplus
  618. extern "C" {
  619. #endif
  620. /* Chicken initialization function */
  621. SWIGEXPORT void SWIG_init(C_word, C_word, C_word) C_noret;
  622. #ifdef __cplusplus
  623. }
  624. #endif
  625. %}
  626. %insert(closprefix) "swigclosprefix.scm"
  627. %insert(init) "swiginit.swg"
  628. %insert(init) %{
  629. /* CHICKEN initialization function */
  630. #ifdef __cplusplus
  631. extern "C" {
  632. #endif
  633. SWIGEXPORT void SWIG_init(C_word argc, C_word closure, C_word continuation) {
  634. int i;
  635. C_word sym;
  636. C_word tmp;
  637. C_word *a;
  638. C_word ret;
  639. C_word *return_vec;
  640. SWIG_InitializeModule(0);
  641. SWIG_PropagateClientData();
  642. ret = C_SCHEME_TRUE;
  643. #if $veclength
  644. return_vec = C_alloc(C_SIZEOF_VECTOR($veclength));
  645. ret = (C_word) return_vec;
  646. *(return_vec++) = C_VECTOR_TYPE | $veclength;
  647. #endif
  648. a = C_alloc(2*$nummethods$symsize);
  649. %}