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.
7 * The Ocaml module handles all types uniformly via typemaps. Here
9 * ----------------------------------------------------------------------------- */
15 %typemap(out) void "$result = Val_int(0);"
18 $1 = caml_ptr_val($input,$descriptor);
21 %typemap(varin) void * {
22 $1 = ($ltype)caml_ptr_val($input,$descriptor);
25 %typemap(out) void * {
26 $result = caml_val_ptr($1,$descriptor);
29 %typemap(varout) void * {
30 $result = caml_val_ptr($1,$descriptor);
35 %typemap(in) SWIGTYPE & {
36 /* %typemap(in) SWIGTYPE & */
37 $1 = ($ltype) caml_ptr_val($input,$1_descriptor);
40 %typemap(varin) SWIGTYPE & {
41 /* %typemap(varin) SWIGTYPE & */
42 $1 = *(($ltype) caml_ptr_val($input,$1_descriptor));
45 %typemap(out) SWIGTYPE & {
46 /* %typemap(out) SWIGTYPE & */
47 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
49 $result = callback(*fromval,caml_val_ptr((void *) &$1,$1_descriptor));
51 $result = caml_val_ptr ((void *) &$1,$1_descriptor);
56 %typemap(argout) SWIGTYPE & {
57 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
60 caml_list_append(swig_result,
61 callback(*fromval,caml_val_ptr((void *) $1,
65 caml_list_append(swig_result,
66 caml_val_ptr ((void *) $1,$1_descriptor));
71 %typemap(argout) const SWIGTYPE & { }
73 %typemap(in) SWIGTYPE {
74 $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
77 %typemap(out) SWIGTYPE {
78 /* %typemap(out) SWIGTYPE */
79 $&1_ltype temp = new $ltype((const $1_ltype &) $1);
80 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
82 $result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
84 $result = caml_val_ptr ((void *)temp,$&1_descriptor);
90 %typemap(in) SWIGTYPE {
91 $1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
94 %typemap(out) SWIGTYPE {
95 /* %typemap(out) SWIGTYPE */
96 void *temp = calloc(1,sizeof($ltype));
97 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
98 memmove( temp, &$1, sizeof( $1_type ) );
100 $result = callback(*fromval,caml_val_ptr((void *)temp,$&1_descriptor));
102 $result = caml_val_ptr ((void *)temp,$&1_descriptor);
106 %apply SWIGTYPE { const SWIGTYPE & };
110 /* The SIMPLE_MAP macro below defines the whole set of typemaps needed
113 %define SIMPLE_MAP(C_NAME, C_TO_MZ, MZ_TO_C)
115 %typemap(in) C_NAME {
116 $1 = MZ_TO_C($input);
118 %typemap(varin) C_NAME {
119 $1 = MZ_TO_C($input);
121 %typemap(in) C_NAME & ($*1_ltype temp) {
122 temp = ($*1_ltype) MZ_TO_C($input);
125 %typemap(varin) C_NAME & {
126 $1 = MZ_TO_C($input);
128 %typemap(directorout) C_NAME {
129 $1 = MZ_TO_C($input);
131 %typemap(in) C_NAME *INPUT ($*1_ltype temp) {
132 temp = ($*1_ltype) MZ_TO_C($input);
135 %typemap(in,numinputs=0) C_NAME *OUTPUT ($*1_ltype temp) {
139 %typemap(out) C_NAME {
140 $result = C_TO_MZ($1);
142 %typemap(varout) C_NAME {
143 $result = C_TO_MZ($1);
145 %typemap(varout) C_NAME & {
146 /* %typemap(varout) C_NAME & (generic) */
147 $result = C_TO_MZ($1);
149 %typemap(argout) C_NAME *OUTPUT {
150 swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
152 %typemap(out) C_NAME & {
153 /* %typemap(out) C_NAME & (generic) */
154 $result = C_TO_MZ(*$1);
156 %typemap(argout) C_NAME & {
157 swig_result = caml_list_append(swig_result,C_TO_MZ((long)*$1));
159 %typemap(directorin) C_NAME {
160 args = caml_list_append(args,C_TO_MZ($1_name));
164 SIMPLE_MAP(bool, caml_val_bool, caml_long_val);
165 SIMPLE_MAP(oc_bool, caml_val_bool, caml_long_val);
166 SIMPLE_MAP(char, caml_val_char, caml_long_val);
167 SIMPLE_MAP(signed char, caml_val_char, caml_long_val);
168 SIMPLE_MAP(unsigned char, caml_val_uchar, caml_long_val);
169 SIMPLE_MAP(int, caml_val_int, caml_long_val);
170 SIMPLE_MAP(short, caml_val_short, caml_long_val);
171 SIMPLE_MAP(wchar_t, caml_val_short, caml_long_val);
172 SIMPLE_MAP(long, caml_val_long, caml_long_val);
173 SIMPLE_MAP(ptrdiff_t, caml_val_int, caml_long_val);
174 SIMPLE_MAP(unsigned int, caml_val_uint, caml_long_val);
175 SIMPLE_MAP(unsigned short, caml_val_ushort, caml_long_val);
176 SIMPLE_MAP(unsigned long, caml_val_ulong, caml_long_val);
177 SIMPLE_MAP(size_t, caml_val_int, caml_long_val);
178 SIMPLE_MAP(float, caml_val_float, caml_double_val);
179 SIMPLE_MAP(double, caml_val_double, caml_double_val);
180 SIMPLE_MAP(long long,caml_val_ulong,caml_long_val);
181 SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
185 %typemap(out) void "$result = Val_unit;";
187 /* Pass through value */
189 %typemap (in) value,caml::value,CAML_VALUE "$1=$input;";
190 %typemap (out) value,caml::value,CAML_VALUE "$result=$1;";
194 %typemap(in) ArrayCarrier * {
195 $1 = ($ltype)caml_ptr_val($input,$1_descriptor);
198 %typemap(out) ArrayCarrier * {
199 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
201 $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
203 $result = caml_val_ptr ((void *)$1,$1_descriptor);
211 /* Handle char arrays as strings */
213 %define %char_ptr_in(how)
214 %typemap(how) char *, signed char *, unsigned char * {
215 /* %typemap(how) char * ... */
216 $1 = ($ltype)caml_string_val($input);
218 /* Again work around the empty array bound bug */
219 %typemap(how) char [ANY], signed char [ANY], unsigned char [ANY] {
220 /* %typemap(how) char [ANY] ... */
221 char *temp = caml_string_val($input);
222 strcpy((char *)$1,temp);
223 /* strncpy would be better but we might not have an array size */
229 %char_ptr_in(directorout);
231 %define %char_ptr_out(how)
233 char *, signed char *, unsigned char *,
234 const char *, const signed char *, const unsigned char * {
235 $result = caml_val_string((char *)$1);
237 /* I'd like to use the length here but can't because it might be empty */
239 char [ANY], signed char [ANY], unsigned char [ANY],
240 const char [ANY], const signed char [ANY], const unsigned char [ANY] {
241 $result = caml_val_string((char *)$1);
246 %char_ptr_out(varout);
247 %char_ptr_out(directorin);
249 %define %swigtype_ptr_in(how)
250 %typemap(how) SWIGTYPE * {
251 /* %typemap(how) SWIGTYPE * */
252 $1 = ($ltype)caml_ptr_val($input,$1_descriptor);
254 %typemap(how) SWIGTYPE (CLASS::*) {
255 /* %typemap(how) SWIGTYPE (CLASS::*) */
256 void *v = caml_ptr_val($input,$1_descriptor);
257 memcpy(& $1, &v, sizeof(v));
261 %define %swigtype_ptr_out(how)
262 %typemap(out) SWIGTYPE * {
263 /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
264 CAML_VALUE *fromval = caml_named_value("create_$ntype_from_ptr");
266 $result = callback(*fromval,caml_val_ptr((void *)$1,$1_descriptor));
268 $result = caml_val_ptr ((void *)$1,$1_descriptor);
271 %typemap(how) SWIGTYPE (CLASS::*) {
272 /* %typemap(how) SWIGTYPE *, SWIGTYPE (CLASS::*) */
274 memcpy(&v,& $1, sizeof(void *));
275 $result = caml_val_ptr (v,$1_descriptor);
279 %swigtype_ptr_in(in);
280 %swigtype_ptr_in(varin);
281 %swigtype_ptr_in(directorout);
282 %swigtype_ptr_out(out);
283 %swigtype_ptr_out(varout);
284 %swigtype_ptr_out(directorin);
286 %define %swigtype_array_fail(how,msg)
287 %typemap(how) SWIGTYPE [] {
292 %swigtype_array_fail(in,"Array arguments for arbitrary types need a typemap");
293 %swigtype_array_fail(varin,"Assignment to global arrays for arbitrary types need a typemap");
294 %swigtype_array_fail(out,"Array arguments for arbitrary types need a typemap");
295 %swigtype_array_fail(varout,"Array variables need a typemap");
296 %swigtype_array_fail(directorin,"Array results with arbitrary types need a typemap");
297 %swigtype_array_fail(directorout,"Array arguments with arbitrary types need a typemap");
302 %define %swig_enum_in(how)
303 %typemap(how) enum SWIGTYPE {
304 $1 = ($type)caml_long_val_full($input,"$type_marker");
308 %define %swig_enum_out(how)
309 %typemap(how) enum SWIGTYPE {
310 $result = callback2(*caml_named_value(SWIG_MODULE "_int_to_enum"),*caml_named_value("$type_marker"),Val_int((int)$1));
316 %swig_enum_in(directorout)
318 %swig_enum_out(varout)
319 %swig_enum_out(directorin)