perl5.002beta3
[perl.git] / lib / ExtUtils / typemap
1 # $Header$ 
2 # basic C types
3 int                     T_IV
4 unsigned                T_IV
5 unsigned int            T_IV
6 long                    T_IV
7 unsigned long           T_IV
8 short                   T_IV
9 unsigned short          T_IV
10 char                    T_CHAR
11 unsigned char           T_U_CHAR
12 char *                  T_PV
13 unsigned char *         T_PV
14 caddr_t                 T_PV
15 wchar_t *               T_PV
16 wchar_t                 T_IV
17 bool_t                  T_IV
18 size_t                  T_IV
19 ssize_t                 T_IV
20 time_t                  T_NV
21 unsigned long *         T_OPAQUEPTR
22 char **                 T_PACKED
23 void *                  T_PTR
24 Time_t *                T_PV
25 SV *                    T_SV
26 SVREF                   T_SVREF
27 AV *                    T_AVREF
28 HV *                    T_HVREF
29 CV *                    T_CVREF
30
31 IV                      T_IV
32 I32                     T_IV
33 I16                     T_IV
34 I8                      T_IV
35 U32                     T_U_LONG
36 U16                     T_U_SHORT
37 U8                      T_IV
38 Result                  T_U_CHAR
39 Boolean                 T_IV
40 double                  T_DOUBLE
41 SysRet                  T_SYSRET
42 SysRetLong              T_SYSRET
43 FILE *                  T_IN
44 FileHandle              T_PTROBJ
45 InputStream             T_IN
46 InOutStream             T_INOUT
47 OutputStream            T_OUT
48
49 #############################################################################
50 INPUT
51 T_SV
52         $var = $arg
53 T_SVREF
54         if (sv_isa($arg, \"${ntype}\"))
55             $var = (SV*)SvRV($arg);
56         else
57             croak(\"$var is not of type ${ntype}\")
58 T_AVREF
59         if (sv_isa($arg, \"${ntype}\"))
60             $var = (AV*)SvRV($arg);
61         else
62             croak(\"$var is not of type ${ntype}\")
63 T_HVREF
64         if (sv_isa($arg, \"${ntype}\"))
65             $var = (HV*)SvRV($arg);
66         else
67             croak(\"$var is not of type ${ntype}\")
68 T_CVREF
69         if (sv_isa($arg, \"${ntype}\"))
70             $var = (CV*)SvRV($arg);
71         else
72             croak(\"$var is not of type ${ntype}\")
73 T_SYSRET
74         $var NOT IMPLEMENTED
75 T_IV
76         $var = ($type)SvIV($arg)
77 T_INT
78         $var = (int)SvIV($arg)
79 T_ENUM
80         $var = ($type)SvIV($arg)
81 T_U_INT
82         $var = (unsigned int)SvIV($arg)
83 T_SHORT
84         $var = (short)SvIV($arg)
85 T_U_SHORT
86         $var = (unsigned short)SvIV($arg)
87 T_LONG
88         $var = (long)SvIV($arg)
89 T_U_LONG
90         $var = (unsigned long)SvIV($arg)
91 T_CHAR
92         $var = (char)*SvPV($arg,na)
93 T_U_CHAR
94         $var = (unsigned char)SvIV($arg)
95 T_FLOAT
96         $var = (float)SvNV($arg)
97 T_NV
98         $var = ($type)SvNV($arg)
99 T_DOUBLE
100         $var = (double)SvNV($arg)
101 T_PV
102         $var = ($type)SvPV($arg,na)
103 T_PTR
104         $var = ($type)SvIV($arg)
105 T_PTRREF
106         if (SvROK($arg)) {
107             IV tmp = SvIV((SV*)SvRV($arg));
108             $var = ($type) tmp;
109         }
110         else
111             croak(\"$var is not a reference\")
112 T_REF_IV_REF
113         if (sv_isa($arg, \"${type}\")) {
114             IV tmp = SvIV((SV*)SvRV($arg));
115             $var = *($type *) tmp;
116         }
117         else
118             croak(\"$var is not of type ${ntype}\")
119 T_REF_IV_PTR
120         if (sv_isa($arg, \"${type}\")) {
121             IV tmp = SvIV((SV*)SvRV($arg));
122             $var = ($type) tmp;
123         }
124         else
125             croak(\"$var is not of type ${ntype}\")
126 T_PTROBJ
127         if (sv_isa($arg, \"${ntype}\")) {
128             IV tmp = SvIV((SV*)SvRV($arg));
129             $var = ($type) tmp;
130         }
131         else
132             croak(\"$var is not of type ${ntype}\")
133 T_PTRDESC
134         if (sv_isa($arg, \"${ntype}\")) {
135             IV tmp = SvIV((SV*)SvRV($arg));
136             ${type}_desc = (\U${type}_DESC\E*) tmp; 
137             $var = ${type}_desc->ptr;
138         }
139         else
140             croak(\"$var is not of type ${ntype}\")
141 T_REFREF
142         if (SvROK($arg)) {
143             IV tmp = SvIV((SV*)SvRV($arg));
144             $var = *($type) tmp;
145         }
146         else
147             croak(\"$var is not a reference\")
148 T_REFOBJ
149         if (sv_isa($arg, \"${ntype}\")) {
150             IV tmp = SvIV((SV*)SvRV($arg));
151             $var = *($type) tmp;
152         }
153         else
154             croak(\"$var is not of type ${ntype}\")
155 T_OPAQUE
156         $var NOT IMPLEMENTED
157 T_OPAQUEPTR
158         $var = ($type)SvPV($arg,na)
159 T_PACKED
160         $var = XS_unpack_$ntype($arg)
161 T_PACKEDARRAY
162         $var = XS_unpack_$ntype($arg)
163 T_CALLBACK
164         $var = make_perl_cb_$type($arg)
165 T_ARRAY
166         $var = $ntype(items -= $argoff);
167         U32 ix_$var = $argoff;
168         while (items--) {
169             DO_ARRAY_ELEM;
170         }
171 T_IN
172         $var = IoIFP(sv_2io($arg))
173 T_INOUT
174         $var = IoIFP(sv_2io($arg))
175 T_OUT
176         $var = IoOFP(sv_2io($arg))
177 #############################################################################
178 OUTPUT
179 T_SV
180         $arg = $var;
181 T_SVREF
182         $arg = newRV((SV*)$var);
183 T_AVREF
184         $arg = newRV((SV*)$var);
185 T_HVREF
186         $arg = newRV((SV*)$var);
187 T_CVREF
188         $arg = newRV((SV*)$var);
189 T_IV
190         sv_setiv($arg, (IV)$var);
191 T_INT
192         sv_setiv($arg, (IV)$var);
193 T_SYSRET
194         if ($var != -1) {
195             if ($var == 0)
196                 sv_setpvn($arg, "0 but true", 10);
197             else
198                 sv_setiv($arg, (IV)$var);
199         }
200 T_ENUM
201         sv_setiv($arg, (IV)$var);
202 T_U_INT
203         sv_setiv($arg, (IV)$var);
204 T_SHORT
205         sv_setiv($arg, (IV)$var);
206 T_U_SHORT
207         sv_setiv($arg, (IV)$var);
208 T_LONG
209         sv_setiv($arg, (IV)$var);
210 T_U_LONG
211         sv_setiv($arg, (IV)$var);
212 T_CHAR
213         sv_setpvn($arg, (char *)&$var, 1);
214 T_U_CHAR
215         sv_setiv($arg, (IV)$var);
216 T_FLOAT
217         sv_setnv($arg, (double)$var);
218 T_NV
219         sv_setnv($arg, (double)$var);
220 T_DOUBLE
221         sv_setnv($arg, (double)$var);
222 T_PV
223         sv_setpv((SV*)$arg, $var);
224 T_PTR
225         sv_setiv($arg, (IV)$var);
226 T_PTRREF
227         sv_setref_pv($arg, Nullch, (void*)$var);
228 T_REF_IV_REF
229         sv_setref_pv($arg, \"${ntype}\", (void*)new $ntype($var));
230 T_REF_IV_PTR
231         sv_setref_pv($arg, \"${ntype}\", (void*)$var);
232 T_PTROBJ
233         sv_setref_pv($arg, \"${ntype}\", (void*)$var);
234 T_PTRDESC
235         sv_setref_pv($arg, \"${ntype}\", (void*)new\U${type}_DESC\E($var));
236 T_REFREF
237         sv_setrefref($arg, \"${ntype}\", XS_service_$ntype,
238                     ($var ? (void*)new $ntype($var) : 0));
239 T_REFOBJ
240         NOT IMPLEMENTED
241 T_OPAQUE
242         sv_setpvn($arg, (char *)&$var, sizeof($var));
243 T_OPAQUEPTR
244         sv_setpvn($arg, (char *)$var, sizeof(*$var)), XFree((char *)$var);
245 T_PACKED
246         XS_pack_$ntype($arg, $var);
247 T_PACKEDARRAY
248         XS_pack_$ntype($arg, $var, count_$ntype);
249 T_DATAUNIT      
250         sv_setpvn($arg, $var.chp(), $var.size());
251 T_CALLBACK
252         sv_setpvn($arg, $var.context.value().chp(),
253                 $var.context.value().size());
254 T_ARRAY
255         ST_EXTEND($var.size);
256         for (U32 ix_$var = 0; ix_$var < $var.size; ix_$var++) {
257                 ST(ix_$var) = sv_newmortal();
258         DO_ARRAY_ELEM
259         }
260         sp += $var.size - 1;
261 T_IN
262         {
263             GV *gv = newGVgen("$Package");
264             if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) )
265                 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
266             else
267                 $arg = &sv_undef;
268         }
269 T_INOUT
270         {
271             GV *gv = newGVgen("$Package");
272             if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) )
273                 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
274             else
275                 $arg = &sv_undef;
276         }
277 T_OUT
278         {
279             GV *gv = newGVgen("$Package");
280             if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) )
281                 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
282             else
283                 $arg = &sv_undef;
284         }