This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Comments, white-space only
[perl5.git] / mathoms.c
... / ...
CommitLineData
1/* mathoms.c
2 *
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 * 2011, 2012 by Larry Wall and others
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 */
10
11/*
12 * Anything that Hobbits had no immediate use for, but were unwilling to
13 * throw away, they called a mathom. Their dwellings were apt to become
14 * rather crowded with mathoms, and many of the presents that passed from
15 * hand to hand were of that sort.
16 *
17 * [p.5 of _The Lord of the Rings_: "Prologue"]
18 */
19
20
21
22/*
23 * This file contains mathoms, various binary artifacts from previous
24 * versions of Perl which we cannot completely remove from the core
25 * code. There are two reasons functions should be here:
26 *
27 * 1) A function has been been replaced by a macro within a minor release,
28 * so XS modules compiled against an older release will expect to
29 * still be able to link against the function
30 * 2) A function Perl_foo(...) with #define foo Perl_foo(aTHX_ ...)
31 * has been replaced by a macro, e.g. #define foo(...) foo_flags(...,0)
32 * but XS code may still explicitly use the long form, i.e.
33 * Perl_foo(aTHX_ ...)
34 *
35 * NOTE: ALL FUNCTIONS IN THIS FILE should have an entry with the 'b' flag in
36 * embed.fnc.
37 *
38 * To move a function to this file, simply cut and paste it here, and change
39 * its embed.fnc entry to additionally have the 'b' flag. If, for some reason
40 * a function you'd like to be treated as mathoms can't be moved from its
41 * current place, simply enclose it between
42 *
43 * #ifndef NO_MATHOMS
44 * ...
45 * #endif
46 *
47 * and add the 'b' flag in embed.fnc.
48 *
49 * The compilation of this file can be suppressed; see INSTALL
50 *
51 * Some blurb for perlapi.pod:
52
53=head1 Obsolete backwards compatibility functions
54
55Some of these are also deprecated. You can exclude these from
56your compiled Perl by adding this option to Configure:
57C<-Accflags='-DNO_MATHOMS'>
58
59=cut
60
61 */
62
63
64#include "EXTERN.h"
65#define PERL_IN_MATHOMS_C
66#include "perl.h"
67
68#ifdef NO_MATHOMS
69/* ..." warning: ISO C forbids an empty source file"
70 So make sure we have something in here by processing the headers anyway.
71 */
72#else
73
74/* The functions in this file should be able to call other deprecated functions
75 * without a compiler warning */
76GCC_DIAG_IGNORE(-Wdeprecated-declarations)
77
78/* ref() is now a macro using Perl_doref;
79 * this version provided for binary compatibility only.
80 */
81OP *
82Perl_ref(pTHX_ OP *o, I32 type)
83{
84 return doref(o, type, TRUE);
85}
86
87/*
88=for apidoc sv_unref
89
90Unsets the RV status of the SV, and decrements the reference count of
91whatever was being referenced by the RV. This can almost be thought of
92as a reversal of C<newSVrv>. This is C<sv_unref_flags> with the C<flag>
93being zero. See C<L</SvROK_off>>.
94
95=cut
96*/
97
98void
99Perl_sv_unref(pTHX_ SV *sv)
100{
101 PERL_ARGS_ASSERT_SV_UNREF;
102
103 sv_unref_flags(sv, 0);
104}
105
106/*
107=for apidoc sv_taint
108
109Taint an SV. Use C<SvTAINTED_on> instead.
110
111=cut
112*/
113
114void
115Perl_sv_taint(pTHX_ SV *sv)
116{
117 PERL_ARGS_ASSERT_SV_TAINT;
118
119 sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0);
120}
121
122/* sv_2iv() is now a macro using Perl_sv_2iv_flags();
123 * this function provided for binary compatibility only
124 */
125
126IV
127Perl_sv_2iv(pTHX_ SV *sv)
128{
129 PERL_ARGS_ASSERT_SV_2IV;
130
131 return sv_2iv_flags(sv, SV_GMAGIC);
132}
133
134/* sv_2uv() is now a macro using Perl_sv_2uv_flags();
135 * this function provided for binary compatibility only
136 */
137
138UV
139Perl_sv_2uv(pTHX_ SV *sv)
140{
141 PERL_ARGS_ASSERT_SV_2UV;
142
143 return sv_2uv_flags(sv, SV_GMAGIC);
144}
145
146/* sv_2nv() is now a macro using Perl_sv_2nv_flags();
147 * this function provided for binary compatibility only
148 */
149
150NV
151Perl_sv_2nv(pTHX_ SV *sv)
152{
153 return sv_2nv_flags(sv, SV_GMAGIC);
154}
155
156
157/* sv_2pv() is now a macro using Perl_sv_2pv_flags();
158 * this function provided for binary compatibility only
159 */
160
161char *
162Perl_sv_2pv(pTHX_ SV *sv, STRLEN *lp)
163{
164 PERL_ARGS_ASSERT_SV_2PV;
165
166 return sv_2pv_flags(sv, lp, SV_GMAGIC);
167}
168
169/*
170=for apidoc sv_2pv_nolen
171
172Like C<sv_2pv()>, but doesn't return the length too. You should usually
173use the macro wrapper C<SvPV_nolen(sv)> instead.
174
175=cut
176*/
177
178char *
179Perl_sv_2pv_nolen(pTHX_ SV *sv)
180{
181 PERL_ARGS_ASSERT_SV_2PV_NOLEN;
182 return sv_2pv(sv, NULL);
183}
184
185/*
186=for apidoc sv_2pvbyte_nolen
187
188Return a pointer to the byte-encoded representation of the SV.
189May cause the SV to be downgraded from UTF-8 as a side-effect.
190
191Usually accessed via the C<SvPVbyte_nolen> macro.
192
193=cut
194*/
195
196char *
197Perl_sv_2pvbyte_nolen(pTHX_ SV *sv)
198{
199 PERL_ARGS_ASSERT_SV_2PVBYTE_NOLEN;
200
201 return sv_2pvbyte(sv, NULL);
202}
203
204/*
205=for apidoc sv_2pvutf8_nolen
206
207Return a pointer to the UTF-8-encoded representation of the SV.
208May cause the SV to be upgraded to UTF-8 as a side-effect.
209
210Usually accessed via the C<SvPVutf8_nolen> macro.
211
212=cut
213*/
214
215char *
216Perl_sv_2pvutf8_nolen(pTHX_ SV *sv)
217{
218 PERL_ARGS_ASSERT_SV_2PVUTF8_NOLEN;
219
220 return sv_2pvutf8(sv, NULL);
221}
222
223/*
224=for apidoc sv_force_normal
225
226Undo various types of fakery on an SV: if the PV is a shared string, make
227a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
228an C<xpvmg>. See also C<L</sv_force_normal_flags>>.
229
230=cut
231*/
232
233void
234Perl_sv_force_normal(pTHX_ SV *sv)
235{
236 PERL_ARGS_ASSERT_SV_FORCE_NORMAL;
237
238 sv_force_normal_flags(sv, 0);
239}
240
241/* sv_setsv() is now a macro using Perl_sv_setsv_flags();
242 * this function provided for binary compatibility only
243 */
244
245void
246Perl_sv_setsv(pTHX_ SV *dstr, SV *sstr)
247{
248 PERL_ARGS_ASSERT_SV_SETSV;
249
250 sv_setsv_flags(dstr, sstr, SV_GMAGIC);
251}
252
253/* sv_catpvn() is now a macro using Perl_sv_catpvn_flags();
254 * this function provided for binary compatibility only
255 */
256
257void
258Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
259{
260 PERL_ARGS_ASSERT_SV_CATPVN;
261
262 sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC);
263}
264
265/*
266=for apidoc sv_catpvn_mg
267
268Like C<sv_catpvn>, but also handles 'set' magic.
269
270=cut
271*/
272
273void
274Perl_sv_catpvn_mg(pTHX_ SV *sv, const char *ptr, STRLEN len)
275{
276 PERL_ARGS_ASSERT_SV_CATPVN_MG;
277
278 sv_catpvn_flags(sv,ptr,len,SV_GMAGIC|SV_SMAGIC);
279}
280
281/* sv_catsv() is now a macro using Perl_sv_catsv_flags();
282 * this function provided for binary compatibility only
283 */
284
285void
286Perl_sv_catsv(pTHX_ SV *dstr, SV *sstr)
287{
288 PERL_ARGS_ASSERT_SV_CATSV;
289
290 sv_catsv_flags(dstr, sstr, SV_GMAGIC);
291}
292
293/*
294=for apidoc sv_catsv_mg
295
296Like C<sv_catsv>, but also handles 'set' magic.
297
298=cut
299*/
300
301void
302Perl_sv_catsv_mg(pTHX_ SV *dsv, SV *ssv)
303{
304 PERL_ARGS_ASSERT_SV_CATSV_MG;
305
306 sv_catsv_flags(dsv,ssv,SV_GMAGIC|SV_SMAGIC);
307}
308
309/*
310=for apidoc sv_iv
311
312A private implementation of the C<SvIVx> macro for compilers which can't
313cope with complex macro expressions. Always use the macro instead.
314
315=cut
316*/
317
318IV
319Perl_sv_iv(pTHX_ SV *sv)
320{
321 PERL_ARGS_ASSERT_SV_IV;
322
323 if (SvIOK(sv)) {
324 if (SvIsUV(sv))
325 return (IV)SvUVX(sv);
326 return SvIVX(sv);
327 }
328 return sv_2iv(sv);
329}
330
331/*
332=for apidoc sv_uv
333
334A private implementation of the C<SvUVx> macro for compilers which can't
335cope with complex macro expressions. Always use the macro instead.
336
337=cut
338*/
339
340UV
341Perl_sv_uv(pTHX_ SV *sv)
342{
343 PERL_ARGS_ASSERT_SV_UV;
344
345 if (SvIOK(sv)) {
346 if (SvIsUV(sv))
347 return SvUVX(sv);
348 return (UV)SvIVX(sv);
349 }
350 return sv_2uv(sv);
351}
352
353/*
354=for apidoc sv_nv
355
356A private implementation of the C<SvNVx> macro for compilers which can't
357cope with complex macro expressions. Always use the macro instead.
358
359=cut
360*/
361
362NV
363Perl_sv_nv(pTHX_ SV *sv)
364{
365 PERL_ARGS_ASSERT_SV_NV;
366
367 if (SvNOK(sv))
368 return SvNVX(sv);
369 return sv_2nv(sv);
370}
371
372/*
373=for apidoc sv_pv
374
375Use the C<SvPV_nolen> macro instead
376
377=for apidoc sv_pvn
378
379A private implementation of the C<SvPV> macro for compilers which can't
380cope with complex macro expressions. Always use the macro instead.
381
382=cut
383*/
384
385char *
386Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
387{
388 PERL_ARGS_ASSERT_SV_PVN;
389
390 if (SvPOK(sv)) {
391 *lp = SvCUR(sv);
392 return SvPVX(sv);
393 }
394 return sv_2pv(sv, lp);
395}
396
397
398char *
399Perl_sv_pvn_nomg(pTHX_ SV *sv, STRLEN *lp)
400{
401 PERL_ARGS_ASSERT_SV_PVN_NOMG;
402
403 if (SvPOK(sv)) {
404 *lp = SvCUR(sv);
405 return SvPVX(sv);
406 }
407 return sv_2pv_flags(sv, lp, 0);
408}
409
410/* sv_pv() is now a macro using SvPV_nolen();
411 * this function provided for binary compatibility only
412 */
413
414char *
415Perl_sv_pv(pTHX_ SV *sv)
416{
417 PERL_ARGS_ASSERT_SV_PV;
418
419 if (SvPOK(sv))
420 return SvPVX(sv);
421
422 return sv_2pv(sv, NULL);
423}
424
425/* sv_pvn_force() is now a macro using Perl_sv_pvn_force_flags();
426 * this function provided for binary compatibility only
427 */
428
429char *
430Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
431{
432 PERL_ARGS_ASSERT_SV_PVN_FORCE;
433
434 return sv_pvn_force_flags(sv, lp, SV_GMAGIC);
435}
436
437/* sv_pvbyte () is now a macro using Perl_sv_2pv_flags();
438 * this function provided for binary compatibility only
439 */
440
441char *
442Perl_sv_pvbyte(pTHX_ SV *sv)
443{
444 PERL_ARGS_ASSERT_SV_PVBYTE;
445
446 sv_utf8_downgrade(sv, FALSE);
447 return sv_pv(sv);
448}
449
450/*
451=for apidoc sv_pvbyte
452
453Use C<SvPVbyte_nolen> instead.
454
455=for apidoc sv_pvbyten
456
457A private implementation of the C<SvPVbyte> macro for compilers
458which can't cope with complex macro expressions. Always use the macro
459instead.
460
461=cut
462*/
463
464char *
465Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
466{
467 PERL_ARGS_ASSERT_SV_PVBYTEN;
468
469 sv_utf8_downgrade(sv, FALSE);
470 return sv_pvn(sv,lp);
471}
472
473/* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
474 * this function provided for binary compatibility only
475 */
476
477char *
478Perl_sv_pvutf8(pTHX_ SV *sv)
479{
480 PERL_ARGS_ASSERT_SV_PVUTF8;
481
482 sv_utf8_upgrade(sv);
483 return sv_pv(sv);
484}
485
486/*
487=for apidoc sv_pvutf8
488
489Use the C<SvPVutf8_nolen> macro instead
490
491=for apidoc sv_pvutf8n
492
493A private implementation of the C<SvPVutf8> macro for compilers
494which can't cope with complex macro expressions. Always use the macro
495instead.
496
497=cut
498*/
499
500char *
501Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
502{
503 PERL_ARGS_ASSERT_SV_PVUTF8N;
504
505 sv_utf8_upgrade(sv);
506 return sv_pvn(sv,lp);
507}
508
509/* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
510 * this function provided for binary compatibility only
511 */
512
513STRLEN
514Perl_sv_utf8_upgrade(pTHX_ SV *sv)
515{
516 PERL_ARGS_ASSERT_SV_UTF8_UPGRADE;
517
518 return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
519}
520
521int
522Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...)
523{
524 int ret = 0;
525 va_list arglist;
526
527 /* Easier to special case this here than in embed.pl. (Look at what it
528 generates for proto.h) */
529#ifdef PERL_IMPLICIT_CONTEXT
530 PERL_ARGS_ASSERT_FPRINTF_NOCONTEXT;
531#endif
532
533 va_start(arglist, format);
534 ret = PerlIO_vprintf(stream, format, arglist);
535 va_end(arglist);
536 return ret;
537}
538
539int
540Perl_printf_nocontext(const char *format, ...)
541{
542 dTHX;
543 va_list arglist;
544 int ret = 0;
545
546#ifdef PERL_IMPLICIT_CONTEXT
547 PERL_ARGS_ASSERT_PRINTF_NOCONTEXT;
548#endif
549
550 va_start(arglist, format);
551 ret = PerlIO_vprintf(PerlIO_stdout(), format, arglist);
552 va_end(arglist);
553 return ret;
554}
555
556#if defined(HUGE_VAL) || (defined(USE_LONG_DOUBLE) && defined(HUGE_VALL))
557/*
558 * This hack is to force load of "huge" support from libm.a
559 * So it is in perl for (say) POSIX to use.
560 * Needed for SunOS with Sun's 'acc' for example.
561 */
562NV
563Perl_huge(void)
564{
565# if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
566 return HUGE_VALL;
567# else
568 return HUGE_VAL;
569# endif
570}
571#endif
572
573/* compatibility with versions <= 5.003. */
574void
575Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
576{
577 PERL_ARGS_ASSERT_GV_FULLNAME;
578
579 gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
580}
581
582/* compatibility with versions <= 5.003. */
583void
584Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
585{
586 PERL_ARGS_ASSERT_GV_EFULLNAME;
587
588 gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
589}
590
591void
592Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
593{
594 PERL_ARGS_ASSERT_GV_FULLNAME3;
595
596 gv_fullname4(sv, gv, prefix, TRUE);
597}
598
599void
600Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
601{
602 PERL_ARGS_ASSERT_GV_EFULLNAME3;
603
604 gv_efullname4(sv, gv, prefix, TRUE);
605}
606
607/*
608=for apidoc gv_fetchmethod
609
610See L</gv_fetchmethod_autoload>.
611
612=cut
613*/
614
615GV *
616Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
617{
618 PERL_ARGS_ASSERT_GV_FETCHMETHOD;
619
620 return gv_fetchmethod_autoload(stash, name, TRUE);
621}
622
623HE *
624Perl_hv_iternext(pTHX_ HV *hv)
625{
626 PERL_ARGS_ASSERT_HV_ITERNEXT;
627
628 return hv_iternext_flags(hv, 0);
629}
630
631void
632Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how)
633{
634 PERL_ARGS_ASSERT_HV_MAGIC;
635
636 sv_magic(MUTABLE_SV(hv), MUTABLE_SV(gv), how, NULL, 0);
637}
638
639bool
640Perl_do_open(pTHX_ GV *gv, const char *name, I32 len, int as_raw,
641 int rawmode, int rawperm, PerlIO *supplied_fp)
642{
643 PERL_ARGS_ASSERT_DO_OPEN;
644
645 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
646 supplied_fp, (SV **) NULL, 0);
647}
648
649bool
650Perl_do_open9(pTHX_ GV *gv, const char *name, I32 len, int
651as_raw,
652 int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
653 I32 num_svs)
654{
655 PERL_ARGS_ASSERT_DO_OPEN9;
656
657 PERL_UNUSED_ARG(num_svs);
658 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
659 supplied_fp, &svs, 1);
660}
661
662int
663Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
664{
665 /* The old body of this is now in non-LAYER part of perlio.c
666 * This is a stub for any XS code which might have been calling it.
667 */
668 const char *name = ":raw";
669
670 PERL_ARGS_ASSERT_DO_BINMODE;
671
672#ifdef PERLIO_USING_CRLF
673 if (!(mode & O_BINARY))
674 name = ":crlf";
675#endif
676 return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
677}
678
679#ifndef OS2
680bool
681Perl_do_aexec(pTHX_ SV *really, SV **mark, SV **sp)
682{
683 PERL_ARGS_ASSERT_DO_AEXEC;
684
685 return do_aexec5(really, mark, sp, 0, 0);
686}
687#endif
688
689/* Backwards compatibility. */
690int
691Perl_init_i18nl14n(pTHX_ int printwarn)
692{
693 return init_i18nl10n(printwarn);
694}
695
696bool
697Perl_is_utf8_string_loc(const U8 *s, const STRLEN len, const U8 **ep)
698{
699 PERL_ARGS_ASSERT_IS_UTF8_STRING_LOC;
700
701 return is_utf8_string_loclen(s, len, ep, 0);
702}
703
704/*
705=for apidoc sv_nolocking
706
707Dummy routine which "locks" an SV when there is no locking module present.
708Exists to avoid test for a C<NULL> function pointer and because it could
709potentially warn under some level of strict-ness.
710
711"Superseded" by C<sv_nosharing()>.
712
713=cut
714*/
715
716void
717Perl_sv_nolocking(pTHX_ SV *sv)
718{
719 PERL_UNUSED_CONTEXT;
720 PERL_UNUSED_ARG(sv);
721}
722
723
724/*
725=for apidoc sv_nounlocking
726
727Dummy routine which "unlocks" an SV when there is no locking module present.
728Exists to avoid test for a C<NULL> function pointer and because it could
729potentially warn under some level of strict-ness.
730
731"Superseded" by C<sv_nosharing()>.
732
733=cut
734
735PERL_UNLOCK_HOOK in intrpvar.h is the macro that refers to this, and guarantees
736that mathoms gets loaded.
737
738*/
739
740void
741Perl_sv_nounlocking(pTHX_ SV *sv)
742{
743 PERL_UNUSED_CONTEXT;
744 PERL_UNUSED_ARG(sv);
745}
746
747void
748Perl_save_long(pTHX_ long int *longp)
749{
750 PERL_ARGS_ASSERT_SAVE_LONG;
751
752 SSCHECK(3);
753 SSPUSHLONG(*longp);
754 SSPUSHPTR(longp);
755 SSPUSHUV(SAVEt_LONG);
756}
757
758void
759Perl_save_nogv(pTHX_ GV *gv)
760{
761 PERL_ARGS_ASSERT_SAVE_NOGV;
762
763 SSCHECK(2);
764 SSPUSHPTR(gv);
765 SSPUSHUV(SAVEt_NSTAB);
766}
767
768void
769Perl_save_list(pTHX_ SV **sarg, I32 maxsarg)
770{
771 I32 i;
772
773 PERL_ARGS_ASSERT_SAVE_LIST;
774
775 for (i = 1; i <= maxsarg; i++) {
776 SV *sv;
777 SvGETMAGIC(sarg[i]);
778 sv = newSV(0);
779 sv_setsv_nomg(sv,sarg[i]);
780 SSCHECK(3);
781 SSPUSHPTR(sarg[i]); /* remember the pointer */
782 SSPUSHPTR(sv); /* remember the value */
783 SSPUSHUV(SAVEt_ITEM);
784 }
785}
786
787/*
788=for apidoc sv_usepvn_mg
789
790Like C<sv_usepvn>, but also handles 'set' magic.
791
792=cut
793*/
794
795void
796Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len)
797{
798 PERL_ARGS_ASSERT_SV_USEPVN_MG;
799
800 sv_usepvn_flags(sv,ptr,len, SV_SMAGIC);
801}
802
803/*
804=for apidoc sv_usepvn
805
806Tells an SV to use C<ptr> to find its string value. Implemented by
807calling C<sv_usepvn_flags> with C<flags> of 0, hence does not handle 'set'
808magic. See C<L</sv_usepvn_flags>>.
809
810=cut
811*/
812
813void
814Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len)
815{
816 PERL_ARGS_ASSERT_SV_USEPVN;
817
818 sv_usepvn_flags(sv,ptr,len, 0);
819}
820
821/*
822=for apidoc unpack_str
823
824The engine implementing C<unpack()> Perl function. Note: parameters C<strbeg>,
825C<new_s> and C<ocnt> are not used. This call should not be used, use
826C<unpackstring> instead.
827
828=cut */
829
830SSize_t
831Perl_unpack_str(pTHX_ const char *pat, const char *patend, const char *s,
832 const char *strbeg, const char *strend, char **new_s, I32 ocnt,
833 U32 flags)
834{
835 PERL_ARGS_ASSERT_UNPACK_STR;
836
837 PERL_UNUSED_ARG(strbeg);
838 PERL_UNUSED_ARG(new_s);
839 PERL_UNUSED_ARG(ocnt);
840
841 return unpackstring(pat, patend, s, strend, flags);
842}
843
844/*
845=for apidoc pack_cat
846
847The engine implementing C<pack()> Perl function. Note: parameters
848C<next_in_list> and C<flags> are not used. This call should not be used; use
849C<packlist> instead.
850
851=cut
852*/
853
854void
855Perl_pack_cat(pTHX_ SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
856{
857 PERL_ARGS_ASSERT_PACK_CAT;
858
859 PERL_UNUSED_ARG(next_in_list);
860 PERL_UNUSED_ARG(flags);
861
862 packlist(cat, pat, patend, beglist, endlist);
863}
864
865HE *
866Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, U32 hash)
867{
868 return (HE *)hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
869}
870
871bool
872Perl_hv_exists_ent(pTHX_ HV *hv, SV *keysv, U32 hash)
873{
874 PERL_ARGS_ASSERT_HV_EXISTS_ENT;
875
876 return cBOOL(hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash));
877}
878
879HE *
880Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, U32 hash)
881{
882 PERL_ARGS_ASSERT_HV_FETCH_ENT;
883
884 return (HE *)hv_common(hv, keysv, NULL, 0, 0,
885 (lval ? HV_FETCH_LVALUE : 0), NULL, hash);
886}
887
888SV *
889Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash)
890{
891 PERL_ARGS_ASSERT_HV_DELETE_ENT;
892
893 return MUTABLE_SV(hv_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, NULL,
894 hash));
895}
896
897SV**
898Perl_hv_store_flags(pTHX_ HV *hv, const char *key, I32 klen, SV *val, U32 hash,
899 int flags)
900{
901 return (SV**) hv_common(hv, NULL, key, klen, flags,
902 (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
903}
904
905SV**
906Perl_hv_store(pTHX_ HV *hv, const char *key, I32 klen_i32, SV *val, U32 hash)
907{
908 STRLEN klen;
909 int flags;
910
911 if (klen_i32 < 0) {
912 klen = -klen_i32;
913 flags = HVhek_UTF8;
914 } else {
915 klen = klen_i32;
916 flags = 0;
917 }
918 return (SV **) hv_common(hv, NULL, key, klen, flags,
919 (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
920}
921
922bool
923Perl_hv_exists(pTHX_ HV *hv, const char *key, I32 klen_i32)
924{
925 STRLEN klen;
926 int flags;
927
928 PERL_ARGS_ASSERT_HV_EXISTS;
929
930 if (klen_i32 < 0) {
931 klen = -klen_i32;
932 flags = HVhek_UTF8;
933 } else {
934 klen = klen_i32;
935 flags = 0;
936 }
937 return cBOOL(hv_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0));
938}
939
940SV**
941Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
942{
943 STRLEN klen;
944 int flags;
945
946 PERL_ARGS_ASSERT_HV_FETCH;
947
948 if (klen_i32 < 0) {
949 klen = -klen_i32;
950 flags = HVhek_UTF8;
951 } else {
952 klen = klen_i32;
953 flags = 0;
954 }
955 return (SV **) hv_common(hv, NULL, key, klen, flags,
956 lval ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE)
957 : HV_FETCH_JUST_SV, NULL, 0);
958}
959
960SV *
961Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
962{
963 STRLEN klen;
964 int k_flags;
965
966 PERL_ARGS_ASSERT_HV_DELETE;
967
968 if (klen_i32 < 0) {
969 klen = -klen_i32;
970 k_flags = HVhek_UTF8;
971 } else {
972 klen = klen_i32;
973 k_flags = 0;
974 }
975 return MUTABLE_SV(hv_common(hv, NULL, key, klen, k_flags, flags | HV_DELETE,
976 NULL, 0));
977}
978
979AV *
980Perl_newAV(pTHX)
981{
982 return MUTABLE_AV(newSV_type(SVt_PVAV));
983 /* sv_upgrade does AvREAL_only():
984 AvALLOC(av) = 0;
985 AvARRAY(av) = NULL;
986 AvMAX(av) = AvFILLp(av) = -1; */
987}
988
989HV *
990Perl_newHV(pTHX)
991{
992 HV * const hv = MUTABLE_HV(newSV_type(SVt_PVHV));
993 assert(!SvOK(hv));
994
995 return hv;
996}
997
998void
999Perl_sv_insert(pTHX_ SV *const bigstr, const STRLEN offset, const STRLEN len,
1000 const char *const little, const STRLEN littlelen)
1001{
1002 PERL_ARGS_ASSERT_SV_INSERT;
1003 sv_insert_flags(bigstr, offset, len, little, littlelen, SV_GMAGIC);
1004}
1005
1006void
1007Perl_save_freesv(pTHX_ SV *sv)
1008{
1009 save_freesv(sv);
1010}
1011
1012void
1013Perl_save_mortalizesv(pTHX_ SV *sv)
1014{
1015 PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
1016
1017 save_mortalizesv(sv);
1018}
1019
1020void
1021Perl_save_freeop(pTHX_ OP *o)
1022{
1023 save_freeop(o);
1024}
1025
1026void
1027Perl_save_freepv(pTHX_ char *pv)
1028{
1029 save_freepv(pv);
1030}
1031
1032void
1033Perl_save_op(pTHX)
1034{
1035 save_op();
1036}
1037
1038#ifdef PERL_DONT_CREATE_GVSV
1039GV *
1040Perl_gv_SVadd(pTHX_ GV *gv)
1041{
1042 return gv_SVadd(gv);
1043}
1044#endif
1045
1046GV *
1047Perl_gv_AVadd(pTHX_ GV *gv)
1048{
1049 return gv_AVadd(gv);
1050}
1051
1052GV *
1053Perl_gv_HVadd(pTHX_ GV *gv)
1054{
1055 return gv_HVadd(gv);
1056}
1057
1058GV *
1059Perl_gv_IOadd(pTHX_ GV *gv)
1060{
1061 return gv_IOadd(gv);
1062}
1063
1064IO *
1065Perl_newIO(pTHX)
1066{
1067 return MUTABLE_IO(newSV_type(SVt_PVIO));
1068}
1069
1070I32
1071Perl_my_stat(pTHX)
1072{
1073 return my_stat_flags(SV_GMAGIC);
1074}
1075
1076I32
1077Perl_my_lstat(pTHX)
1078{
1079 return my_lstat_flags(SV_GMAGIC);
1080}
1081
1082I32
1083Perl_sv_eq(pTHX_ SV *sv1, SV *sv2)
1084{
1085 return sv_eq_flags(sv1, sv2, SV_GMAGIC);
1086}
1087
1088#ifdef USE_LOCALE_COLLATE
1089char *
1090Perl_sv_collxfrm(pTHX_ SV *const sv, STRLEN *const nxp)
1091{
1092 PERL_ARGS_ASSERT_SV_COLLXFRM;
1093 return sv_collxfrm_flags(sv, nxp, SV_GMAGIC);
1094}
1095
1096char *
1097Perl_mem_collxfrm(pTHX_ const char *input_string, STRLEN len, STRLEN *xlen)
1098{
1099 /* This function is retained for compatibility in case someone outside core
1100 * is using this (but it is undocumented) */
1101
1102 PERL_ARGS_ASSERT_MEM_COLLXFRM;
1103
1104 return _mem_collxfrm(input_string, len, xlen, FALSE);
1105}
1106
1107#endif
1108
1109bool
1110Perl_sv_2bool(pTHX_ SV *const sv)
1111{
1112 PERL_ARGS_ASSERT_SV_2BOOL;
1113 return sv_2bool_flags(sv, SV_GMAGIC);
1114}
1115
1116
1117/*
1118=for apidoc custom_op_name
1119Return the name for a given custom op. This was once used by the C<OP_NAME>
1120macro, but is no longer: it has only been kept for compatibility, and
1121should not be used.
1122
1123=for apidoc custom_op_desc
1124Return the description of a given custom op. This was once used by the
1125C<OP_DESC> macro, but is no longer: it has only been kept for
1126compatibility, and should not be used.
1127
1128=cut
1129*/
1130
1131const char*
1132Perl_custom_op_name(pTHX_ const OP* o)
1133{
1134 PERL_ARGS_ASSERT_CUSTOM_OP_NAME;
1135 return XopENTRYCUSTOM(o, xop_name);
1136}
1137
1138const char*
1139Perl_custom_op_desc(pTHX_ const OP* o)
1140{
1141 PERL_ARGS_ASSERT_CUSTOM_OP_DESC;
1142 return XopENTRYCUSTOM(o, xop_desc);
1143}
1144
1145CV *
1146Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
1147{
1148 return newATTRSUB(floor, o, proto, NULL, block);
1149}
1150
1151SV *
1152Perl_sv_mortalcopy(pTHX_ SV *const oldstr)
1153{
1154 return Perl_sv_mortalcopy_flags(aTHX_ oldstr, SV_GMAGIC);
1155}
1156
1157void
1158Perl_sv_copypv(pTHX_ SV *const dsv, SV *const ssv)
1159{
1160 PERL_ARGS_ASSERT_SV_COPYPV;
1161
1162 sv_copypv_flags(dsv, ssv, SV_GMAGIC);
1163}
1164
1165UV /* Made into a function, so can be deprecated */
1166NATIVE_TO_NEED(const UV enc, const UV ch)
1167{
1168 PERL_UNUSED_ARG(enc);
1169 return ch;
1170}
1171
1172UV /* Made into a function, so can be deprecated */
1173ASCII_TO_NEED(const UV enc, const UV ch)
1174{
1175 PERL_UNUSED_ARG(enc);
1176 return ch;
1177}
1178
1179bool
1180Perl_is_uni_alnum(pTHX_ UV c)
1181{
1182 return isWORDCHAR_uni(c);
1183}
1184
1185bool
1186Perl_is_uni_alnumc(pTHX_ UV c)
1187{
1188 return isALNUM_uni(c);
1189}
1190
1191bool
1192Perl_is_uni_alpha(pTHX_ UV c)
1193{
1194 return isALPHA_uni(c);
1195}
1196
1197bool
1198Perl_is_uni_ascii(pTHX_ UV c)
1199{
1200 PERL_UNUSED_CONTEXT;
1201 return isASCII_uni(c);
1202}
1203
1204bool
1205Perl_is_uni_blank(pTHX_ UV c)
1206{
1207 PERL_UNUSED_CONTEXT;
1208 return isBLANK_uni(c);
1209}
1210
1211bool
1212Perl_is_uni_space(pTHX_ UV c)
1213{
1214 PERL_UNUSED_CONTEXT;
1215 return isSPACE_uni(c);
1216}
1217
1218bool
1219Perl_is_uni_digit(pTHX_ UV c)
1220{
1221 PERL_UNUSED_CONTEXT;
1222 return isDIGIT_uni(c);
1223}
1224
1225bool
1226Perl_is_uni_upper(pTHX_ UV c)
1227{
1228 PERL_UNUSED_CONTEXT;
1229 return isUPPER_uni(c);
1230}
1231
1232bool
1233Perl_is_uni_lower(pTHX_ UV c)
1234{
1235 PERL_UNUSED_CONTEXT;
1236 return isLOWER_uni(c);
1237}
1238
1239bool
1240Perl_is_uni_cntrl(pTHX_ UV c)
1241{
1242 PERL_UNUSED_CONTEXT;
1243 return isCNTRL_L1(c);
1244}
1245
1246bool
1247Perl_is_uni_graph(pTHX_ UV c)
1248{
1249 PERL_UNUSED_CONTEXT;
1250 return isGRAPH_uni(c);
1251}
1252
1253bool
1254Perl_is_uni_print(pTHX_ UV c)
1255{
1256 PERL_UNUSED_CONTEXT;
1257 return isPRINT_uni(c);
1258}
1259
1260bool
1261Perl_is_uni_punct(pTHX_ UV c)
1262{
1263 PERL_UNUSED_CONTEXT;
1264 return isPUNCT_uni(c);
1265}
1266
1267bool
1268Perl_is_uni_xdigit(pTHX_ UV c)
1269{
1270 PERL_UNUSED_CONTEXT;
1271 return isXDIGIT_uni(c);
1272}
1273
1274bool
1275Perl_is_uni_alnum_lc(pTHX_ UV c)
1276{
1277 PERL_UNUSED_CONTEXT;
1278 return isWORDCHAR_LC_uvchr(c);
1279}
1280
1281bool
1282Perl_is_uni_alnumc_lc(pTHX_ UV c)
1283{
1284 PERL_UNUSED_CONTEXT;
1285 return isALPHANUMERIC_LC_uvchr(c);
1286}
1287
1288bool
1289Perl_is_uni_idfirst_lc(pTHX_ UV c)
1290{
1291 PERL_UNUSED_CONTEXT;
1292 /* XXX Should probably be something that resolves to the old IDFIRST, but
1293 * this function is deprecated, so not bothering */
1294 return isIDFIRST_LC_uvchr(c);
1295}
1296
1297bool
1298Perl_is_uni_alpha_lc(pTHX_ UV c)
1299{
1300 PERL_UNUSED_CONTEXT;
1301 return isALPHA_LC_uvchr(c);
1302}
1303
1304bool
1305Perl_is_uni_ascii_lc(pTHX_ UV c)
1306{
1307 PERL_UNUSED_CONTEXT;
1308 return isASCII_LC_uvchr(c);
1309}
1310
1311bool
1312Perl_is_uni_blank_lc(pTHX_ UV c)
1313{
1314 PERL_UNUSED_CONTEXT;
1315 return isBLANK_LC_uvchr(c);
1316}
1317
1318bool
1319Perl_is_uni_space_lc(pTHX_ UV c)
1320{
1321 PERL_UNUSED_CONTEXT;
1322 return isSPACE_LC_uvchr(c);
1323}
1324
1325bool
1326Perl_is_uni_digit_lc(pTHX_ UV c)
1327{
1328 return isDIGIT_LC_uvchr(c);
1329}
1330
1331bool
1332Perl_is_uni_idfirst(pTHX_ UV c)
1333{
1334 U8 tmpbuf[UTF8_MAXBYTES+1];
1335 uvchr_to_utf8(tmpbuf, c);
1336 return _is_utf8_idstart(tmpbuf);
1337}
1338
1339bool
1340Perl_is_uni_upper_lc(pTHX_ UV c)
1341{
1342 return isUPPER_LC_uvchr(c);
1343}
1344
1345bool
1346Perl_is_uni_lower_lc(pTHX_ UV c)
1347{
1348 return isLOWER_LC_uvchr(c);
1349}
1350
1351bool
1352Perl_is_uni_cntrl_lc(pTHX_ UV c)
1353{
1354 return isCNTRL_LC_uvchr(c);
1355}
1356
1357bool
1358Perl_is_uni_graph_lc(pTHX_ UV c)
1359{
1360 return isGRAPH_LC_uvchr(c);
1361}
1362
1363bool
1364Perl_is_uni_print_lc(pTHX_ UV c)
1365{
1366 return isPRINT_LC_uvchr(c);
1367}
1368
1369bool
1370Perl_is_uni_punct_lc(pTHX_ UV c)
1371{
1372 return isPUNCT_LC_uvchr(c);
1373}
1374
1375bool
1376Perl_is_uni_xdigit_lc(pTHX_ UV c)
1377{
1378 return isXDIGIT_LC_uvchr(c);
1379}
1380
1381U32
1382Perl_to_uni_upper_lc(pTHX_ U32 c)
1383{
1384 /* XXX returns only the first character -- do not use XXX */
1385 /* XXX no locale support yet */
1386 STRLEN len;
1387 U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
1388 return (U32)to_uni_upper(c, tmpbuf, &len);
1389}
1390
1391U32
1392Perl_to_uni_title_lc(pTHX_ U32 c)
1393{
1394 /* XXX returns only the first character XXX -- do not use XXX */
1395 /* XXX no locale support yet */
1396 STRLEN len;
1397 U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
1398 return (U32)to_uni_title(c, tmpbuf, &len);
1399}
1400
1401U32
1402Perl_to_uni_lower_lc(pTHX_ U32 c)
1403{
1404 /* XXX returns only the first character -- do not use XXX */
1405 /* XXX no locale support yet */
1406 STRLEN len;
1407 U8 tmpbuf[UTF8_MAXBYTES_CASE+1];
1408 return (U32)to_uni_lower(c, tmpbuf, &len);
1409}
1410
1411bool
1412Perl_is_utf8_mark(pTHX_ const U8 *p)
1413{
1414 PERL_ARGS_ASSERT_IS_UTF8_MARK;
1415
1416 return _is_utf8_mark(p);
1417}
1418
1419/*
1420=for apidoc is_utf8_char
1421
1422Tests if some arbitrary number of bytes begins in a valid UTF-8
1423character. Note that an INVARIANT (i.e. ASCII on non-EBCDIC machines)
1424character is a valid UTF-8 character. The actual number of bytes in the UTF-8
1425character will be returned if it is valid, otherwise 0.
1426
1427This function is deprecated due to the possibility that malformed input could
1428cause reading beyond the end of the input buffer. Use L</isUTF8_CHAR>
1429instead.
1430
1431=cut */
1432
1433STRLEN
1434Perl_is_utf8_char(const U8 *s)
1435{
1436 PERL_ARGS_ASSERT_IS_UTF8_CHAR;
1437
1438 /* Assumes we have enough space, which is why this is deprecated. But the
1439 * strnlen() makes it safe for the common case of NUL-terminated strings */
1440 return isUTF8_CHAR(s, s + my_strnlen((char *) s, UTF8SKIP(s)));
1441}
1442
1443/*
1444=for apidoc is_utf8_char_buf
1445
1446This is identical to the macro L<perlapi/isUTF8_CHAR>.
1447
1448=cut */
1449
1450STRLEN
1451Perl_is_utf8_char_buf(const U8 *buf, const U8* buf_end)
1452{
1453
1454 PERL_ARGS_ASSERT_IS_UTF8_CHAR_BUF;
1455
1456 return isUTF8_CHAR(buf, buf_end);
1457}
1458
1459/* DEPRECATED!
1460 * Like L</utf8_to_uvuni_buf>(), but should only be called when it is known that
1461 * there are no malformations in the input UTF-8 string C<s>. Surrogates,
1462 * non-character code points, and non-Unicode code points are allowed */
1463
1464UV
1465Perl_valid_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1466{
1467 PERL_UNUSED_CONTEXT;
1468 PERL_ARGS_ASSERT_VALID_UTF8_TO_UVUNI;
1469
1470 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1471}
1472
1473/*
1474=for apidoc utf8_to_uvuni
1475
1476Returns the Unicode code point of the first character in the string C<s>
1477which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1478length, in bytes, of that character.
1479
1480Some, but not all, UTF-8 malformations are detected, and in fact, some
1481malformed input could cause reading beyond the end of the input buffer, which
1482is one reason why this function is deprecated. The other is that only in
1483extremely limited circumstances should the Unicode versus native code point be
1484of any interest to you. See L</utf8_to_uvuni_buf> for alternatives.
1485
1486If C<s> points to one of the detected malformations, and UTF8 warnings are
1487enabled, zero is returned and C<*retlen> is set (if C<retlen> doesn't point to
1488NULL) to -1. If those warnings are off, the computed value if well-defined (or
1489the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1490is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1491next possible position in C<s> that could begin a non-malformed character.
1492See L<perlapi/utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1493
1494=cut
1495*/
1496
1497UV
1498Perl_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1499{
1500 PERL_UNUSED_CONTEXT;
1501 PERL_ARGS_ASSERT_UTF8_TO_UVUNI;
1502
1503 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1504}
1505
1506/*
1507=for apidoc pad_compname_type
1508
1509Looks up the type of the lexical variable at position C<po> in the
1510currently-compiling pad. If the variable is typed, the stash of the
1511class to which it is typed is returned. If not, C<NULL> is returned.
1512
1513=cut
1514*/
1515
1516HV *
1517Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1518{
1519 return PAD_COMPNAME_TYPE(po);
1520}
1521
1522/* return ptr to little string in big string, NULL if not found */
1523/* The original version of this routine was donated by Corey Satten. */
1524
1525char *
1526Perl_instr(const char *big, const char *little)
1527{
1528 PERL_ARGS_ASSERT_INSTR;
1529
1530 return instr((char *) big, (char *) little);
1531}
1532
1533SV *
1534Perl_newSVsv(pTHX_ SV *const old)
1535{
1536 return newSVsv(old);
1537}
1538
1539bool
1540Perl_sv_utf8_downgrade(pTHX_ SV *const sv, const bool fail_ok)
1541{
1542 PERL_ARGS_ASSERT_SV_UTF8_DOWNGRADE;
1543
1544 return sv_utf8_downgrade(sv, fail_ok);
1545}
1546
1547char *
1548Perl_sv_2pvutf8(pTHX_ SV *sv, STRLEN *const lp)
1549{
1550 PERL_ARGS_ASSERT_SV_2PVUTF8;
1551
1552 return sv_2pvutf8(sv, lp);
1553}
1554
1555char *
1556Perl_sv_2pvbyte(pTHX_ SV *sv, STRLEN *const lp)
1557{
1558 PERL_ARGS_ASSERT_SV_2PVBYTE;
1559
1560 return sv_2pvbyte(sv, lp);
1561}
1562
1563GCC_DIAG_RESTORE
1564
1565#endif /* NO_MATHOMS */
1566
1567/*
1568 * ex: set ts=8 sts=4 sw=4 et:
1569 */