| 1 | /* typemaps.i --- guile-specific typemaps -*- c -*- |
| 2 | Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> |
| 3 | |
| 4 | $Header: /cvsroot/swig/SWIG/Lib/guile/typemaps.i,v 1.31 2005/09/26 21:46:23 mkoeppe Exp $ */ |
| 5 | |
| 6 | /* Pointers */ |
| 7 | |
| 8 | %typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { |
| 9 | $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); |
| 10 | } |
| 11 | %typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] ""; |
| 12 | |
| 13 | %typemap(in) void * { |
| 14 | $1 = SWIG_MustGetPtr($input, NULL, $argnum, 0); |
| 15 | } |
| 16 | %typemap(freearg) void * ""; |
| 17 | |
| 18 | %typemap(varin) SWIGTYPE * { |
| 19 | $1 = ($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 [] { |
| 27 | scm_wrong_type_arg((char *) FUNC_NAME, 1, $input); |
| 28 | } |
| 29 | |
| 30 | %typemap(varin) SWIGTYPE [ANY] { |
| 31 | void *temp; |
| 32 | int ii; |
| 33 | $1_basetype *b = 0; |
| 34 | temp = SWIG_MustGetPtr($input, $1_descriptor, 1, 0); |
| 35 | b = ($1_basetype *) $1; |
| 36 | for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii); |
| 37 | } |
| 38 | |
| 39 | %typemap(varin) void * { |
| 40 | $1 = SWIG_MustGetPtr($input, NULL, 1, 0); |
| 41 | } |
| 42 | |
| 43 | %typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { |
| 44 | $result = SWIG_NewPointerObj ($1, $descriptor, $owner); |
| 45 | } |
| 46 | |
| 47 | %typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC { |
| 48 | swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1); |
| 49 | $result = SWIG_NewPointerObj ($1, ty, $owner); |
| 50 | } |
| 51 | |
| 52 | %typemap(varout) SWIGTYPE *, SWIGTYPE [] { |
| 53 | $result = SWIG_NewPointerObj ($1, $descriptor, 0); |
| 54 | } |
| 55 | |
| 56 | %typemap(varout) SWIGTYPE & { |
| 57 | $result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0); |
| 58 | } |
| 59 | |
| 60 | %typemap(throws) SWIGTYPE { |
| 61 | $<ype temp = new $ltype($1); |
| 62 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 63 | gh_list(SWIG_NewPointerObj(temp, $&descriptor, 1), |
| 64 | SCM_UNDEFINED)); |
| 65 | } |
| 66 | |
| 67 | %typemap(throws) SWIGTYPE & { |
| 68 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 69 | gh_list(SWIG_NewPointerObj(&$1, $descriptor, 1), |
| 70 | SCM_UNDEFINED)); |
| 71 | } |
| 72 | |
| 73 | %typemap(throws) SWIGTYPE * { |
| 74 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 75 | gh_list(SWIG_NewPointerObj($1, $descriptor, 1), |
| 76 | SCM_UNDEFINED)); |
| 77 | } |
| 78 | |
| 79 | %typemap(throws) SWIGTYPE [] { |
| 80 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 81 | gh_list(SWIG_NewPointerObj($1, $descriptor, 1), |
| 82 | SCM_UNDEFINED)); |
| 83 | } |
| 84 | |
| 85 | /* Change of object ownership, and interaction of destructor-like functions and the |
| 86 | garbage-collector */ |
| 87 | |
| 88 | %typemap(in, doc="$NAME is of type <$type> and gets destroyed by the function") SWIGTYPE *DESTROYED { |
| 89 | $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); |
| 90 | } |
| 91 | |
| 92 | %typemap(freearg) SWIGTYPE *DESTROYED { |
| 93 | SWIG_Guile_MarkPointerDestroyed($input); |
| 94 | } |
| 95 | |
| 96 | %typemap(in, doc="$NAME is of type <$type> and is consumed by the function") SWIGTYPE *CONSUMED { |
| 97 | $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); |
| 98 | SWIG_Guile_MarkPointerNoncollectable($input); |
| 99 | } |
| 100 | |
| 101 | /* Pass-by-value */ |
| 102 | |
| 103 | %typemap(in) SWIGTYPE($&1_ltype argp) { |
| 104 | argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); |
| 105 | $1 = *argp; |
| 106 | } |
| 107 | |
| 108 | %typemap(varin) SWIGTYPE { |
| 109 | $&1_ltype argp; |
| 110 | argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, 1, 0); |
| 111 | $1 = *argp; |
| 112 | } |
| 113 | |
| 114 | %typemap(out) SWIGTYPE |
| 115 | #ifdef __cplusplus |
| 116 | { |
| 117 | $&1_ltype resultptr; |
| 118 | resultptr = new $1_ltype(($1_ltype &) $1); |
| 119 | $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); |
| 120 | } |
| 121 | #else |
| 122 | { |
| 123 | $&1_ltype resultptr; |
| 124 | resultptr = ($&1_ltype) malloc(sizeof($1_type)); |
| 125 | memmove(resultptr, &$1, sizeof($1_type)); |
| 126 | $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 1); |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | %typemap(varout) SWIGTYPE |
| 131 | #ifdef __cplusplus |
| 132 | { |
| 133 | $&1_ltype resultptr; |
| 134 | resultptr = new $1_ltype(($1_ltype&) $1); |
| 135 | $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); |
| 136 | } |
| 137 | #else |
| 138 | { |
| 139 | $&1_ltype resultptr; |
| 140 | resultptr = ($&1_ltype) malloc(sizeof($1_type)); |
| 141 | memmove(resultptr, &$1, sizeof($1_type)); |
| 142 | $result = SWIG_NewPointerObj(resultptr, $&1_descriptor, 0); |
| 143 | } |
| 144 | #endif |
| 145 | |
| 146 | /* Enums */ |
| 147 | |
| 148 | %typemap(in) enum SWIGTYPE { $1 = ($1_type) gh_scm2int($input); } |
| 149 | /* The complicated construction below needed to deal with anonymous |
| 150 | enums, which cannot be cast to. */ |
| 151 | %typemap(varin) enum SWIGTYPE { |
| 152 | if (sizeof(int) != sizeof($1)) { |
| 153 | scm_error(scm_str2symbol("swig-error"), |
| 154 | (char *) FUNC_NAME, |
| 155 | (char *) "enum variable '$name' cannot be set", |
| 156 | SCM_EOL, SCM_BOOL_F); |
| 157 | } |
| 158 | * (int *) &($1) = gh_scm2int($input); |
| 159 | } |
| 160 | %typemap(out) enum SWIGTYPE { $result = gh_int2scm($1); } |
| 161 | %typemap(varout) enum SWIGTYPE { $result = gh_int2scm($1); } |
| 162 | %typemap(throws) enum SWIGTYPE { |
| 163 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 164 | gh_list(gh_int2scm($1), SCM_UNDEFINED)); |
| 165 | } |
| 166 | |
| 167 | /* The SIMPLE_MAP_WITH_EXPR macro below defines the whole set of |
| 168 | typemaps needed for simple types. |
| 169 | -- SCM_TO_C_EXPR is a C expression that translates the Scheme value |
| 170 | "swig_scm_value" to a C value. |
| 171 | -- C_TO_SCM_EXPR is a C expression that translates the C value |
| 172 | "swig_c_value" to a Scheme value. */ |
| 173 | |
| 174 | %define SIMPLE_MAP_WITH_EXPR(C_NAME, SCM_TO_C_EXPR, C_TO_SCM_EXPR, SCM_NAME) |
| 175 | %typemap (in, doc="$NAME is of type <" #SCM_NAME ">") C_NAME |
| 176 | { SCM swig_scm_value = $input; |
| 177 | $1 = SCM_TO_C_EXPR; } |
| 178 | %typemap (varin, doc="NEW-VALUE is of type <" #SCM_NAME ">") C_NAME |
| 179 | { SCM swig_scm_value = $input; |
| 180 | $1 = SCM_TO_C_EXPR; } |
| 181 | %typemap (out, doc="<" #SCM_NAME ">") C_NAME |
| 182 | { C_NAME swig_c_value = $1; |
| 183 | $result = C_TO_SCM_EXPR; } |
| 184 | %typemap (varout, doc="<" #SCM_NAME ">") C_NAME |
| 185 | { C_NAME swig_c_value = $1; |
| 186 | $result = C_TO_SCM_EXPR; } |
| 187 | /* INPUT and OUTPUT */ |
| 188 | %typemap (in, doc="$NAME is of type <" #SCM_NAME ">)") |
| 189 | C_NAME *INPUT(C_NAME temp) { |
| 190 | SCM swig_scm_value = $input; |
| 191 | temp = (C_NAME) SCM_TO_C_EXPR; $1 = &temp; } |
| 192 | %typemap (in,numinputs=0) C_NAME *OUTPUT (C_NAME temp) |
| 193 | {$1 = &temp;} |
| 194 | %typemap (argout,doc="$name (of type <" #SCM_NAME ">)") C_NAME *OUTPUT |
| 195 | { C_NAME swig_c_value = *$1; |
| 196 | SWIG_APPEND_VALUE(C_TO_SCM_EXPR); } |
| 197 | %typemap (in) C_NAME *BOTH = C_NAME *INPUT; |
| 198 | %typemap (argout) C_NAME *BOTH = C_NAME *OUTPUT; |
| 199 | %typemap (in) C_NAME *INOUT = C_NAME *INPUT; |
| 200 | %typemap (argout) C_NAME *INOUT = C_NAME *OUTPUT; |
| 201 | /* Const primitive references. Passed by value */ |
| 202 | %typemap(in, doc="$NAME is of type <" #SCM_NAME ">") const C_NAME & (C_NAME temp) |
| 203 | { SCM swig_scm_value = $input; |
| 204 | temp = SCM_TO_C_EXPR; |
| 205 | $1 = &temp; } |
| 206 | %typemap(out, doc="<" #SCM_NAME ">") const C_NAME & |
| 207 | { C_NAME swig_c_value = *$1; |
| 208 | $result = C_TO_SCM_EXPR; } |
| 209 | /* Throw typemap */ |
| 210 | %typemap(throws) C_NAME { |
| 211 | C_NAME swig_c_value = $1; |
| 212 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 213 | gh_list(C_TO_SCM_EXPR, SCM_UNDEFINED)); |
| 214 | } |
| 215 | %enddef |
| 216 | |
| 217 | /* The SIMPLE_MAP macro below defines the whole set of typemaps needed |
| 218 | for simple types. It generates slightly simpler code than the |
| 219 | macro above, but it is only suitable for very simple conversion |
| 220 | expressions. */ |
| 221 | |
| 222 | %define SIMPLE_MAP(C_NAME, SCM_TO_C, C_TO_SCM, SCM_NAME) |
| 223 | %typemap (in, doc="$NAME is of type <" #SCM_NAME ">") |
| 224 | C_NAME {$1 = SCM_TO_C($input);} |
| 225 | %typemap (varin, doc="NEW-VALUE is of type <" #SCM_NAME ">") |
| 226 | C_NAME {$1 = SCM_TO_C($input);} |
| 227 | %typemap (out, doc="<" #SCM_NAME ">") |
| 228 | C_NAME {$result = C_TO_SCM($1);} |
| 229 | %typemap (varout, doc="<" #SCM_NAME ">") |
| 230 | C_NAME {$result = C_TO_SCM($1);} |
| 231 | /* INPUT and OUTPUT */ |
| 232 | %typemap (in, doc="$NAME is of type <" #SCM_NAME ">)") |
| 233 | C_NAME *INPUT(C_NAME temp), C_NAME &INPUT(C_NAME temp) { |
| 234 | temp = (C_NAME) SCM_TO_C($input); $1 = &temp; |
| 235 | } |
| 236 | %typemap (in,numinputs=0) C_NAME *OUTPUT (C_NAME temp), C_NAME &OUTPUT(C_NAME temp) |
| 237 | {$1 = &temp;} |
| 238 | %typemap (argout,doc="$name (of type <" #SCM_NAME ">)") C_NAME *OUTPUT, C_NAME &OUTPUT |
| 239 | {SWIG_APPEND_VALUE(C_TO_SCM(*$1));} |
| 240 | %typemap (in) C_NAME *BOTH = C_NAME *INPUT; |
| 241 | %typemap (argout) C_NAME *BOTH = C_NAME *OUTPUT; |
| 242 | %typemap (in) C_NAME *INOUT = C_NAME *INPUT; |
| 243 | %typemap (argout) C_NAME *INOUT = C_NAME *OUTPUT; |
| 244 | %typemap (in) C_NAME &INOUT = C_NAME &INPUT; |
| 245 | %typemap (argout) C_NAME &INOUT = C_NAME &OUTPUT; |
| 246 | /* Const primitive references. Passed by value */ |
| 247 | %typemap(in, doc="$NAME is of type <" #SCM_NAME ">") const C_NAME & (C_NAME temp) { |
| 248 | temp = SCM_TO_C($input); |
| 249 | $1 = &temp; |
| 250 | } |
| 251 | %typemap(out, doc="<" #SCM_NAME ">") const C_NAME & { |
| 252 | $result = C_TO_SCM(*$1); |
| 253 | } |
| 254 | /* Throw typemap */ |
| 255 | %typemap(throws) C_NAME { |
| 256 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 257 | gh_list(C_TO_SCM($1), SCM_UNDEFINED)); |
| 258 | } |
| 259 | %enddef |
| 260 | |
| 261 | SIMPLE_MAP(bool, gh_scm2bool, gh_bool2scm, boolean); |
| 262 | SIMPLE_MAP(char, gh_scm2char, gh_char2scm, char); |
| 263 | SIMPLE_MAP(unsigned char, gh_scm2char, gh_char2scm, char); |
| 264 | SIMPLE_MAP(signed char, gh_scm2char, gh_char2scm, char); |
| 265 | SIMPLE_MAP(int, gh_scm2int, gh_int2scm, integer); |
| 266 | SIMPLE_MAP(short, gh_scm2int, gh_int2scm, integer); |
| 267 | SIMPLE_MAP(long, gh_scm2long, gh_long2scm, integer); |
| 268 | SIMPLE_MAP(ptrdiff_t, gh_scm2long, gh_long2scm, integer); |
| 269 | SIMPLE_MAP(unsigned int, gh_scm2ulong, gh_ulong2scm, integer); |
| 270 | SIMPLE_MAP(unsigned short, gh_scm2ulong, gh_ulong2scm, integer); |
| 271 | SIMPLE_MAP(unsigned long, gh_scm2ulong, gh_ulong2scm, integer); |
| 272 | SIMPLE_MAP(size_t, gh_scm2ulong, gh_ulong2scm, integer); |
| 273 | SIMPLE_MAP(float, gh_scm2double, gh_double2scm, real); |
| 274 | SIMPLE_MAP(double, gh_scm2double, gh_double2scm, real); |
| 275 | // SIMPLE_MAP(char *, SWIG_scm2str, gh_str02scm, string); |
| 276 | // SIMPLE_MAP(const char *, SWIG_scm2str, gh_str02scm, string); |
| 277 | |
| 278 | /* Strings */ |
| 279 | |
| 280 | %typemap (in, doc="$NAME is a string") char *(int must_free = 0) { |
| 281 | $1 = SWIG_scm2str($input); |
| 282 | must_free = 1; |
| 283 | } |
| 284 | %typemap (varin, doc="NEW-VALUE is a string") char * {$1 = SWIG_scm2str($input);} |
| 285 | %typemap (out, doc="<string>") char * {$result = gh_str02scm($1);} |
| 286 | %typemap (varout, doc="<string>") char * {$result = gh_str02scm($1);} |
| 287 | %typemap (in, doc="$NAME is a string") char * *INPUT(char * temp, int must_free = 0) { |
| 288 | temp = (char *) SWIG_scm2str($input); $1 = &temp; |
| 289 | must_free = 1; |
| 290 | } |
| 291 | %typemap (in,numinputs=0) char * *OUTPUT (char * temp) |
| 292 | {$1 = &temp;} |
| 293 | %typemap (argout,doc="$NAME (a string)") char * *OUTPUT |
| 294 | {SWIG_APPEND_VALUE(gh_str02scm(*$1));} |
| 295 | %typemap (in) char * *BOTH = char * *INPUT; |
| 296 | %typemap (argout) char * *BOTH = char * *OUTPUT; |
| 297 | %typemap (in) char * *INOUT = char * *INPUT; |
| 298 | %typemap (argout) char * *INOUT = char * *OUTPUT; |
| 299 | |
| 300 | /* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after |
| 301 | the function call. */ |
| 302 | |
| 303 | %typemap (freearg) char * "if (must_free$argnum && $1) SWIG_free($1);"; |
| 304 | %typemap (freearg) char **INPUT, char **BOTH "if (must_free$argnum && (*$1)) SWIG_free(*$1);" |
| 305 | %typemap (freearg) char **OUTPUT "SWIG_free(*$1);" |
| 306 | |
| 307 | /* But this shall not apply if we try to pass a single char by |
| 308 | reference. */ |
| 309 | |
| 310 | %typemap (freearg) char *OUTPUT, char *BOTH ""; |
| 311 | |
| 312 | /* If we set a string variable, delete the old result first, unless const. */ |
| 313 | |
| 314 | %typemap (varin) char * { |
| 315 | if ($1) free($1); |
| 316 | $1 = SWIG_scm2str($input); |
| 317 | } |
| 318 | |
| 319 | %typemap (varin) const char * { |
| 320 | $1 = SWIG_scm2str($input); |
| 321 | } |
| 322 | |
| 323 | %typemap(throws) char * { |
| 324 | scm_throw(gh_symbol2scm((char *) "swig-exception"), |
| 325 | gh_list(gh_str02scm($1), SCM_UNDEFINED)); |
| 326 | } |
| 327 | |
| 328 | /* Void */ |
| 329 | |
| 330 | %typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;"; |
| 331 | |
| 332 | /* SCM is passed through */ |
| 333 | |
| 334 | typedef unsigned long SCM; |
| 335 | %typemap (in) SCM "$1=$input;"; |
| 336 | %typemap (out) SCM "$result=$1;"; |
| 337 | %typecheck(SWIG_TYPECHECK_POINTER) SCM "$1=1;"; |
| 338 | |
| 339 | /* ------------------------------------------------------------ |
| 340 | * String & length |
| 341 | * ------------------------------------------------------------ */ |
| 342 | |
| 343 | %typemap(in) (char *STRING, int LENGTH) { |
| 344 | size_t temp; |
| 345 | $1 = ($1_ltype) gh_scm2newstr($input, &temp); |
| 346 | $2 = ($2_ltype) temp; |
| 347 | } |
| 348 | |
| 349 | /* ------------------------------------------------------------ |
| 350 | * Typechecking rules |
| 351 | * ------------------------------------------------------------ */ |
| 352 | |
| 353 | /* adapted from python.swg */ |
| 354 | |
| 355 | %typecheck(SWIG_TYPECHECK_INTEGER) |
| 356 | int, short, long, |
| 357 | unsigned int, unsigned short, unsigned long, |
| 358 | signed char, unsigned char, |
| 359 | long long, unsigned long long, |
| 360 | size_t, ptrdiff_t, |
| 361 | std::size_t, std::ptrdiff_t, |
| 362 | const int &, const short &, const long &, |
| 363 | const unsigned int &, const unsigned short &, const unsigned long &, |
| 364 | const long long &, const unsigned long long &, |
| 365 | const size_t &, const ptrdiff_t &, |
| 366 | const std::size_t &, const std::ptrdiff_t &, |
| 367 | enum SWIGTYPE |
| 368 | { |
| 369 | $1 = SCM_NFALSEP(scm_integer_p($input)) ? 1 : 0; |
| 370 | } |
| 371 | |
| 372 | %typecheck(SWIG_TYPECHECK_BOOL) |
| 373 | bool, bool&, const bool& |
| 374 | { |
| 375 | $1 = SCM_BOOLP($input) ? 1 : 0; |
| 376 | } |
| 377 | |
| 378 | %typecheck(SWIG_TYPECHECK_DOUBLE) |
| 379 | float, double, |
| 380 | const float &, const double & |
| 381 | { |
| 382 | $1 = SCM_NFALSEP(scm_real_p($input)) ? 1 : 0; |
| 383 | } |
| 384 | |
| 385 | %typecheck(SWIG_TYPECHECK_CHAR) char { |
| 386 | $1 = SCM_CHARP($input) ? 1 : 0; |
| 387 | } |
| 388 | |
| 389 | %typecheck(SWIG_TYPECHECK_STRING) char * { |
| 390 | $1 = SCM_STRINGP($input) ? 1 : 0; |
| 391 | } |
| 392 | |
| 393 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] { |
| 394 | void *ptr; |
| 395 | $1 = !SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0); |
| 396 | } |
| 397 | |
| 398 | %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE { |
| 399 | void *ptr; |
| 400 | $1 = !SWIG_ConvertPtr($input, &ptr, $&descriptor, 0); |
| 401 | } |
| 402 | |
| 403 | %typecheck(SWIG_TYPECHECK_VOIDPTR) void * { |
| 404 | void *ptr; |
| 405 | $1 = !SWIG_ConvertPtr($input, &ptr, 0, 0); |
| 406 | } |
| 407 | |
| 408 | /* typemaps.i ends here */ |