1 /* ----------------------------------------------------------------------------- 2 * typemaps.i 3 * ----------------------------------------------------------------------------- */ 4 5 /* The MzScheme module handles all types uniformly via typemaps. Here 6 are the definitions. */ 7 8 /* Pointers */ 9 10 %typemap(in) SWIGTYPE * { 11 $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0); 12 } 13 14 %typemap(in) void * { 15 $1 = SWIG_MustGetPtr($input, NULL, $argnum, 0); 16 } 17 18 %typemap(varin) SWIGTYPE * { 19 $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, 1, 0); 20 } 21 22 %typemap(varin) SWIGTYPE & { 23 $1 = *(($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0)); 24 } 25 26 %typemap(varin) SWIGTYPE [ANY] { 27 void *temp; 28 int ii; 29 $1_basetype *b = 0; 30 temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0); 31 b = ($1_basetype *) $1; 32 for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii); 33 } 34 35 36 %typemap(varin) void * { 37 $1 = SWIG_MustGetPtr($input, NULL, 1, 0); 38 } 39 40 %typemap(out) SWIGTYPE * { 41 $result = SWIG_NewPointerObj ($1, $descriptor, $owner); 42 } 43 44 %typemap(out) SWIGTYPE *DYNAMIC { 45 swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1); 46 $result = SWIG_NewPointerObj ($1, ty, $owner); 47 } 48 49 %typemap(varout) SWIGTYPE *, SWIGTYPE [] { 50 $result = SWIG_NewPointerObj ($1, $descriptor, 0); 51 } 52 53 %typemap(varout) SWIGTYPE & { 54 $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); 55 } 56 57 /* C++ References */ 58 59 #ifdef __cplusplus 60 61 %typemap(in) SWIGTYPE &, const SWIGTYPE & { 62 $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0); 63 if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)"); 64 } 65 66 %typemap(out) SWIGTYPE &, const SWIGTYPE & { 67 $result = SWIG_NewPointerObj ($1, $descriptor, $owner); 68 } 69 70 %typemap(out) SWIGTYPE &DYNAMIC { 71 swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1); 72 $result = SWIG_NewPointerObj ($1, ty, $owner); 73 } 74 75 #endif 76 77 /* Arrays */ 78 79 %typemap(in) SWIGTYPE[] { 80 $1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0); 81 } 82 83 %typemap(out) SWIGTYPE[] { 84 $result = SWIG_NewPointerObj ($1, $descriptor, $owner); 85 } 86 87 /* Enums */ 88 %typemap(in) enum SWIGTYPE { 89 if (!SWIG_is_integer($input)) 90 scheme_wrong_type(FUNC_NAME, "integer", $argnum - 1, argc, argv); 91 $1 = ($1_type) SWIG_convert_int($input); 92 } 93 94 %typemap(varin) enum SWIGTYPE { 95 if (!SWIG_is_integer($input)) 96 scheme_wrong_type(FUNC_NAME, "integer", 0, argc, argv); 97 $1 = ($1_type) SWIG_convert_int($input); 98 } 99 100 %typemap(out) enum SWIGTYPE "$result = scheme_make_integer_value($1);"; 101 %typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);"; 102 103 104 /* Pass-by-value */ 105 106 %typemap(in) SWIGTYPE($&1_ltype argp) { 107 argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); 108 $1 = *argp; 109 } 110 111 %typemap(varin) SWIGTYPE { 112 $&1_ltype argp; 113 argp = ($&1_ltype) SWIG_MustGetPtr($input, $&1_descriptor, 1, 0); 114 $1 = *argp; 115 } 116 117 118 %typemap(out) SWIGTYPE 119 #ifdef __cplusplus 120 { 121 $&1_ltype resultptr; 122 resultptr = new $1_ltype(($1_ltype &) $1); 123 $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); 124 } 125 #else 126 { 127 $&1_ltype resultptr; 128 resultptr = ($&1_ltype) malloc(sizeof($1_type)); 129 memmove(resultptr, &$1, sizeof($1_type)); 130 $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1); 131 } 132 #endif 133 134 %typemap(varout) SWIGTYPE 135 #ifdef __cplusplus 136 { 137 $&1_ltype resultptr; 138 resultptr = new $1_ltype(($1_ltype &) $1); 139 $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); 140 } 141 #else 142 { 143 $&1_ltype resultptr; 144 resultptr = ($&1_ltype) malloc(sizeof($1_type)); 145 memmove(resultptr, &$1, sizeof($1_type)); 146 $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0); 147 } 148 #endif 149 150 /* The SIMPLE_MAP macro below defines the whole set of typemaps needed 151 for simple types. */ 152 153 %define SIMPLE_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME) 154 %typemap(in) C_NAME { 155 if (!MZ_PREDICATE($input)) 156 scheme_wrong_type(FUNC_NAME, #MZ_NAME, $argnum - 1, argc, argv); 157 $1 = MZ_TO_C($input); 158 } 159 %typemap(varin) C_NAME { 160 if (!MZ_PREDICATE($input)) 161 scheme_wrong_type(FUNC_NAME, #MZ_NAME, 0, argc, argv); 162 $1 = MZ_TO_C($input); 163 } 164 %typemap(out) C_NAME { 165 $result = C_TO_MZ($1); 166 } 167 %typemap(varout) C_NAME { 168 $result = C_TO_MZ($1); 169 } 170 %typemap(in) C_NAME *INPUT (C_NAME temp) { 171 temp = (C_NAME) MZ_TO_C($input); 172 $1 = &temp; 173 } 174 %typemap(in,numinputs=0) C_NAME *OUTPUT (C_NAME temp) { 175 $1 = &temp; 176 } 177 %typemap(argout) C_NAME *OUTPUT { 178 Scheme_Object *s; 179 s = C_TO_MZ(*$1); 180 SWIG_APPEND_VALUE(s); 181 } 182 %typemap(in) C_NAME *BOTH = C_NAME *INPUT; 183 %typemap(argout) C_NAME *BOTH = C_NAME *OUTPUT; 184 %typemap(in) C_NAME *INOUT = C_NAME *INPUT; 185 %typemap(argout) C_NAME *INOUT = C_NAME *OUTPUT; 186 %enddef 187 188 SIMPLE_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP, 189 swig_make_boolean, boolean); 190 SIMPLE_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL, 191 scheme_make_character, character); 192 SIMPLE_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL, 193 scheme_make_character, character); 194 SIMPLE_MAP(int, SWIG_is_integer, SWIG_convert_int, 195 scheme_make_integer_value, integer); 196 SIMPLE_MAP(short, SWIG_is_integer, SWIG_convert_short, 197 scheme_make_integer_value, integer); 198 SIMPLE_MAP(long, SWIG_is_integer, SWIG_convert_long, 199 scheme_make_integer_value, integer); 200 SIMPLE_MAP(ptrdiff_t, SWIG_is_integer, SWIG_convert_long, 201 scheme_make_integer_value, integer); 202 SIMPLE_MAP(unsigned int, SWIG_is_unsigned_integer, SWIG_convert_unsigned_int, 203 scheme_make_integer_value_from_unsigned, integer); 204 SIMPLE_MAP(unsigned short, SWIG_is_unsigned_integer, SWIG_convert_unsigned_short, 205 scheme_make_integer_value_from_unsigned, integer); 206 SIMPLE_MAP(unsigned long, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long, 207 scheme_make_integer_value_from_unsigned, integer); 208 SIMPLE_MAP(size_t, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long, 209 scheme_make_integer_value_from_unsigned, integer); 210 SIMPLE_MAP(float, SCHEME_REALP, scheme_real_to_double, 211 scheme_make_double, real); 212 SIMPLE_MAP(double, SCHEME_REALP, scheme_real_to_double, 213 scheme_make_double, real); 214 215 SIMPLE_MAP(char *, SCHEME_STRINGP, SCHEME_STR_VAL, 216 SCHEME_MAKE_STRING, string); 217 SIMPLE_MAP(const char *, SCHEME_STRINGP, SCHEME_STR_VAL, 218 SCHEME_MAKE_STRING, string); 219 220 /* For MzScheme 30x: Use these typemaps if you are not going to use 221 UTF8 encodings in your C code. 222 SIMPLE_MAP(char *,SCHEME_BYTE_STRINGP, SCHEME_BYTE_STR_VAL, 223 scheme_make_byte_string_without_copying,bytestring); 224 SIMPLE_MAP(const char *,SCHEME_BYTE_STRINGP, SCHEME_BYTE_STR_VAL, 225 scheme_make_byte_string_without_copying,bytestring); 226 */ 227 228 /* Const primitive references. Passed by value */ 229 230 %define REF_MAP(C_NAME, MZ_PREDICATE, MZ_TO_C, C_TO_MZ, MZ_NAME) 231 %typemap(in) const C_NAME & (C_NAME temp) { 232 if (!MZ_PREDICATE($input)) 233 scheme_wrong_type(FUNC_NAME, #MZ_NAME, $argnum - 1, argc, argv); 234 temp = MZ_TO_C($input); 235 $1 = &temp; 236 } 237 %typemap(out) const C_NAME & { 238 $result = C_TO_MZ(*$1); 239 } 240 %enddef 241 242 REF_MAP(bool, SCHEME_BOOLP, SCHEME_TRUEP, 243 swig_make_boolean, boolean); 244 REF_MAP(char, SCHEME_CHARP, SCHEME_CHAR_VAL, 245 scheme_make_character, character); 246 REF_MAP(unsigned char, SCHEME_CHARP, SCHEME_CHAR_VAL, 247 scheme_make_character, character); 248 REF_MAP(int, SWIG_is_integer, SWIG_convert_int, 249 scheme_make_integer_value, integer); 250 REF_MAP(short, SWIG_is_integer, SWIG_convert_short, 251 scheme_make_integer_value, integer); 252 REF_MAP(long, SWIG_is_integer, SWIG_convert_long, 253 scheme_make_integer_value, integer); 254 REF_MAP(unsigned int, SWIG_is_unsigned_integer, SWIG_convert_unsigned_int, 255 scheme_make_integer_value_from_unsigned, integer); 256 REF_MAP(unsigned short, SWIG_is_unsigned_integer, SWIG_convert_unsigned_short, 257 scheme_make_integer_value_from_unsigned, integer); 258 REF_MAP(unsigned long, SWIG_is_unsigned_integer, SWIG_convert_unsigned_long, 259 scheme_make_integer_value_from_unsigned, integer); 260 REF_MAP(float, SCHEME_REALP, scheme_real_to_double, 261 scheme_make_double, real); 262 REF_MAP(double, SCHEME_REALP, scheme_real_to_double, 263 scheme_make_double, real); 264 265 /* Void */ 266 267 %typemap(out) void "$result = scheme_void;"; 268 269 /* Pass through Scheme_Object * */ 270 271 %typemap (in) Scheme_Object * "$1=$input;"; 272 %typemap (out) Scheme_Object * "$result=$1;"; 273 %typecheck(SWIG_TYPECHECK_POINTER) Scheme_Object * "$1=1;"; 274 275 276 /* ------------------------------------------------------------ 277 * String & length 278 * ------------------------------------------------------------ */ 279 280 //%typemap(in) (char *STRING, int LENGTH) { 281 // int temp; 282 // $1 = ($1_ltype) SWIG_Guile_scm2newstr($input, &temp); 283 // $2 = ($2_ltype) temp; 284 //} 285 286 287 /* ------------------------------------------------------------ 288 * Typechecking rules 289 * ------------------------------------------------------------ */ 290 291 %typecheck(SWIG_TYPECHECK_INTEGER) 292 int, short, long, 293 unsigned int, unsigned short, unsigned long, 294 signed char, unsigned char, 295 long long, unsigned long long, 296 const int &, const short &, const long &, 297 const unsigned int &, const unsigned short &, const unsigned long &, 298 const long long &, const unsigned long long &, 299 enum SWIGTYPE 300 { 301 $1 = (SWIG_is_integer($input)) ? 1 : 0; 302 } 303 304 %typecheck(SWIG_TYPECHECK_BOOL) bool, bool &, const bool & 305 { 306 $1 = (SCHEME_BOOLP($input)) ? 1 : 0; 307 } 308 309 %typecheck(SWIG_TYPECHECK_DOUBLE) 310 float, double, 311 const float &, const double & 312 { 313 $1 = (SCHEME_REALP($input)) ? 1 : 0; 314 } 315 316 %typecheck(SWIG_TYPECHECK_STRING) char { 317 $1 = (SCHEME_STRINGP($input)) ? 1 : 0; 318 } 319 320 %typecheck(SWIG_TYPECHECK_STRING) char * { 321 $1 = (SCHEME_STRINGP($input)) ? 1 : 0; 322 } 323 324 %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { 325 void *ptr; 326 if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0)) { 327 $1 = 0; 328 } else { 329 $1 = 1; 330 } 331 } 332 333 %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { 334 void *ptr; 335 if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0)) { 336 $1 = 0; 337 } else { 338 $1 = 1; 339 } 340 } 341 342 %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { 343 void *ptr; 344 if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0)) { 345 $1 = 0; 346 } else { 347 $1 = 1; 348 } 349 } 350 351 352 /* Array reference typemaps */ 353 %apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) } 354 355 /* const pointers */ 356 %apply SWIGTYPE * { SWIGTYPE *const } 357 358 359