3 * Copyright (C) 2005, 2006, 2007, 2007, by Larry Wall and others
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Anything that Hobbits had no immediate use for, but were unwilling to
12 * throw away, they called a mathom. Their dwellings were apt to become
13 * rather crowded with mathoms, and many of the presents that passed from
14 * hand to hand were of that sort."
20 * This file contains mathoms, various binary artifacts from previous
21 * versions of Perl. For binary or source compatibility reasons, though,
22 * we cannot completely remove them from the core code.
29 #define PERL_IN_MATHOMS_C
32 PERL_CALLCONV OP * Perl_ref(pTHX_ OP *o, I32 type);
33 PERL_CALLCONV void Perl_sv_unref(pTHX_ SV *sv);
34 PERL_CALLCONV void Perl_sv_taint(pTHX_ SV *sv);
35 PERL_CALLCONV IV Perl_sv_2iv(pTHX_ register SV *sv);
36 PERL_CALLCONV UV Perl_sv_2uv(pTHX_ register SV *sv);
37 PERL_CALLCONV char * Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp);
38 PERL_CALLCONV char * Perl_sv_2pv_nolen(pTHX_ register SV *sv);
39 PERL_CALLCONV char * Perl_sv_2pvbyte_nolen(pTHX_ register SV *sv);
40 PERL_CALLCONV char * Perl_sv_2pvutf8_nolen(pTHX_ register SV *sv);
41 PERL_CALLCONV void Perl_sv_force_normal(pTHX_ register SV *sv);
42 PERL_CALLCONV void Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr);
43 PERL_CALLCONV void Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen);
44 PERL_CALLCONV void Perl_sv_catpvn_mg(pTHX_ register SV *sv, register const char *ptr, register STRLEN len);
45 PERL_CALLCONV void Perl_sv_catsv(pTHX_ SV *dstr, register SV *sstr);
46 PERL_CALLCONV void Perl_sv_catsv_mg(pTHX_ SV *dsv, register SV *ssv);
47 PERL_CALLCONV char * Perl_sv_pv(pTHX_ SV *sv);
48 PERL_CALLCONV char * Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp);
49 PERL_CALLCONV char * Perl_sv_pvbyte(pTHX_ SV *sv);
50 PERL_CALLCONV char * Perl_sv_pvutf8(pTHX_ SV *sv);
51 PERL_CALLCONV STRLEN Perl_sv_utf8_upgrade(pTHX_ register SV *sv);
52 PERL_CALLCONV NV Perl_huge(void);
53 PERL_CALLCONV void Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix);
54 PERL_CALLCONV void Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix);
55 PERL_CALLCONV GV * Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name);
56 PERL_CALLCONV HE * Perl_hv_iternext(pTHX_ HV *hv);
57 PERL_CALLCONV void Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how);
58 PERL_CALLCONV bool Perl_do_open(pTHX_ GV *gv, register const char *name, I32 len, int as_raw, int rawmode, int rawperm, PerlIO *supplied_fp);
59 PERL_CALLCONV bool Perl_do_aexec(pTHX_ SV *really, register SV **mark, register SV **sp);
60 PERL_CALLCONV bool Perl_do_exec(pTHX_ const char *cmd);
61 PERL_CALLCONV U8 * Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv);
62 PERL_CALLCONV bool Perl_is_utf8_string_loc(pTHX_ const U8 *s, STRLEN len, const U8 **ep);
63 PERL_CALLCONV void Perl_sv_nolocking(pTHX_ SV *sv);
64 PERL_CALLCONV void Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len);
65 PERL_CALLCONV void Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len);
66 PERL_CALLCONV int Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...);
67 PERL_CALLCONV int Perl_printf_nocontext(const char *format, ...);
68 PERL_CALLCONV int Perl_magic_setglob(pTHX_ SV* sv, MAGIC* mg);
69 PERL_CALLCONV AV * Perl_newAV(pTHX);
70 PERL_CALLCONV HV * Perl_newHV(pTHX);
72 /* ref() is now a macro using Perl_doref;
73 * this version provided for binary compatibility only.
76 Perl_ref(pTHX_ OP *o, I32 type)
78 return doref(o, type, TRUE);
84 Unsets the RV status of the SV, and decrements the reference count of
85 whatever was being referenced by the RV. This can almost be thought of
86 as a reversal of C<newSVrv>. This is C<sv_unref_flags> with the C<flag>
87 being zero. See C<SvROK_off>.
93 Perl_sv_unref(pTHX_ SV *sv)
95 sv_unref_flags(sv, 0);
101 Taint an SV. Use C<SvTAINTED_on> instead.
106 Perl_sv_taint(pTHX_ SV *sv)
108 sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0);
111 /* sv_2iv() is now a macro using Perl_sv_2iv_flags();
112 * this function provided for binary compatibility only
116 Perl_sv_2iv(pTHX_ register SV *sv)
118 return sv_2iv_flags(sv, SV_GMAGIC);
121 /* sv_2uv() is now a macro using Perl_sv_2uv_flags();
122 * this function provided for binary compatibility only
126 Perl_sv_2uv(pTHX_ register SV *sv)
128 return sv_2uv_flags(sv, SV_GMAGIC);
131 /* sv_2pv() is now a macro using Perl_sv_2pv_flags();
132 * this function provided for binary compatibility only
136 Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp)
138 return sv_2pv_flags(sv, lp, SV_GMAGIC);
142 =for apidoc sv_2pv_nolen
144 Like C<sv_2pv()>, but doesn't return the length too. You should usually
145 use the macro wrapper C<SvPV_nolen(sv)> instead.
150 Perl_sv_2pv_nolen(pTHX_ register SV *sv)
152 return sv_2pv(sv, NULL);
156 =for apidoc sv_2pvbyte_nolen
158 Return a pointer to the byte-encoded representation of the SV.
159 May cause the SV to be downgraded from UTF-8 as a side-effect.
161 Usually accessed via the C<SvPVbyte_nolen> macro.
167 Perl_sv_2pvbyte_nolen(pTHX_ register SV *sv)
169 return sv_2pvbyte(sv, NULL);
173 =for apidoc sv_2pvutf8_nolen
175 Return a pointer to the UTF-8-encoded representation of the SV.
176 May cause the SV to be upgraded to UTF-8 as a side-effect.
178 Usually accessed via the C<SvPVutf8_nolen> macro.
184 Perl_sv_2pvutf8_nolen(pTHX_ register SV *sv)
186 return sv_2pvutf8(sv, NULL);
190 =for apidoc sv_force_normal
192 Undo various types of fakery on an SV: if the PV is a shared string, make
193 a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
194 an xpvmg. See also C<sv_force_normal_flags>.
200 Perl_sv_force_normal(pTHX_ register SV *sv)
202 sv_force_normal_flags(sv, 0);
205 /* sv_setsv() is now a macro using Perl_sv_setsv_flags();
206 * this function provided for binary compatibility only
210 Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr)
212 sv_setsv_flags(dstr, sstr, SV_GMAGIC);
215 /* sv_catpvn() is now a macro using Perl_sv_catpvn_flags();
216 * this function provided for binary compatibility only
220 Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
222 sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC);
226 =for apidoc sv_catpvn_mg
228 Like C<sv_catpvn>, but also handles 'set' magic.
234 Perl_sv_catpvn_mg(pTHX_ register SV *sv, register const char *ptr, register STRLEN len)
236 sv_catpvn_flags(sv,ptr,len,SV_GMAGIC|SV_SMAGIC);
239 /* sv_catsv() is now a macro using Perl_sv_catsv_flags();
240 * this function provided for binary compatibility only
244 Perl_sv_catsv(pTHX_ SV *dstr, register SV *sstr)
246 sv_catsv_flags(dstr, sstr, SV_GMAGIC);
250 =for apidoc sv_catsv_mg
252 Like C<sv_catsv>, but also handles 'set' magic.
258 Perl_sv_catsv_mg(pTHX_ SV *dsv, register SV *ssv)
260 sv_catsv_flags(dsv,ssv,SV_GMAGIC|SV_SMAGIC);
266 A private implementation of the C<SvIVx> macro for compilers which can't
267 cope with complex macro expressions. Always use the macro instead.
273 Perl_sv_iv(pTHX_ register SV *sv)
277 return (IV)SvUVX(sv);
286 A private implementation of the C<SvUVx> macro for compilers which can't
287 cope with complex macro expressions. Always use the macro instead.
293 Perl_sv_uv(pTHX_ register SV *sv)
298 return (UV)SvIVX(sv);
306 A private implementation of the C<SvNVx> macro for compilers which can't
307 cope with complex macro expressions. Always use the macro instead.
313 Perl_sv_nv(pTHX_ register SV *sv)
323 Use the C<SvPV_nolen> macro instead
327 A private implementation of the C<SvPV> macro for compilers which can't
328 cope with complex macro expressions. Always use the macro instead.
334 Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
340 return sv_2pv(sv, lp);
345 Perl_sv_pvn_nomg(pTHX_ register SV *sv, STRLEN *lp)
351 return sv_2pv_flags(sv, lp, 0);
354 /* sv_pv() is now a macro using SvPV_nolen();
355 * this function provided for binary compatibility only
359 Perl_sv_pv(pTHX_ SV *sv)
364 return sv_2pv(sv, NULL);
367 /* sv_pvn_force() is now a macro using Perl_sv_pvn_force_flags();
368 * this function provided for binary compatibility only
372 Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
374 return sv_pvn_force_flags(sv, lp, SV_GMAGIC);
377 /* sv_pvbyte () is now a macro using Perl_sv_2pv_flags();
378 * this function provided for binary compatibility only
382 Perl_sv_pvbyte(pTHX_ SV *sv)
384 sv_utf8_downgrade(sv, FALSE);
389 =for apidoc sv_pvbyte
391 Use C<SvPVbyte_nolen> instead.
393 =for apidoc sv_pvbyten
395 A private implementation of the C<SvPVbyte> macro for compilers
396 which can't cope with complex macro expressions. Always use the macro
403 Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
405 sv_utf8_downgrade(sv, FALSE);
406 return sv_pvn(sv,lp);
409 /* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
410 * this function provided for binary compatibility only
414 Perl_sv_pvutf8(pTHX_ SV *sv)
421 =for apidoc sv_pvutf8
423 Use the C<SvPVutf8_nolen> macro instead
425 =for apidoc sv_pvutf8n
427 A private implementation of the C<SvPVutf8> macro for compilers
428 which can't cope with complex macro expressions. Always use the macro
435 Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
438 return sv_pvn(sv,lp);
441 /* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
442 * this function provided for binary compatibility only
446 Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
448 return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
452 Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...)
456 va_start(arglist, format);
457 return PerlIO_vprintf(stream, format, arglist);
461 Perl_printf_nocontext(const char *format, ...)
465 va_start(arglist, format);
466 return PerlIO_vprintf(PerlIO_stdout(), format, arglist);
469 #if defined(HUGE_VAL) || (defined(USE_LONG_DOUBLE) && defined(HUGE_VALL))
471 * This hack is to force load of "huge" support from libm.a
472 * So it is in perl for (say) POSIX to use.
473 * Needed for SunOS with Sun's 'acc' for example.
478 # if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
486 /* compatibility with versions <= 5.003. */
488 Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
490 gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
493 /* compatibility with versions <= 5.003. */
495 Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
497 gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
501 Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
503 gv_fullname4(sv, gv, prefix, TRUE);
507 Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
509 gv_efullname4(sv, gv, prefix, TRUE);
513 =for apidoc gv_fetchmethod
515 See L<gv_fetchmethod_autoload>.
521 Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
523 return gv_fetchmethod_autoload(stash, name, TRUE);
527 Perl_hv_iternext(pTHX_ HV *hv)
529 return hv_iternext_flags(hv, 0);
533 Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how)
535 sv_magic((SV*)hv, (SV*)gv, how, NULL, 0);
539 Perl_av_fake(pTHX_ register I32 size, register SV **strp)
542 register AV * const av = (AV*)newSV_type(SVt_PVAV);
543 Newx(ary,size+1,SV*);
545 Copy(strp,ary,size,SV*);
548 AvFILLp(av) = size - 1;
549 AvMAX(av) = size - 1;
559 Perl_do_open(pTHX_ GV *gv, register const char *name, I32 len, int as_raw,
560 int rawmode, int rawperm, PerlIO *supplied_fp)
562 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
563 supplied_fp, (SV **) NULL, 0);
567 Perl_do_open9(pTHX_ GV *gv, register const char *name, I32 len, int
569 int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
572 PERL_UNUSED_ARG(num_svs);
573 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
574 supplied_fp, &svs, 1);
578 Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
580 /* The old body of this is now in non-LAYER part of perlio.c
581 * This is a stub for any XS code which might have been calling it.
583 const char *name = ":raw";
584 #ifdef PERLIO_USING_CRLF
585 if (!(mode & O_BINARY))
588 return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
593 Perl_do_aexec(pTHX_ SV *really, register SV **mark, register SV **sp)
595 return do_aexec5(really, mark, sp, 0, 0);
599 #ifdef PERL_DEFAULT_DO_EXEC3_IMPLEMENTATION
601 Perl_do_exec(pTHX_ const char *cmd)
603 return do_exec3(cmd,0,0);
607 /* Backwards compatibility. */
609 Perl_init_i18nl14n(pTHX_ int printwarn)
611 return init_i18nl10n(printwarn);
615 Perl_oopsCV(pTHX_ OP *o)
617 Perl_croak(aTHX_ "NOT IMPL LINE %d",__LINE__);
620 NORETURN_FUNCTION_END;
625 DIE(aTHX_ "NOT IMPL LINE %d",__LINE__);
630 DIE(aTHX_ "panic: mapstart"); /* uses grepstart */
633 /* These ops all have the same body as pp_null. */
658 /* Ops that are calls to do_kv. */
669 /* Ops that are simply calls to other ops. */
708 return pp_ssockopt();
713 return pp_getpeername();
723 return pp_ftrowned();
748 return pp_shmwrite();
763 return pp_ghostent();
768 return pp_ghostent();
783 return pp_gprotoent();
788 return pp_gprotoent();
793 return pp_gservent();
798 return pp_gservent();
843 return pp_ftrowned();
848 return pp_ftrowned();
853 return pp_ftrowned();
858 return pp_ftrowned();
863 return pp_ftrowned();
868 return pp_ftrowned();
873 return pp_ftrowned();
878 return pp_ftrowned();
883 return pp_ftrowned();
888 return pp_ftrowned();
943 return pp_shmwrite();
948 return pp_shmwrite();
958 return pp_shmwrite();
1043 return Perl_pp_rv2av(aTHX);
1047 Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv)
1049 return Perl_uvuni_to_utf8_flags(aTHX_ d, uv, 0);
1053 Perl_is_utf8_string_loc(pTHX_ const U8 *s, STRLEN len, const U8 **ep)
1055 return is_utf8_string_loclen(s, len, ep, 0);
1059 =for apidoc sv_nolocking
1061 Dummy routine which "locks" an SV when there is no locking module present.
1062 Exists to avoid test for a NULL function pointer and because it could
1063 potentially warn under some level of strict-ness.
1065 "Superseded" by sv_nosharing().
1071 Perl_sv_nolocking(pTHX_ SV *sv)
1073 PERL_UNUSED_CONTEXT;
1074 PERL_UNUSED_ARG(sv);
1079 =for apidoc sv_nounlocking
1081 Dummy routine which "unlocks" an SV when there is no locking module present.
1082 Exists to avoid test for a NULL function pointer and because it could
1083 potentially warn under some level of strict-ness.
1085 "Superseded" by sv_nosharing().
1091 Perl_sv_nounlocking(pTHX_ SV *sv)
1093 PERL_UNUSED_CONTEXT;
1094 PERL_UNUSED_ARG(sv);
1098 Perl_save_long(pTHX_ long int *longp)
1104 SSPUSHINT(SAVEt_LONG);
1108 Perl_save_iv(pTHX_ IV *ivp)
1114 SSPUSHINT(SAVEt_IV);
1118 Perl_save_nogv(pTHX_ GV *gv)
1123 SSPUSHINT(SAVEt_NSTAB);
1127 Perl_save_list(pTHX_ register SV **sarg, I32 maxsarg)
1132 for (i = 1; i <= maxsarg; i++) {
1133 register SV * const sv = newSV(0);
1134 sv_setsv(sv,sarg[i]);
1136 SSPUSHPTR(sarg[i]); /* remember the pointer */
1137 SSPUSHPTR(sv); /* remember the value */
1138 SSPUSHINT(SAVEt_ITEM);
1143 =for apidoc sv_usepvn_mg
1145 Like C<sv_usepvn>, but also handles 'set' magic.
1151 Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len)
1153 sv_usepvn_flags(sv,ptr,len, SV_SMAGIC);
1157 =for apidoc sv_usepvn
1159 Tells an SV to use C<ptr> to find its string value. Implemented by
1160 calling C<sv_usepvn_flags> with C<flags> of 0, hence does not handle 'set'
1161 magic. See C<sv_usepvn_flags>.
1167 Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len)
1169 sv_usepvn_flags(sv,ptr,len, 0);
1173 Perl_cv_ckproto(pTHX_ const CV *cv, const GV *gv, const char *p)
1175 cv_ckproto_len(cv, gv, p, p ? strlen(p) : 0);
1179 =for apidoc unpack_str
1181 The engine implementing unpack() Perl function. Note: parameters strbeg, new_s
1182 and ocnt are not used. This call should not be used, use unpackstring instead.
1187 Perl_unpack_str(pTHX_ const char *pat, const char *patend, const char *s,
1188 const char *strbeg, const char *strend, char **new_s, I32 ocnt,
1191 PERL_UNUSED_ARG(strbeg);
1192 PERL_UNUSED_ARG(new_s);
1193 PERL_UNUSED_ARG(ocnt);
1195 return unpackstring(pat, patend, s, strend, flags);
1199 =for apidoc pack_cat
1201 The engine implementing pack() Perl function. Note: parameters next_in_list and
1202 flags are not used. This call should not be used; use packlist instead.
1208 Perl_pack_cat(pTHX_ SV *cat, const char *pat, const char *patend, register SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
1210 PERL_UNUSED_ARG(next_in_list);
1211 PERL_UNUSED_ARG(flags);
1213 packlist(cat, pat, patend, beglist, endlist);
1217 Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, U32 hash)
1219 return (HE *)hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
1223 Perl_hv_exists_ent(pTHX_ HV *hv, SV *keysv, U32 hash)
1225 return hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash)
1230 Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, U32 hash)
1232 return (HE *)hv_common(hv, keysv, NULL, 0, 0,
1233 (lval ? HV_FETCH_LVALUE : 0), NULL, hash);
1237 Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash)
1239 return (SV *) hv_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, NULL,
1244 Perl_hv_store_flags(pTHX_ HV *hv, const char *key, I32 klen, SV *val, U32 hash,
1247 return (SV**) hv_common(hv, NULL, key, klen, flags,
1248 (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
1252 Perl_hv_store(pTHX_ HV *hv, const char *key, I32 klen_i32, SV *val, U32 hash)
1264 return (SV **) hv_common(hv, NULL, key, klen, flags,
1265 (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
1269 Perl_hv_exists(pTHX_ HV *hv, const char *key, I32 klen_i32)
1281 return hv_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0)
1286 Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
1298 return (SV **) hv_common(hv, NULL, key, klen, flags,
1299 lval ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE)
1300 : HV_FETCH_JUST_SV, NULL, 0);
1304 Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
1311 k_flags = HVhek_UTF8;
1316 return (SV *) hv_common(hv, NULL, key, klen, k_flags, flags | HV_DELETE,
1320 /* Functions after here were made mathoms post 5.10.0 but pre 5.8.9 */
1325 return (AV*)newSV_type(SVt_PVAV);
1326 /* sv_upgrade does AvREAL_only():
1329 AvMAX(av) = AvFILLp(av) = -1; */
1335 HV * const hv = (HV*)newSV_type(SVt_PVHV);
1341 #endif /* NO_MATHOMS */
1345 * c-indentation-style: bsd
1347 * indent-tabs-mode: t
1350 * ex: set ts=8 sts=4 sw=4 noet: