This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move ExtUtils::ParseXS from cpan/ to dist/
[perl5.git] / dist / ExtUtils-ParseXS / t / typemap
CommitLineData
28892255
DG
1# basic C types
2int T_IV
3unsigned T_UV
4unsigned int T_UV
5long T_IV
6unsigned long T_UV
7short T_IV
8unsigned short T_UV
9char T_CHAR
10unsigned char T_U_CHAR
11char * T_PV
12unsigned char * T_PV
13const char * T_PV
14caddr_t T_PV
15wchar_t * T_PV
16wchar_t T_IV
17# bool_t is defined in <rpc/rpc.h>
18bool_t T_IV
19size_t T_UV
20ssize_t T_IV
21time_t T_NV
22unsigned long * T_OPAQUEPTR
23char ** T_PACKEDARRAY
24void * T_PTR
25Time_t * T_PV
26SV * T_SV
27SVREF T_SVREF
28AV * T_AVREF
29HV * T_HVREF
30CV * T_CVREF
31
32IV T_IV
33UV T_UV
34NV T_NV
35I32 T_IV
36I16 T_IV
37I8 T_IV
38STRLEN T_UV
39U32 T_U_LONG
40U16 T_U_SHORT
41U8 T_UV
42Result T_U_CHAR
43Boolean T_BOOL
44float T_FLOAT
45double T_DOUBLE
46SysRet T_SYSRET
47SysRetLong T_SYSRET
48FILE * T_STDIO
49PerlIO * T_INOUT
50FileHandle T_PTROBJ
51InputStream T_IN
52InOutStream T_INOUT
53OutputStream T_OUT
54bool T_BOOL
55
56#############################################################################
57INPUT
58T_SV
59 $var = $arg
60T_SVREF
61 if (SvROK($arg))
62 $var = (SV*)SvRV($arg);
63 else
64 Perl_croak(aTHX_ \"%s: %s is not a reference\",
65 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
66 \"$var\")
67T_AVREF
68 if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV)
69 $var = (AV*)SvRV($arg);
70 else
71 Perl_croak(aTHX_ \"%s: %s is not an array reference\",
72 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
73 \"$var\")
74T_HVREF
75 if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVHV)
76 $var = (HV*)SvRV($arg);
77 else
78 Perl_croak(aTHX_ \"%s: %s is not a hash reference\",
79 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
80 \"$var\")
81T_CVREF
82 if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVCV)
83 $var = (CV*)SvRV($arg);
84 else
85 Perl_croak(aTHX_ \"%s: %s is not a code reference\",
86 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
87 \"$var\")
88T_SYSRET
89 $var NOT IMPLEMENTED
90T_UV
91 $var = ($type)SvUV($arg)
92T_IV
93 $var = ($type)SvIV($arg)
94T_INT
95 $var = (int)SvIV($arg)
96T_ENUM
97 $var = ($type)SvIV($arg)
98T_BOOL
99 $var = (bool)SvTRUE($arg)
100T_U_INT
101 $var = (unsigned int)SvUV($arg)
102T_SHORT
103 $var = (short)SvIV($arg)
104T_U_SHORT
105 $var = (unsigned short)SvUV($arg)
106T_LONG
107 $var = (long)SvIV($arg)
108T_U_LONG
109 $var = (unsigned long)SvUV($arg)
110T_CHAR
111 $var = (char)*SvPV_nolen($arg)
112T_U_CHAR
113 $var = (unsigned char)SvUV($arg)
114T_FLOAT
115 $var = (float)SvNV($arg)
116T_NV
117 $var = ($type)SvNV($arg)
118T_DOUBLE
119 $var = (double)SvNV($arg)
120T_PV
121 $var = ($type)SvPV_nolen($arg)
122T_PTR
123 $var = INT2PTR($type,SvIV($arg))
124T_PTRREF
125 if (SvROK($arg)) {
126 IV tmp = SvIV((SV*)SvRV($arg));
127 $var = INT2PTR($type,tmp);
128 }
129 else
130 Perl_croak(aTHX_ \"%s: %s is not a reference\",
131 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
132 \"$var\")
133T_REF_IV_REF
134 if (sv_isa($arg, \"${ntype}\")) {
135 IV tmp = SvIV((SV*)SvRV($arg));
136 $var = *INT2PTR($type *, tmp);
137 }
138 else
139 Perl_croak(aTHX_ \"%s: %s is not of type %s\",
140 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
141 \"$var\", \"$ntype\")
142T_REF_IV_PTR
143 if (sv_isa($arg, \"${ntype}\")) {
144 IV tmp = SvIV((SV*)SvRV($arg));
145 $var = INT2PTR($type, tmp);
146 }
147 else
148 Perl_croak(aTHX_ \"%s: %s is not of type %s\",
149 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
150 \"$var\", \"$ntype\")
151T_PTROBJ
152 if (sv_derived_from($arg, \"${ntype}\")) {
153 IV tmp = SvIV((SV*)SvRV($arg));
154 $var = INT2PTR($type,tmp);
155 }
156 else
157 Perl_croak(aTHX_ \"%s: %s is not of type %s\",
158 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
159 \"$var\", \"$ntype\")
160T_PTRDESC
161 if (sv_isa($arg, \"${ntype}\")) {
162 IV tmp = SvIV((SV*)SvRV($arg));
163 ${type}_desc = (\U${type}_DESC\E*) tmp;
164 $var = ${type}_desc->ptr;
165 }
166 else
167 Perl_croak(aTHX_ \"%s: %s is not of type %s\",
168 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
169 \"$var\", \"$ntype\")
170T_REFREF
171 if (SvROK($arg)) {
172 IV tmp = SvIV((SV*)SvRV($arg));
173 $var = *INT2PTR($type,tmp);
174 }
175 else
176 Perl_croak(aTHX_ \"%s: %s is not a reference\",
177 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
178 \"$var\")
179T_REFOBJ
180 if (sv_isa($arg, \"${ntype}\")) {
181 IV tmp = SvIV((SV*)SvRV($arg));
182 $var = *INT2PTR($type,tmp);
183 }
184 else
185 Perl_croak(aTHX_ \"%s: %s is not of type %s\",
186 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
187 \"$var\", \"$ntype\")
188T_OPAQUE
189 $var = *($type *)SvPV_nolen($arg)
190T_OPAQUEPTR
191 $var = ($type)SvPV_nolen($arg)
192T_PACKED
193 $var = XS_unpack_$ntype($arg)
194T_PACKEDARRAY
195 $var = XS_unpack_$ntype($arg)
196T_CALLBACK
197 $var = make_perl_cb_$type($arg)
198T_ARRAY
199 U32 ix_$var = $argoff;
200 $var = $ntype(items -= $argoff);
201 while (items--) {
202 DO_ARRAY_ELEM;
203 ix_$var++;
204 }
205 /* this is the number of elements in the array */
206 ix_$var -= $argoff
207T_STDIO
208 $var = PerlIO_findFILE(IoIFP(sv_2io($arg)))
209T_IN
210 $var = IoIFP(sv_2io($arg))
211T_INOUT
212 $var = IoIFP(sv_2io($arg))
213T_OUT
214 $var = IoOFP(sv_2io($arg))
215#############################################################################
216OUTPUT
217T_SV
218 $arg = $var;
219T_SVREF
220 $arg = newRV((SV*)$var);
221T_AVREF
222 $arg = newRV((SV*)$var);
223T_HVREF
224 $arg = newRV((SV*)$var);
225T_CVREF
226 $arg = newRV((SV*)$var);
227T_IV
228 sv_setiv($arg, (IV)$var);
229T_UV
230 sv_setuv($arg, (UV)$var);
231T_INT
232 sv_setiv($arg, (IV)$var);
233T_SYSRET
234 if ($var != -1) {
235 if ($var == 0)
236 sv_setpvn($arg, "0 but true", 10);
237 else
238 sv_setiv($arg, (IV)$var);
239 }
240T_ENUM
241 sv_setiv($arg, (IV)$var);
242T_BOOL
243 $arg = boolSV($var);
244T_U_INT
245 sv_setuv($arg, (UV)$var);
246T_SHORT
247 sv_setiv($arg, (IV)$var);
248T_U_SHORT
249 sv_setuv($arg, (UV)$var);
250T_LONG
251 sv_setiv($arg, (IV)$var);
252T_U_LONG
253 sv_setuv($arg, (UV)$var);
254T_CHAR
255 sv_setpvn($arg, (char *)&$var, 1);
256T_U_CHAR
257 sv_setuv($arg, (UV)$var);
258T_FLOAT
259 sv_setnv($arg, (double)$var);
260T_NV
261 sv_setnv($arg, (NV)$var);
262T_DOUBLE
263 sv_setnv($arg, (double)$var);
264T_PV
265 sv_setpv((SV*)$arg, $var);
266T_PTR
267 sv_setiv($arg, PTR2IV($var));
268T_PTRREF
269 sv_setref_pv($arg, Nullch, (void*)$var);
270T_REF_IV_REF
271 sv_setref_pv($arg, \"${ntype}\", (void*)new $ntype($var));
272T_REF_IV_PTR
273 sv_setref_pv($arg, \"${ntype}\", (void*)$var);
274T_PTROBJ
275 sv_setref_pv($arg, \"${ntype}\", (void*)$var);
276T_PTRDESC
277 sv_setref_pv($arg, \"${ntype}\", (void*)new\U${type}_DESC\E($var));
278T_REFREF
279 NOT_IMPLEMENTED
280T_REFOBJ
281 NOT IMPLEMENTED
282T_OPAQUE
283 sv_setpvn($arg, (char *)&$var, sizeof($var));
284T_OPAQUEPTR
285 sv_setpvn($arg, (char *)$var, sizeof(*$var));
286T_PACKED
287 XS_pack_$ntype($arg, $var);
288T_PACKEDARRAY
289 XS_pack_$ntype($arg, $var, count_$ntype);
290T_DATAUNIT
291 sv_setpvn($arg, $var.chp(), $var.size());
292T_CALLBACK
293 sv_setpvn($arg, $var.context.value().chp(),
294 $var.context.value().size());
295T_ARRAY
296 {
297 U32 ix_$var;
298 EXTEND(SP,size_$var);
299 for (ix_$var = 0; ix_$var < size_$var; ix_$var++) {
300 ST(ix_$var) = sv_newmortal();
301 DO_ARRAY_ELEM
302 }
303 }
304T_STDIO
305 {
306 GV *gv = newGVgen("$Package");
307 PerlIO *fp = PerlIO_importFILE($var,0);
308 if ( fp && do_open(gv, "+<&", 3, FALSE, 0, 0, fp) )
309 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
310 else
311 $arg = &PL_sv_undef;
312 }
313T_IN
314 {
315 GV *gv = newGVgen("$Package");
316 if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) )
317 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
318 else
319 $arg = &PL_sv_undef;
320 }
321T_INOUT
322 {
323 GV *gv = newGVgen("$Package");
324 if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) )
325 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
326 else
327 $arg = &PL_sv_undef;
328 }
329T_OUT
330 {
331 GV *gv = newGVgen("$Package");
332 if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) )
333 sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1)));
334 else
335 $arg = &PL_sv_undef;
336 }