3 * Copyright (C) 2005, 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."
18 * This file contains mathoms, various binary artifacts from previous
19 * versions of Perl. For binary or source compatibility reasons, though,
20 * we cannot completely remove them from the core code.
27 #define PERL_IN_MATHOMS_C
30 /* ref() is now a macro using Perl_doref;
31 * this version provided for binary compatibility only.
34 Perl_ref(pTHX_ OP *o, I32 type)
36 return doref(o, type, TRUE);
42 Unsets the RV status of the SV, and decrements the reference count of
43 whatever was being referenced by the RV. This can almost be thought of
44 as a reversal of C<newSVrv>. This is C<sv_unref_flags> with the C<flag>
45 being zero. See C<SvROK_off>.
51 Perl_sv_unref(pTHX_ SV *sv)
53 sv_unref_flags(sv, 0);
59 Taint an SV. Use C<SvTAINTED_on> instead.
64 Perl_sv_taint(pTHX_ SV *sv)
66 sv_magic((sv), Nullsv, PERL_MAGIC_taint, Nullch, 0);
69 /* sv_2iv() is now a macro using Perl_sv_2iv_flags();
70 * this function provided for binary compatibility only
74 Perl_sv_2iv(pTHX_ register SV *sv)
76 return sv_2iv_flags(sv, SV_GMAGIC);
79 /* sv_2uv() is now a macro using Perl_sv_2uv_flags();
80 * this function provided for binary compatibility only
84 Perl_sv_2uv(pTHX_ register SV *sv)
86 return sv_2uv_flags(sv, SV_GMAGIC);
89 /* sv_2pv() is now a macro using Perl_sv_2pv_flags();
90 * this function provided for binary compatibility only
94 Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp)
96 return sv_2pv_flags(sv, lp, SV_GMAGIC);
100 =for apidoc sv_2pv_nolen
102 Like C<sv_2pv()>, but doesn't return the length too. You should usually
103 use the macro wrapper C<SvPV_nolen(sv)> instead.
108 Perl_sv_2pv_nolen(pTHX_ register SV *sv)
110 return sv_2pv(sv, 0);
114 =for apidoc sv_2pvbyte_nolen
116 Return a pointer to the byte-encoded representation of the SV.
117 May cause the SV to be downgraded from UTF-8 as a side-effect.
119 Usually accessed via the C<SvPVbyte_nolen> macro.
125 Perl_sv_2pvbyte_nolen(pTHX_ register SV *sv)
127 return sv_2pvbyte(sv, 0);
131 =for apidoc sv_2pvutf8_nolen
133 Return a pointer to the UTF-8-encoded representation of the SV.
134 May cause the SV to be upgraded to UTF-8 as a side-effect.
136 Usually accessed via the C<SvPVutf8_nolen> macro.
142 Perl_sv_2pvutf8_nolen(pTHX_ register SV *sv)
144 return sv_2pvutf8(sv, 0);
148 =for apidoc sv_force_normal
150 Undo various types of fakery on an SV: if the PV is a shared string, make
151 a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
152 an xpvmg. See also C<sv_force_normal_flags>.
158 Perl_sv_force_normal(pTHX_ register SV *sv)
160 sv_force_normal_flags(sv, 0);
163 /* sv_setsv() is now a macro using Perl_sv_setsv_flags();
164 * this function provided for binary compatibility only
168 Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr)
170 sv_setsv_flags(dstr, sstr, SV_GMAGIC);
173 /* sv_catpvn() is now a macro using Perl_sv_catpvn_flags();
174 * this function provided for binary compatibility only
178 Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
180 sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC);
183 /* sv_catsv() is now a macro using Perl_sv_catsv_flags();
184 * this function provided for binary compatibility only
188 Perl_sv_catsv(pTHX_ SV *dstr, register SV *sstr)
190 sv_catsv_flags(dstr, sstr, SV_GMAGIC);
196 A private implementation of the C<SvIVx> macro for compilers which can't
197 cope with complex macro expressions. Always use the macro instead.
203 Perl_sv_iv(pTHX_ register SV *sv)
207 return (IV)SvUVX(sv);
216 A private implementation of the C<SvUVx> macro for compilers which can't
217 cope with complex macro expressions. Always use the macro instead.
223 Perl_sv_uv(pTHX_ register SV *sv)
228 return (UV)SvIVX(sv);
236 A private implementation of the C<SvNVx> macro for compilers which can't
237 cope with complex macro expressions. Always use the macro instead.
243 Perl_sv_nv(pTHX_ register SV *sv)
253 Use the C<SvPV_nolen> macro instead
257 A private implementation of the C<SvPV> macro for compilers which can't
258 cope with complex macro expressions. Always use the macro instead.
264 Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
270 return sv_2pv(sv, lp);
275 Perl_sv_pvn_nomg(pTHX_ register SV *sv, STRLEN *lp)
281 return sv_2pv_flags(sv, lp, 0);
284 /* sv_pv() is now a macro using SvPV_nolen();
285 * this function provided for binary compatibility only
289 Perl_sv_pv(pTHX_ SV *sv)
294 return sv_2pv(sv, 0);
297 /* sv_pvn_force() is now a macro using Perl_sv_pvn_force_flags();
298 * this function provided for binary compatibility only
302 Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
304 return sv_pvn_force_flags(sv, lp, SV_GMAGIC);
307 /* sv_pvbyte () is now a macro using Perl_sv_2pv_flags();
308 * this function provided for binary compatibility only
312 Perl_sv_pvbyte(pTHX_ SV *sv)
314 sv_utf8_downgrade(sv,0);
319 =for apidoc sv_pvbyte
321 Use C<SvPVbyte_nolen> instead.
323 =for apidoc sv_pvbyten
325 A private implementation of the C<SvPVbyte> macro for compilers
326 which can't cope with complex macro expressions. Always use the macro
333 Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
335 sv_utf8_downgrade(sv,0);
336 return sv_pvn(sv,lp);
339 /* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
340 * this function provided for binary compatibility only
344 Perl_sv_pvutf8(pTHX_ SV *sv)
351 =for apidoc sv_pvutf8
353 Use the C<SvPVutf8_nolen> macro instead
355 =for apidoc sv_pvutf8n
357 A private implementation of the C<SvPVutf8> macro for compilers
358 which can't cope with complex macro expressions. Always use the macro
365 Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
368 return sv_pvn(sv,lp);
371 /* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
372 * this function provided for binary compatibility only
376 Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
378 return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
382 =for apidoc A|U8 *|uvchr_to_utf8|U8 *d|UV uv
384 Adds the UTF-8 representation of the Native codepoint C<uv> to the end
385 of the string C<d>; C<d> should be have at least C<UTF8_MAXBYTES+1> free
386 bytes available. The return value is the pointer to the byte after the
387 end of the new character. In other words,
389 d = uvchr_to_utf8(d, uv);
391 is the recommended wide native character-aware way of saying
398 /* On ASCII machines this is normally a macro but we want a
399 real function in case XS code wants it
401 #undef Perl_uvchr_to_utf8
403 Perl_uvchr_to_utf8(pTHX_ U8 *d, UV uv)
405 return Perl_uvuni_to_utf8_flags(aTHX_ d, NATIVE_TO_UNI(uv), 0);
410 =for apidoc A|UV|utf8n_to_uvchr|U8 *s|STRLEN curlen|STRLEN *retlen|U32
413 Returns the native character value of the first character in the string
415 which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
416 length, in bytes, of that character.
418 Allows length and flags to be passed to low level routine.
422 /* On ASCII machines this is normally a macro but we want
423 a real function in case XS code wants it
425 #undef Perl_utf8n_to_uvchr
427 Perl_utf8n_to_uvchr(pTHX_ const U8 *s, STRLEN curlen, STRLEN *retlen,
430 const UV uv = Perl_utf8n_to_uvuni(aTHX_ s, curlen, retlen, flags);
431 return UNI_TO_NATIVE(uv);
434 Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...)
438 va_start(arglist, format);
439 return PerlIO_vprintf(stream, format, arglist);
443 Perl_printf_nocontext(const char *format, ...)
447 va_start(arglist, format);
448 return PerlIO_vprintf(PerlIO_stdout(), format, arglist);
451 #if defined(HUGE_VAL) || (defined(USE_LONG_DOUBLE) && defined(HUGE_VALL))
453 * This hack is to force load of "huge" support from libm.a
454 * So it is in perl for (say) POSIX to use.
455 * Needed for SunOS with Sun's 'acc' for example.
460 # if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
469 perlsio_binmode(FILE *fp, int iotype, int mode)
472 * This used to be contents of do_binmode in doio.c
475 # if defined(atarist) || defined(__MINT__)
478 ((FILE *) fp)->_flag |= _IOBIN;
480 ((FILE *) fp)->_flag &= ~_IOBIN;
487 if (PerlLIO_setmode(fp, mode) != -1) {
489 if (PerlLIO_setmode(fileno(fp), mode) != -1) {
491 # if defined(WIN32) && defined(__BORLANDC__)
493 * The translation mode of the stream is maintained independent
495 * the translation mode of the fd in the Borland RTL (heavy
496 * digging through their runtime sources reveal). User has to
498 * the mode explicitly for the stream (though they don't
500 * this anywhere). GSAR 97-5-24
506 fp->flags &= ~_F_BIN;
514 # if defined(USEMYBINMODE)
516 if (my_binmode(fp, iotype, mode) != FALSE)
522 PERL_UNUSED_ARG(iotype);
523 PERL_UNUSED_ARG(mode);
530 /* compatibility with versions <= 5.003. */
532 Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
534 gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
537 /* compatibility with versions <= 5.003. */
539 Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
541 gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
545 Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
547 gv_fullname4(sv, gv, prefix, TRUE);
551 Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
553 gv_efullname4(sv, gv, prefix, TRUE);
557 Perl_av_fake(pTHX_ register I32 size, register SV **strp)
560 register AV * const av = (AV*)NEWSV(9,0);
562 sv_upgrade((SV *)av, SVt_PVAV);
563 Newx(ary,size+1,SV*);
565 Copy(strp,ary,size,SV*);
567 SvPV_set(av, (char*)ary);
568 AvFILLp(av) = size - 1;
569 AvMAX(av) = size - 1;
579 Perl_do_open9(pTHX_ GV *gv, register const char *name, I32 len, int
581 int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
584 PERL_UNUSED_ARG(num_svs);
585 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
586 supplied_fp, &svs, 1);
590 Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
592 /* The old body of this is now in non-LAYER part of perlio.c
593 * This is a stub for any XS code which might have been calling it.
595 const char *name = ":raw";
596 #ifdef PERLIO_USING_CRLF
597 if (!(mode & O_BINARY))
600 return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
606 * c-indentation-style: bsd
608 * indent-tabs-mode: t
611 * ex: set ts=8 sts=4 sw=4 noet: