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