This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
stop T_IN/OUT/INOUT/STDIO typemaps leaking
[perl5.git] / lib / ExtUtils / typemap
CommitLineData
93a17b20 1# basic C types
85e6fe83 2int T_IV
3aa35033
GS
3unsigned T_UV
4unsigned int T_UV
a0d0e21e 5long T_IV
3aa35033 6unsigned long T_UV
85e6fe83 7short T_IV
3aa35033 8unsigned short T_UV
93a17b20 9char T_CHAR
85e6fe83 10unsigned char T_U_CHAR
a0d0e21e
LW
11char * T_PV
12unsigned char * T_PV
e6d4bf43 13const char * T_PV
a0d0e21e
LW
14caddr_t T_PV
15wchar_t * T_PV
16wchar_t T_IV
d2b7433c 17# bool_t is defined in <rpc/rpc.h>
a0d0e21e 18bool_t T_IV
12734836 19size_t T_UV
a0d0e21e
LW
20ssize_t T_IV
21time_t T_NV
93a17b20 22unsigned long * T_OPAQUEPTR
5abff6f9 23char ** T_PACKEDARRAY
93a17b20 24void * T_PTR
a0d0e21e 25Time_t * T_PV
2304df62 26SV * T_SV
b64f48ff
SM
27
28# These are the backwards-compatibility AV*/HV* typemaps that
29# do not decrement refcounts. Locally override with
1d2615b4
SM
30# "AV* T_AVREF_REFCOUNT_FIXED", "HV* T_HVREF_REFCOUNT_FIXED",
31# "CV* T_CVREF_REFCOUNT_FIXED", "SVREF T_SVREF_REFCOUNT_FIXED",
32# to get the fixed versions.
33SVREF T_SVREF
34CV * T_CVREF
a0d0e21e
LW
35AV * T_AVREF
36HV * T_HVREF
93a17b20 37
a0d0e21e 38IV T_IV
0ca04487 39UV T_UV
f8c11764 40NV T_NV
85e6fe83
LW
41I32 T_IV
42I16 T_IV
43I8 T_IV
12734836 44STRLEN T_UV
93a17b20
LW
45U32 T_U_LONG
46U16 T_U_SHORT
3aa35033 47U8 T_UV
93a17b20 48Result T_U_CHAR
f8c11764
TJ
49Boolean T_BOOL
50float T_FLOAT
93a17b20 51double T_DOUBLE
2304df62 52SysRet T_SYSRET
a0d0e21e 53SysRetLong T_SYSRET
f7e7eb72
NIS
54FILE * T_STDIO
55PerlIO * T_INOUT
a0d0e21e
LW
56FileHandle T_PTROBJ
57InputStream T_IN
58InOutStream T_INOUT
59OutputStream T_OUT
1cc23d7f 60bool T_BOOL
93a17b20 61
8990e307
LW
62#############################################################################
63INPUT
2304df62 64T_SV
a0d0e21e
LW
65 $var = $arg
66T_SVREF
88b5a879 67 STMT_START {
68 SV* const xsub_tmp_sv = $arg;
69 SvGETMAGIC(xsub_tmp_sv);
70 if (SvROK(xsub_tmp_sv)){
71 $var = SvRV(xsub_tmp_sv);
72 }
73 else{
8fe523b4 74 Perl_croak_nocontext(\"%s: %s is not a reference\",
88b5a879 75 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
76 \"$var\");
77 }
78 } STMT_END
1d2615b4
SM
79T_SVREF_REFCOUNT_FIXED
80 STMT_START {
81 SV* const xsub_tmp_sv = $arg;
82 SvGETMAGIC(xsub_tmp_sv);
83 if (SvROK(xsub_tmp_sv)){
84 $var = SvRV(xsub_tmp_sv);
85 }
86 else{
8fe523b4 87 Perl_croak_nocontext(\"%s: %s is not a reference\",
1d2615b4
SM
88 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
89 \"$var\");
90 }
91 } STMT_END
a0d0e21e 92T_AVREF
88b5a879 93 STMT_START {
94 SV* const xsub_tmp_sv = $arg;
95 SvGETMAGIC(xsub_tmp_sv);
96 if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVAV){
97 $var = (AV*)SvRV(xsub_tmp_sv);
98 }
99 else{
8fe523b4 100 Perl_croak_nocontext(\"%s: %s is not an ARRAY reference\",
88b5a879 101 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
102 \"$var\");
103 }
104 } STMT_END
b64f48ff
SM
105T_AVREF_REFCOUNT_FIXED
106 STMT_START {
107 SV* const xsub_tmp_sv = $arg;
108 SvGETMAGIC(xsub_tmp_sv);
109 if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVAV){
110 $var = (AV*)SvRV(xsub_tmp_sv);
111 }
112 else{
8fe523b4 113 Perl_croak_nocontext(\"%s: %s is not an ARRAY reference\",
b64f48ff
SM
114 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
115 \"$var\");
116 }
117 } STMT_END
a0d0e21e 118T_HVREF
88b5a879 119 STMT_START {
120 SV* const xsub_tmp_sv = $arg;
121 SvGETMAGIC(xsub_tmp_sv);
122 if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVHV){
dd698a05 123 $var = (HV*)SvRV(xsub_tmp_sv);
88b5a879 124 }
125 else{
8fe523b4 126 Perl_croak_nocontext(\"%s: %s is not a HASH reference\",
88b5a879 127 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
128 \"$var\");
129 }
130 } STMT_END
b64f48ff
SM
131T_HVREF_REFCOUNT_FIXED
132 STMT_START {
133 SV* const xsub_tmp_sv = $arg;
134 SvGETMAGIC(xsub_tmp_sv);
135 if (SvROK(xsub_tmp_sv) && SvTYPE(SvRV(xsub_tmp_sv)) == SVt_PVHV){
136 $var = (HV*)SvRV(xsub_tmp_sv);
137 }
138 else{
8fe523b4 139 Perl_croak_nocontext(\"%s: %s is not a HASH reference\",
b64f48ff
SM
140 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
141 \"$var\");
142 }
143 } STMT_END
a0d0e21e 144T_CVREF
88b5a879 145 STMT_START {
8465c88d
SM
146 HV *st;
147 GV *gvp;
148 SV * const xsub_tmp_sv = $arg;
88b5a879 149 SvGETMAGIC(xsub_tmp_sv);
8465c88d
SM
150 $var = sv_2cv(xsub_tmp_sv, &st, &gvp, 0);
151 if (!$var) {
8fe523b4 152 Perl_croak_nocontext(\"%s: %s is not a CODE reference\",
88b5a879 153 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
154 \"$var\");
155 }
156 } STMT_END
1d2615b4
SM
157T_CVREF_REFCOUNT_FIXED
158 STMT_START {
8465c88d
SM
159 HV *st;
160 GV *gvp;
161 SV * const xsub_tmp_sv = $arg;
1d2615b4 162 SvGETMAGIC(xsub_tmp_sv);
8465c88d
SM
163 $var = sv_2cv(xsub_tmp_sv, &st, &gvp, 0);
164 if (!$var) {
8fe523b4 165 Perl_croak_nocontext(\"%s: %s is not a CODE reference\",
1d2615b4
SM
166 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
167 \"$var\");
168 }
169 } STMT_END
2304df62
AD
170T_SYSRET
171 $var NOT IMPLEMENTED
3aa35033
GS
172T_UV
173 $var = ($type)SvUV($arg)
85e6fe83
LW
174T_IV
175 $var = ($type)SvIV($arg)
8990e307
LW
176T_INT
177 $var = (int)SvIV($arg)
178T_ENUM
179 $var = ($type)SvIV($arg)
1cc23d7f 180T_BOOL
f8c11764 181 $var = (bool)SvTRUE($arg)
8990e307 182T_U_INT
3aa35033 183 $var = (unsigned int)SvUV($arg)
8990e307
LW
184T_SHORT
185 $var = (short)SvIV($arg)
186T_U_SHORT
3aa35033 187 $var = (unsigned short)SvUV($arg)
8990e307
LW
188T_LONG
189 $var = (long)SvIV($arg)
190T_U_LONG
3aa35033 191 $var = (unsigned long)SvUV($arg)
8990e307 192T_CHAR
3521e4ee 193 $var = (char)*SvPV_nolen($arg)
8990e307 194T_U_CHAR
3aa35033 195 $var = (unsigned char)SvUV($arg)
8990e307
LW
196T_FLOAT
197 $var = (float)SvNV($arg)
85e6fe83
LW
198T_NV
199 $var = ($type)SvNV($arg)
8990e307 200T_DOUBLE
85e6fe83 201 $var = (double)SvNV($arg)
a0d0e21e 202T_PV
3521e4ee 203 $var = ($type)SvPV_nolen($arg)
8990e307 204T_PTR
56431972 205 $var = INT2PTR($type,SvIV($arg))
8990e307 206T_PTRREF
85e6fe83 207 if (SvROK($arg)) {
a0d0e21e 208 IV tmp = SvIV((SV*)SvRV($arg));
56431972 209 $var = INT2PTR($type,tmp);
85e6fe83 210 }
8990e307 211 else
8fe523b4 212 Perl_croak_nocontext(\"%s: %s is not a reference\",
52c93dd1
AT
213 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
214 \"$var\")
a0d0e21e 215T_REF_IV_REF
5abff6f9 216 if (sv_isa($arg, \"${ntype}\")) {
a0d0e21e 217 IV tmp = SvIV((SV*)SvRV($arg));
c725d115 218 $var = *INT2PTR($type *, tmp);
a0d0e21e
LW
219 }
220 else
8fe523b4 221 Perl_croak_nocontext(\"%s: %s is not of type %s\",
52c93dd1
AT
222 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
223 \"$var\", \"$ntype\")
a0d0e21e 224T_REF_IV_PTR
f8c11764 225 if (sv_isa($arg, \"${ntype}\")) {
a0d0e21e 226 IV tmp = SvIV((SV*)SvRV($arg));
c725d115 227 $var = INT2PTR($type, tmp);
a0d0e21e
LW
228 }
229 else
8fe523b4 230 Perl_croak_nocontext(\"%s: %s is not of type %s\",
52c93dd1
AT
231 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
232 \"$var\", \"$ntype\")
8990e307 233T_PTROBJ
dc1f0c20 234 if (SvROK($arg) && sv_derived_from($arg, \"${ntype}\")) {
a0d0e21e 235 IV tmp = SvIV((SV*)SvRV($arg));
56431972 236 $var = INT2PTR($type,tmp);
85e6fe83 237 }
8990e307 238 else
8fe523b4 239 Perl_croak_nocontext(\"%s: %s is not of type %s\",
52c93dd1
AT
240 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
241 \"$var\", \"$ntype\")
8990e307
LW
242T_PTRDESC
243 if (sv_isa($arg, \"${ntype}\")) {
a0d0e21e 244 IV tmp = SvIV((SV*)SvRV($arg));
f7e7eb72 245 ${type}_desc = (\U${type}_DESC\E*) tmp;
8990e307
LW
246 $var = ${type}_desc->ptr;
247 }
248 else
8fe523b4 249 Perl_croak_nocontext(\"%s: %s is not of type %s\",
52c93dd1
AT
250 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
251 \"$var\", \"$ntype\")
8990e307 252T_REFREF
85e6fe83 253 if (SvROK($arg)) {
a0d0e21e 254 IV tmp = SvIV((SV*)SvRV($arg));
56431972 255 $var = *INT2PTR($type,tmp);
85e6fe83 256 }
8990e307 257 else
8fe523b4 258 Perl_croak_nocontext(\"%s: %s is not a reference\",
52c93dd1
AT
259 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
260 \"$var\")
8990e307 261T_REFOBJ
85e6fe83 262 if (sv_isa($arg, \"${ntype}\")) {
a0d0e21e 263 IV tmp = SvIV((SV*)SvRV($arg));
56431972 264 $var = *INT2PTR($type,tmp);
85e6fe83 265 }
8990e307 266 else
8fe523b4 267 Perl_croak_nocontext(\"%s: %s is not of type %s\",
52c93dd1
AT
268 ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
269 \"$var\", \"$ntype\")
8990e307 270T_OPAQUE
3521e4ee 271 $var = *($type *)SvPV_nolen($arg)
8990e307 272T_OPAQUEPTR
3521e4ee 273 $var = ($type)SvPV_nolen($arg)
8990e307
LW
274T_PACKED
275 $var = XS_unpack_$ntype($arg)
276T_PACKEDARRAY
277 $var = XS_unpack_$ntype($arg)
8990e307 278T_ARRAY
8990e307 279 U32 ix_$var = $argoff;
f8c11764 280 $var = $ntype(items -= $argoff);
8990e307
LW
281 while (items--) {
282 DO_ARRAY_ELEM;
f8c11764 283 ix_$var++;
8990e307 284 }
f8c11764
TJ
285 /* this is the number of elements in the array */
286 ix_$var -= $argoff
f7e7eb72
NIS
287T_STDIO
288 $var = PerlIO_findFILE(IoIFP(sv_2io($arg)))
a0d0e21e
LW
289T_IN
290 $var = IoIFP(sv_2io($arg))
291T_INOUT
292 $var = IoIFP(sv_2io($arg))
293T_OUT
294 $var = IoOFP(sv_2io($arg))
8990e307
LW
295#############################################################################
296OUTPUT
2304df62
AD
297T_SV
298 $arg = $var;
a0d0e21e 299T_SVREF
2304df62 300 $arg = newRV((SV*)$var);
1d2615b4
SM
301T_SVREF_REFCOUNT_FIXED
302 $arg = newRV_noinc((SV*)$var);
a0d0e21e 303T_AVREF
2304df62 304 $arg = newRV((SV*)$var);
b64f48ff
SM
305T_AVREF_REFCOUNT_FIXED
306 $arg = newRV_noinc((SV*)$var);
a0d0e21e 307T_HVREF
2304df62 308 $arg = newRV((SV*)$var);
b64f48ff
SM
309T_HVREF_REFCOUNT_FIXED
310 $arg = newRV_noinc((SV*)$var);
a0d0e21e 311T_CVREF
2304df62 312 $arg = newRV((SV*)$var);
1d2615b4
SM
313T_CVREF_REFCOUNT_FIXED
314 $arg = newRV_noinc((SV*)$var);
85e6fe83 315T_IV
ef50df4b 316 sv_setiv($arg, (IV)$var);
3aa35033
GS
317T_UV
318 sv_setuv($arg, (UV)$var);
8990e307 319T_INT
ef50df4b 320 sv_setiv($arg, (IV)$var);
2304df62
AD
321T_SYSRET
322 if ($var != -1) {
323 if ($var == 0)
ef50df4b 324 sv_setpvn($arg, "0 but true", 10);
2304df62 325 else
ef50df4b 326 sv_setiv($arg, (IV)$var);
2304df62 327 }
8990e307 328T_ENUM
ef50df4b 329 sv_setiv($arg, (IV)$var);
1cc23d7f 330T_BOOL
9712754a 331 ${"$var" eq "RETVAL" ? \"$arg = boolSV($var);" : \"sv_setsv($arg, boolSV($var));"}
8990e307 332T_U_INT
3aa35033 333 sv_setuv($arg, (UV)$var);
8990e307 334T_SHORT
ef50df4b 335 sv_setiv($arg, (IV)$var);
8990e307 336T_U_SHORT
3aa35033 337 sv_setuv($arg, (UV)$var);
8990e307 338T_LONG
ef50df4b 339 sv_setiv($arg, (IV)$var);
8990e307 340T_U_LONG
3aa35033 341 sv_setuv($arg, (UV)$var);
8990e307 342T_CHAR
ef50df4b 343 sv_setpvn($arg, (char *)&$var, 1);
8990e307 344T_U_CHAR
3aa35033 345 sv_setuv($arg, (UV)$var);
8990e307 346T_FLOAT
ef50df4b 347 sv_setnv($arg, (double)$var);
85e6fe83 348T_NV
59f3815a 349 sv_setnv($arg, (NV)$var);
8990e307 350T_DOUBLE
ef50df4b 351 sv_setnv($arg, (double)$var);
a0d0e21e 352T_PV
ef50df4b 353 sv_setpv((SV*)$arg, $var);
8990e307 354T_PTR
46e87256 355 sv_setiv($arg, PTR2IV($var));
8990e307 356T_PTRREF
a0d0e21e
LW
357 sv_setref_pv($arg, Nullch, (void*)$var);
358T_REF_IV_REF
359 sv_setref_pv($arg, \"${ntype}\", (void*)new $ntype($var));
360T_REF_IV_PTR
361 sv_setref_pv($arg, \"${ntype}\", (void*)$var);
8990e307 362T_PTROBJ
a0d0e21e 363 sv_setref_pv($arg, \"${ntype}\", (void*)$var);
8990e307 364T_PTRDESC
a0d0e21e 365 sv_setref_pv($arg, \"${ntype}\", (void*)new\U${type}_DESC\E($var));
8990e307 366T_REFREF
f8c11764 367 NOT_IMPLEMENTED
8990e307
LW
368T_REFOBJ
369 NOT IMPLEMENTED
370T_OPAQUE
ef50df4b 371 sv_setpvn($arg, (char *)&$var, sizeof($var));
8990e307 372T_OPAQUEPTR
4bd3d083 373 sv_setpvn($arg, (char *)$var, sizeof(*$var));
8990e307
LW
374T_PACKED
375 XS_pack_$ntype($arg, $var);
376T_PACKEDARRAY
377 XS_pack_$ntype($arg, $var, count_$ntype);
8990e307 378T_ARRAY
f8c11764
TJ
379 {
380 U32 ix_$var;
381 EXTEND(SP,size_$var);
382 for (ix_$var = 0; ix_$var < size_$var; ix_$var++) {
8990e307
LW
383 ST(ix_$var) = sv_newmortal();
384 DO_ARRAY_ELEM
f8c11764
TJ
385 }
386 }
f7e7eb72
NIS
387T_STDIO
388 {
389 GV *gv = newGVgen("$Package");
390 PerlIO *fp = PerlIO_importFILE($var,0);
50e5165b
DM
391 if ( fp && do_open(gv, "+<&", 3, FALSE, 0, 0, fp) ) {
392 SV *rv = newRV_noinc((SV*)gv);
393 rv = sv_bless(rv, gv_stashpv("$Package",1));
394 sv_setsv($arg, rv);
395 SvREFCNT_dec_NN(rv);
396 }
f7e7eb72
NIS
397 else
398 $arg = &PL_sv_undef;
399 }
a0d0e21e
LW
400T_IN
401 {
402 GV *gv = newGVgen("$Package");
50e5165b
DM
403 if ( do_open(gv, "<&", 2, FALSE, 0, 0, $var) ) {
404 SV *rv = newRV_noinc((SV*)gv);
405 rv = sv_bless(rv, gv_stashpv("$Package",1));
406 sv_setsv($arg, rv);
407 SvREFCNT_dec_NN(rv);
408 }
a0d0e21e 409 else
6b88bc9c 410 $arg = &PL_sv_undef;
a0d0e21e
LW
411 }
412T_INOUT
413 {
414 GV *gv = newGVgen("$Package");
50e5165b
DM
415 if ( do_open(gv, "+<&", 3, FALSE, 0, 0, $var) ) {
416 SV *rv = newRV_noinc((SV*)gv);
417 rv = sv_bless(rv, gv_stashpv("$Package",1));
418 sv_setsv($arg, rv);
419 SvREFCNT_dec_NN(rv);
420 }
a0d0e21e 421 else
6b88bc9c 422 $arg = &PL_sv_undef;
a0d0e21e
LW
423 }
424T_OUT
425 {
426 GV *gv = newGVgen("$Package");
50e5165b
DM
427 if ( do_open(gv, "+>&", 3, FALSE, 0, 0, $var) ) {
428 SV *rv = newRV_noinc((SV*)gv);
429 rv = sv_bless(rv, gv_stashpv("$Package",1));
430 sv_setsv($arg, rv);
431 SvREFCNT_dec_NN(rv);
432 }
a0d0e21e 433 else
6b88bc9c 434 $arg = &PL_sv_undef;
a0d0e21e 435 }