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