xref: /openbsd-src/gnu/usr.bin/perl/mathoms.c (revision 1ad61ae0a79a724d2d3ec69e69c8e1d1ff6b53a0)
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 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  * This file can't just be cleaned out periodically, because that would break
36  * builds with -DPERL_NO_SHORT_NAMES
37  *
38  * NOTE: ALL FUNCTIONS IN THIS FILE should have an entry with the 'b' flag in
39  * embed.fnc.
40  *
41  * To move a function to this file, simply cut and paste it here, and change
42  * its embed.fnc entry to additionally have the 'b' flag.  If, for some reason
43  * a function you'd like to be treated as mathoms can't be moved from its
44  * current place, simply enclose it between
45  *
46  * #ifndef NO_MATHOMS
47  *    ...
48  * #endif
49  *
50  * and add the 'b' flag in embed.fnc.
51  *
52  * The compilation of this file can be suppressed; see INSTALL
53  *
54  * Some blurb for perlapi.pod:
55 
56  head1 Obsolete backwards compatibility functions
57 
58 Some of these are also deprecated.  You can exclude these from
59 your compiled Perl by adding this option to Configure:
60 C<-Accflags='-DNO_MATHOMS'>
61 
62 =cut
63 
64  */
65 
66 
67 #include "EXTERN.h"
68 #define PERL_IN_MATHOMS_C
69 #include "perl.h"
70 
71 #ifdef NO_MATHOMS
72 /* ..." warning: ISO C forbids an empty source file"
73    So make sure we have something in here by processing the headers anyway.
74  */
75 #else
76 
77 /* The functions in this file should be able to call other deprecated functions
78  * without a compiler warning */
79 GCC_DIAG_IGNORE(-Wdeprecated-declarations)
80 
81 /* ref() is now a macro using Perl_doref;
82  * this version provided for binary compatibility only.
83  */
84 OP *
85 Perl_ref(pTHX_ OP *o, I32 type)
86 {
87     return doref(o, type, TRUE);
88 }
89 
90 /*
91 =for apidoc_section $SV
92 =for apidoc sv_unref
93 
94 Unsets the RV status of the SV, and decrements the reference count of
95 whatever was being referenced by the RV.  This can almost be thought of
96 as a reversal of C<newSVrv>.  This is C<sv_unref_flags> with the C<flag>
97 being zero.  See C<L</SvROK_off>>.
98 
99 =cut
100 */
101 
102 void
103 Perl_sv_unref(pTHX_ SV *sv)
104 {
105     PERL_ARGS_ASSERT_SV_UNREF;
106 
107     sv_unref_flags(sv, 0);
108 }
109 
110 /*
111 =for apidoc_section $tainting
112 =for apidoc sv_taint
113 
114 Taint an SV.  Use C<SvTAINTED_on> instead.
115 
116 =cut
117 */
118 
119 void
120 Perl_sv_taint(pTHX_ SV *sv)
121 {
122     PERL_ARGS_ASSERT_SV_TAINT;
123 
124     sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0);
125 }
126 
127 /* sv_2iv() is now a macro using Perl_sv_2iv_flags();
128  * this function provided for binary compatibility only
129  */
130 
131 IV
132 Perl_sv_2iv(pTHX_ SV *sv)
133 {
134     PERL_ARGS_ASSERT_SV_2IV;
135 
136     return sv_2iv_flags(sv, SV_GMAGIC);
137 }
138 
139 /* sv_2uv() is now a macro using Perl_sv_2uv_flags();
140  * this function provided for binary compatibility only
141  */
142 
143 UV
144 Perl_sv_2uv(pTHX_ SV *sv)
145 {
146     PERL_ARGS_ASSERT_SV_2UV;
147 
148     return sv_2uv_flags(sv, SV_GMAGIC);
149 }
150 
151 /* sv_2nv() is now a macro using Perl_sv_2nv_flags();
152  * this function provided for binary compatibility only
153  */
154 
155 NV
156 Perl_sv_2nv(pTHX_ SV *sv)
157 {
158     return sv_2nv_flags(sv, SV_GMAGIC);
159 }
160 
161 
162 /* sv_2pv() is now a macro using Perl_sv_2pv_flags();
163  * this function provided for binary compatibility only
164  */
165 
166 char *
167 Perl_sv_2pv(pTHX_ SV *sv, STRLEN *lp)
168 {
169     PERL_ARGS_ASSERT_SV_2PV;
170 
171     return sv_2pv_flags(sv, lp, SV_GMAGIC);
172 }
173 
174 /*
175 =for apidoc_section $SV
176 =for apidoc sv_2pv_nolen
177 
178 Like C<sv_2pv()>, but doesn't return the length too.  You should usually
179 use the macro wrapper C<SvPV_nolen(sv)> instead.
180 
181 =cut
182 */
183 
184 char *
185 Perl_sv_2pv_nolen(pTHX_ SV *sv)
186 {
187     PERL_ARGS_ASSERT_SV_2PV_NOLEN;
188     return sv_2pv(sv, NULL);
189 }
190 
191 /*
192 =for apidoc_section $SV
193 =for apidoc sv_2pvbyte_nolen
194 
195 Return a pointer to the byte-encoded representation of the SV.
196 May cause the SV to be downgraded from UTF-8 as a side-effect.
197 
198 Usually accessed via the C<SvPVbyte_nolen> macro.
199 
200 =cut
201 */
202 
203 char *
204 Perl_sv_2pvbyte_nolen(pTHX_ SV *sv)
205 {
206     PERL_ARGS_ASSERT_SV_2PVBYTE_NOLEN;
207 
208     return sv_2pvbyte(sv, NULL);
209 }
210 
211 /*
212 =for apidoc_section $SV
213 =for apidoc sv_2pvutf8_nolen
214 
215 Return a pointer to the UTF-8-encoded representation of the SV.
216 May cause the SV to be upgraded to UTF-8 as a side-effect.
217 
218 Usually accessed via the C<SvPVutf8_nolen> macro.
219 
220 =cut
221 */
222 
223 char *
224 Perl_sv_2pvutf8_nolen(pTHX_ SV *sv)
225 {
226     PERL_ARGS_ASSERT_SV_2PVUTF8_NOLEN;
227 
228     return sv_2pvutf8(sv, NULL);
229 }
230 
231 /*
232 =for apidoc_section $SV
233 =for apidoc sv_force_normal
234 
235 Undo various types of fakery on an SV: if the PV is a shared string, make
236 a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
237 an C<xpvmg>.  See also C<L</sv_force_normal_flags>>.
238 
239 =cut
240 */
241 
242 void
243 Perl_sv_force_normal(pTHX_ SV *sv)
244 {
245     PERL_ARGS_ASSERT_SV_FORCE_NORMAL;
246 
247     sv_force_normal_flags(sv, 0);
248 }
249 
250 /* sv_setsv() is now a macro using Perl_sv_setsv_flags();
251  * this function provided for binary compatibility only
252  */
253 
254 void
255 Perl_sv_setsv(pTHX_ SV *dsv, SV *ssv)
256 {
257     PERL_ARGS_ASSERT_SV_SETSV;
258 
259     sv_setsv_flags(dsv, ssv, SV_GMAGIC);
260 }
261 
262 /* sv_catpvn() is now a macro using Perl_sv_catpvn_flags();
263  * this function provided for binary compatibility only
264  */
265 
266 void
267 Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
268 {
269     PERL_ARGS_ASSERT_SV_CATPVN;
270 
271     sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC);
272 }
273 
274 void
275 Perl_sv_catpvn_mg(pTHX_ SV *dsv, const char *sstr, STRLEN len)
276 {
277     PERL_ARGS_ASSERT_SV_CATPVN_MG;
278 
279     sv_catpvn_flags(dsv,sstr,len,SV_GMAGIC|SV_SMAGIC);
280 }
281 
282 /* sv_catsv() is now a macro using Perl_sv_catsv_flags();
283  * this function provided for binary compatibility only
284  */
285 
286 void
287 Perl_sv_catsv(pTHX_ SV *dsv, SV *sstr)
288 {
289     PERL_ARGS_ASSERT_SV_CATSV;
290 
291     sv_catsv_flags(dsv, sstr, SV_GMAGIC);
292 }
293 
294 void
295 Perl_sv_catsv_mg(pTHX_ SV *dsv, SV *sstr)
296 {
297     PERL_ARGS_ASSERT_SV_CATSV_MG;
298 
299     sv_catsv_flags(dsv,sstr,SV_GMAGIC|SV_SMAGIC);
300 }
301 
302 /*
303 =for apidoc_section $SV
304 =for apidoc sv_iv
305 
306 A private implementation of the C<SvIVx> macro for compilers which can't
307 cope with complex macro expressions.  Always use the macro instead.
308 
309 =cut
310 */
311 
312 IV
313 Perl_sv_iv(pTHX_ SV *sv)
314 {
315     PERL_ARGS_ASSERT_SV_IV;
316 
317     if (SvIOK(sv)) {
318         if (SvIsUV(sv))
319             return (IV)SvUVX(sv);
320         return SvIVX(sv);
321     }
322     return sv_2iv(sv);
323 }
324 
325 /*
326 =for apidoc_section $SV
327 =for apidoc sv_uv
328 
329 A private implementation of the C<SvUVx> macro for compilers which can't
330 cope with complex macro expressions.  Always use the macro instead.
331 
332 =cut
333 */
334 
335 UV
336 Perl_sv_uv(pTHX_ SV *sv)
337 {
338     PERL_ARGS_ASSERT_SV_UV;
339 
340     if (SvIOK(sv)) {
341         if (SvIsUV(sv))
342             return SvUVX(sv);
343         return (UV)SvIVX(sv);
344     }
345     return sv_2uv(sv);
346 }
347 
348 /*
349 =for apidoc_section $SV
350 =for apidoc sv_nv
351 
352 A private implementation of the C<SvNVx> macro for compilers which can't
353 cope with complex macro expressions.  Always use the macro instead.
354 
355 =cut
356 */
357 
358 NV
359 Perl_sv_nv(pTHX_ SV *sv)
360 {
361     PERL_ARGS_ASSERT_SV_NV;
362 
363     if (SvNOK(sv))
364         return SvNVX(sv);
365     return sv_2nv(sv);
366 }
367 
368 /*
369 =for apidoc_section $SV
370 =for apidoc sv_pv
371 
372 Use the C<SvPV_nolen> macro instead
373 
374 =for apidoc_section $SV
375 =for apidoc sv_pvn
376 
377 A private implementation of the C<SvPV> macro for compilers which can't
378 cope with complex macro expressions.  Always use the macro instead.
379 
380 =cut
381 */
382 
383 char *
384 Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
385 {
386     PERL_ARGS_ASSERT_SV_PVN;
387 
388     if (SvPOK(sv)) {
389         *lp = SvCUR(sv);
390         return SvPVX(sv);
391     }
392     return sv_2pv(sv, lp);
393 }
394 
395 
396 char *
397 Perl_sv_pvn_nomg(pTHX_ SV *sv, STRLEN *lp)
398 {
399     PERL_ARGS_ASSERT_SV_PVN_NOMG;
400 
401     if (SvPOK(sv)) {
402         *lp = SvCUR(sv);
403         return SvPVX(sv);
404     }
405     return sv_2pv_flags(sv, lp, 0);
406 }
407 
408 /* sv_pv() is now a macro using SvPV_nolen();
409  * this function provided for binary compatibility only
410  */
411 
412 char *
413 Perl_sv_pv(pTHX_ SV *sv)
414 {
415     PERL_ARGS_ASSERT_SV_PV;
416 
417     if (SvPOK(sv))
418         return SvPVX(sv);
419 
420     return sv_2pv(sv, NULL);
421 }
422 
423 /* sv_pvn_force() is now a macro using Perl_sv_pvn_force_flags();
424  * this function provided for binary compatibility only
425  */
426 
427 char *
428 Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
429 {
430     PERL_ARGS_ASSERT_SV_PVN_FORCE;
431 
432     return sv_pvn_force_flags(sv, lp, SV_GMAGIC);
433 }
434 
435 /* sv_pvbyte () is now a macro using Perl_sv_2pv_flags();
436  * this function provided for binary compatibility only
437  */
438 
439 char *
440 Perl_sv_pvbyte(pTHX_ SV *sv)
441 {
442     PERL_ARGS_ASSERT_SV_PVBYTE;
443 
444     sv_utf8_downgrade(sv, FALSE);
445     return sv_pv(sv);
446 }
447 
448 /*
449 =for apidoc_section $SV
450 =for apidoc sv_pvbyte
451 
452 Use C<SvPVbyte_nolen> instead.
453 
454 =for apidoc sv_pvbyten
455 
456 A private implementation of the C<SvPVbyte> macro for compilers
457 which can't cope with complex macro expressions.  Always use the macro
458 instead.
459 
460 =cut
461 */
462 
463 char *
464 Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
465 {
466     PERL_ARGS_ASSERT_SV_PVBYTEN;
467 
468     sv_utf8_downgrade(sv, FALSE);
469     return sv_pvn(sv,lp);
470 }
471 
472 /* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
473  * this function provided for binary compatibility only
474  */
475 
476 char *
477 Perl_sv_pvutf8(pTHX_ SV *sv)
478 {
479     PERL_ARGS_ASSERT_SV_PVUTF8;
480 
481     sv_utf8_upgrade(sv);
482     return sv_pv(sv);
483 }
484 
485 /*
486 =for apidoc_section $SV
487 =for apidoc sv_pvutf8
488 
489 Use the C<SvPVutf8_nolen> macro instead
490 
491 =for apidoc sv_pvutf8n
492 
493 A private implementation of the C<SvPVutf8> macro for compilers
494 which can't cope with complex macro expressions.  Always use the macro
495 instead.
496 
497 =cut
498 */
499 
500 char *
501 Perl_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 
513 STRLEN
514 Perl_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 
521 int
522 Perl_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 MULTIPLICITY
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 
539 int
540 Perl_printf_nocontext(const char *format, ...)
541 {
542     dTHX;
543     va_list arglist;
544     int ret = 0;
545 
546 #ifdef MULTIPLICITY
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  */
562 NV
563 Perl_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. */
574 void
575 Perl_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. */
583 void
584 Perl_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 
591 void
592 Perl_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 
599 void
600 Perl_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_section $GV
609 =for apidoc gv_fetchmethod
610 
611 See L</gv_fetchmethod_autoload>.
612 
613 =cut
614 */
615 
616 GV *
617 Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
618 {
619     PERL_ARGS_ASSERT_GV_FETCHMETHOD;
620 
621     return gv_fetchmethod_autoload(stash, name, TRUE);
622 }
623 
624 HE *
625 Perl_hv_iternext(pTHX_ HV *hv)
626 {
627     PERL_ARGS_ASSERT_HV_ITERNEXT;
628 
629     return hv_iternext_flags(hv, 0);
630 }
631 
632 void
633 Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how)
634 {
635     PERL_ARGS_ASSERT_HV_MAGIC;
636 
637     sv_magic(MUTABLE_SV(hv), MUTABLE_SV(gv), how, NULL, 0);
638 }
639 
640 bool
641 Perl_do_open(pTHX_ GV *gv, const char *name, I32 len, int as_raw,
642              int rawmode, int rawperm, PerlIO *supplied_fp)
643 {
644     PERL_ARGS_ASSERT_DO_OPEN;
645 
646     return do_openn(gv, name, len, as_raw, rawmode, rawperm,
647                     supplied_fp, (SV **) NULL, 0);
648 }
649 
650 bool
651 Perl_do_open9(pTHX_ GV *gv, const char *name, I32 len, int
652 as_raw,
653               int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
654               I32 num_svs)
655 {
656     PERL_ARGS_ASSERT_DO_OPEN9;
657 
658     PERL_UNUSED_ARG(num_svs);
659     return do_openn(gv, name, len, as_raw, rawmode, rawperm,
660                     supplied_fp, &svs, 1);
661 }
662 
663 int
664 Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
665 {
666  /* The old body of this is now in non-LAYER part of perlio.c
667   * This is a stub for any XS code which might have been calling it.
668   */
669  const char *name = ":raw";
670 
671  PERL_ARGS_ASSERT_DO_BINMODE;
672 
673 #ifdef PERLIO_USING_CRLF
674  if (!(mode & O_BINARY))
675      name = ":crlf";
676 #endif
677  return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
678 }
679 
680 #ifndef OS2
681 bool
682 Perl_do_aexec(pTHX_ SV *really, SV **mark, SV **sp)
683 {
684     PERL_ARGS_ASSERT_DO_AEXEC;
685 
686     return do_aexec5(really, mark, sp, 0, 0);
687 }
688 #endif
689 
690 /* Backwards compatibility. */
691 int
692 Perl_init_i18nl14n(pTHX_ int printwarn)
693 {
694     return init_i18nl10n(printwarn);
695 }
696 
697 bool
698 Perl_is_utf8_string_loc(const U8 *s, const STRLEN len, const U8 **ep)
699 {
700     PERL_ARGS_ASSERT_IS_UTF8_STRING_LOC;
701 
702     return is_utf8_string_loclen(s, len, ep, 0);
703 }
704 
705 /*
706 =for apidoc_section $SV
707 =for apidoc sv_nolocking
708 
709 Dummy routine which "locks" an SV when there is no locking module present.
710 Exists to avoid test for a C<NULL> function pointer and because it could
711 potentially warn under some level of strict-ness.
712 
713 "Superseded" by C<sv_nosharing()>.
714 
715 =cut
716 */
717 
718 void
719 Perl_sv_nolocking(pTHX_ SV *sv)
720 {
721     PERL_UNUSED_CONTEXT;
722     PERL_UNUSED_ARG(sv);
723 }
724 
725 
726 /*
727 =for apidoc_section $SV
728 =for apidoc sv_nounlocking
729 
730 Dummy routine which "unlocks" an SV when there is no locking module present.
731 Exists to avoid test for a C<NULL> function pointer and because it could
732 potentially warn under some level of strict-ness.
733 
734 "Superseded" by C<sv_nosharing()>.
735 
736 =cut
737 
738 PERL_UNLOCK_HOOK in intrpvar.h is the macro that refers to this, and guarantees
739 that mathoms gets loaded.
740 
741 */
742 
743 void
744 Perl_sv_nounlocking(pTHX_ SV *sv)
745 {
746     PERL_UNUSED_CONTEXT;
747     PERL_UNUSED_ARG(sv);
748 }
749 
750 void
751 Perl_save_long(pTHX_ long int *longp)
752 {
753     PERL_ARGS_ASSERT_SAVE_LONG;
754 
755     SSCHECK(3);
756     SSPUSHLONG(*longp);
757     SSPUSHPTR(longp);
758     SSPUSHUV(SAVEt_LONG);
759 }
760 
761 void
762 Perl_save_nogv(pTHX_ GV *gv)
763 {
764     PERL_ARGS_ASSERT_SAVE_NOGV;
765 
766     SSCHECK(2);
767     SSPUSHPTR(gv);
768     SSPUSHUV(SAVEt_NSTAB);
769 }
770 
771 void
772 Perl_save_list(pTHX_ SV **sarg, I32 maxsarg)
773 {
774     I32 i;
775 
776     PERL_ARGS_ASSERT_SAVE_LIST;
777 
778     for (i = 1; i <= maxsarg; i++) {
779         SV *sv;
780         SvGETMAGIC(sarg[i]);
781         sv = newSV(0);
782         sv_setsv_nomg(sv,sarg[i]);
783         SSCHECK(3);
784         SSPUSHPTR(sarg[i]);		/* remember the pointer */
785         SSPUSHPTR(sv);			/* remember the value */
786         SSPUSHUV(SAVEt_ITEM);
787     }
788 }
789 
790 void
791 Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len)
792 {
793     PERL_ARGS_ASSERT_SV_USEPVN_MG;
794 
795     sv_usepvn_flags(sv,ptr,len, SV_SMAGIC);
796 }
797 
798 
799 void
800 Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len)
801 {
802     PERL_ARGS_ASSERT_SV_USEPVN;
803 
804     sv_usepvn_flags(sv,ptr,len, 0);
805 }
806 
807 /*
808 =for apidoc_section $pack
809 =for apidoc unpack_str
810 
811 The engine implementing C<unpack()> Perl function.  Note: parameters C<strbeg>,
812 C<new_s> and C<ocnt> are not used.  This call should not be used, use
813 C<unpackstring> instead.
814 
815 =cut */
816 
817 SSize_t
818 Perl_unpack_str(pTHX_ const char *pat, const char *patend, const char *s,
819                 const char *strbeg, const char *strend, char **new_s, I32 ocnt,
820                 U32 flags)
821 {
822     PERL_ARGS_ASSERT_UNPACK_STR;
823 
824     PERL_UNUSED_ARG(strbeg);
825     PERL_UNUSED_ARG(new_s);
826     PERL_UNUSED_ARG(ocnt);
827 
828     return unpackstring(pat, patend, s, strend, flags);
829 }
830 
831 /*
832 =for apidoc_section $pack
833 =for apidoc pack_cat
834 
835 The engine implementing C<pack()> Perl function.  Note: parameters
836 C<next_in_list> and C<flags> are not used.  This call should not be used; use
837 C<L</packlist>> instead.
838 
839 =cut
840 */
841 
842 void
843 Perl_pack_cat(pTHX_ SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
844 {
845     PERL_ARGS_ASSERT_PACK_CAT;
846 
847     PERL_UNUSED_ARG(next_in_list);
848     PERL_UNUSED_ARG(flags);
849 
850     packlist(cat, pat, patend, beglist, endlist);
851 }
852 
853 HE *
854 Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, U32 hash)
855 {
856   return (HE *)hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
857 }
858 
859 bool
860 Perl_hv_exists_ent(pTHX_ HV *hv, SV *keysv, U32 hash)
861 {
862     PERL_ARGS_ASSERT_HV_EXISTS_ENT;
863 
864     return cBOOL(hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash));
865 }
866 
867 HE *
868 Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, U32 hash)
869 {
870     PERL_ARGS_ASSERT_HV_FETCH_ENT;
871 
872     return (HE *)hv_common(hv, keysv, NULL, 0, 0,
873                      (lval ? HV_FETCH_LVALUE : 0), NULL, hash);
874 }
875 
876 SV *
877 Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash)
878 {
879     PERL_ARGS_ASSERT_HV_DELETE_ENT;
880 
881     return MUTABLE_SV(hv_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, NULL,
882                                 hash));
883 }
884 
885 SV**
886 Perl_hv_store_flags(pTHX_ HV *hv, const char *key, I32 klen, SV *val, U32 hash,
887                     int flags)
888 {
889     return (SV**) hv_common(hv, NULL, key, klen, flags,
890                             (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
891 }
892 
893 SV**
894 Perl_hv_store(pTHX_ HV *hv, const char *key, I32 klen_i32, SV *val, U32 hash)
895 {
896     STRLEN klen;
897     int flags;
898 
899     if (klen_i32 < 0) {
900         klen = -klen_i32;
901         flags = HVhek_UTF8;
902     } else {
903         klen = klen_i32;
904         flags = 0;
905     }
906     return (SV **) hv_common(hv, NULL, key, klen, flags,
907                              (HV_FETCH_ISSTORE|HV_FETCH_JUST_SV), val, hash);
908 }
909 
910 bool
911 Perl_hv_exists(pTHX_ HV *hv, const char *key, I32 klen_i32)
912 {
913     STRLEN klen;
914     int flags;
915 
916     PERL_ARGS_ASSERT_HV_EXISTS;
917 
918     if (klen_i32 < 0) {
919         klen = -klen_i32;
920         flags = HVhek_UTF8;
921     } else {
922         klen = klen_i32;
923         flags = 0;
924     }
925     return cBOOL(hv_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0));
926 }
927 
928 SV**
929 Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
930 {
931     STRLEN klen;
932     int flags;
933 
934     PERL_ARGS_ASSERT_HV_FETCH;
935 
936     if (klen_i32 < 0) {
937         klen = -klen_i32;
938         flags = HVhek_UTF8;
939     } else {
940         klen = klen_i32;
941         flags = 0;
942     }
943     return (SV **) hv_common(hv, NULL, key, klen, flags,
944                              lval ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE)
945                              : HV_FETCH_JUST_SV, NULL, 0);
946 }
947 
948 SV *
949 Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
950 {
951     STRLEN klen;
952     int k_flags;
953 
954     PERL_ARGS_ASSERT_HV_DELETE;
955 
956     if (klen_i32 < 0) {
957         klen = -klen_i32;
958         k_flags = HVhek_UTF8;
959     } else {
960         klen = klen_i32;
961         k_flags = 0;
962     }
963     return MUTABLE_SV(hv_common(hv, NULL, key, klen, k_flags, flags | HV_DELETE,
964                                 NULL, 0));
965 }
966 
967 AV *
968 Perl_newAV(pTHX)
969 {
970     return MUTABLE_AV(newSV_type(SVt_PVAV));
971     /* sv_upgrade does AvREAL_only():
972     AvALLOC(av) = 0;
973     AvARRAY(av) = NULL;
974     AvMAX(av) = AvFILLp(av) = -1; */
975 }
976 
977 HV *
978 Perl_newHV(pTHX)
979 {
980     HV * const hv = MUTABLE_HV(newSV_type(SVt_PVHV));
981     assert(!SvOK(hv));
982 
983     return hv;
984 }
985 
986 void
987 Perl_sv_insert(pTHX_ SV *const bigstr, const STRLEN offset, const STRLEN len,
988               const char *const little, const STRLEN littlelen)
989 {
990     PERL_ARGS_ASSERT_SV_INSERT;
991     sv_insert_flags(bigstr, offset, len, little, littlelen, SV_GMAGIC);
992 }
993 
994 void
995 Perl_save_freesv(pTHX_ SV *sv)
996 {
997     save_freesv(sv);
998 }
999 
1000 void
1001 Perl_save_mortalizesv(pTHX_ SV *sv)
1002 {
1003     PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
1004 
1005     save_mortalizesv(sv);
1006 }
1007 
1008 void
1009 Perl_save_freeop(pTHX_ OP *o)
1010 {
1011     save_freeop(o);
1012 }
1013 
1014 void
1015 Perl_save_freepv(pTHX_ char *pv)
1016 {
1017     save_freepv(pv);
1018 }
1019 
1020 void
1021 Perl_save_op(pTHX)
1022 {
1023     save_op();
1024 }
1025 
1026 #ifdef PERL_DONT_CREATE_GVSV
1027 GV *
1028 Perl_gv_SVadd(pTHX_ GV *gv)
1029 {
1030     return gv_SVadd(gv);
1031 }
1032 #endif
1033 
1034 GV *
1035 Perl_gv_AVadd(pTHX_ GV *gv)
1036 {
1037     return gv_AVadd(gv);
1038 }
1039 
1040 GV *
1041 Perl_gv_HVadd(pTHX_ GV *gv)
1042 {
1043     return gv_HVadd(gv);
1044 }
1045 
1046 GV *
1047 Perl_gv_IOadd(pTHX_ GV *gv)
1048 {
1049     return gv_IOadd(gv);
1050 }
1051 
1052 IO *
1053 Perl_newIO(pTHX)
1054 {
1055     return MUTABLE_IO(newSV_type(SVt_PVIO));
1056 }
1057 
1058 I32
1059 Perl_my_stat(pTHX)
1060 {
1061     return my_stat_flags(SV_GMAGIC);
1062 }
1063 
1064 I32
1065 Perl_my_lstat(pTHX)
1066 {
1067     return my_lstat_flags(SV_GMAGIC);
1068 }
1069 
1070 I32
1071 Perl_sv_eq(pTHX_ SV *sv1, SV *sv2)
1072 {
1073     return sv_eq_flags(sv1, sv2, SV_GMAGIC);
1074 }
1075 
1076 #ifdef USE_LOCALE_COLLATE
1077 char *
1078 Perl_sv_collxfrm(pTHX_ SV *const sv, STRLEN *const nxp)
1079 {
1080     PERL_ARGS_ASSERT_SV_COLLXFRM;
1081     return sv_collxfrm_flags(sv, nxp, SV_GMAGIC);
1082 }
1083 
1084 char *
1085 Perl_mem_collxfrm(pTHX_ const char *input_string, STRLEN len, STRLEN *xlen)
1086 {
1087     /* This function is retained for compatibility in case someone outside core
1088      * is using this (but it is undocumented) */
1089 
1090     PERL_ARGS_ASSERT_MEM_COLLXFRM;
1091 
1092     return _mem_collxfrm(input_string, len, xlen, FALSE);
1093 }
1094 
1095 #endif
1096 
1097 bool
1098 Perl_sv_2bool(pTHX_ SV *const sv)
1099 {
1100     PERL_ARGS_ASSERT_SV_2BOOL;
1101     return sv_2bool_flags(sv, SV_GMAGIC);
1102 }
1103 
1104 
1105 /*
1106 =for apidoc_section $custom
1107 =for apidoc custom_op_name
1108 Return the name for a given custom op.  This was once used by the C<OP_NAME>
1109 macro, but is no longer: it has only been kept for compatibility, and
1110 should not be used.
1111 
1112 =for apidoc custom_op_desc
1113 Return the description of a given custom op.  This was once used by the
1114 C<OP_DESC> macro, but is no longer: it has only been kept for
1115 compatibility, and should not be used.
1116 
1117 =cut
1118 */
1119 
1120 const char*
1121 Perl_custom_op_name(pTHX_ const OP* o)
1122 {
1123     PERL_ARGS_ASSERT_CUSTOM_OP_NAME;
1124     return XopENTRYCUSTOM(o, xop_name);
1125 }
1126 
1127 const char*
1128 Perl_custom_op_desc(pTHX_ const OP* o)
1129 {
1130     PERL_ARGS_ASSERT_CUSTOM_OP_DESC;
1131     return XopENTRYCUSTOM(o, xop_desc);
1132 }
1133 
1134 CV *
1135 Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
1136 {
1137     return newATTRSUB(floor, o, proto, NULL, block);
1138 }
1139 
1140 SV *
1141 Perl_sv_mortalcopy(pTHX_ SV *const oldsv)
1142 {
1143     return Perl_sv_mortalcopy_flags(aTHX_ oldsv, SV_GMAGIC);
1144 }
1145 
1146 void
1147 Perl_sv_copypv(pTHX_ SV *const dsv, SV *const ssv)
1148 {
1149     PERL_ARGS_ASSERT_SV_COPYPV;
1150 
1151     sv_copypv_flags(dsv, ssv, SV_GMAGIC);
1152 }
1153 
1154 UV      /* Made into a function, so can be deprecated */
1155 NATIVE_TO_NEED(const UV enc, const UV ch)
1156 {
1157     PERL_UNUSED_ARG(enc);
1158     return ch;
1159 }
1160 
1161 UV      /* Made into a function, so can be deprecated */
1162 ASCII_TO_NEED(const UV enc, const UV ch)
1163 {
1164     PERL_UNUSED_ARG(enc);
1165     return ch;
1166 }
1167 
1168 /*
1169 =for apidoc_section $unicode
1170 =for apidoc is_utf8_char
1171 
1172 Tests if some arbitrary number of bytes begins in a valid UTF-8
1173 character.  Note that an INVARIANT (i.e. ASCII on non-EBCDIC machines)
1174 character is a valid UTF-8 character.  The actual number of bytes in the UTF-8
1175 character will be returned if it is valid, otherwise 0.
1176 
1177 This function is deprecated due to the possibility that malformed input could
1178 cause reading beyond the end of the input buffer.  Use L</isUTF8_CHAR>
1179 instead.
1180 
1181 =cut */
1182 
1183 STRLEN
1184 Perl_is_utf8_char(const U8 *s)
1185 {
1186     PERL_ARGS_ASSERT_IS_UTF8_CHAR;
1187 
1188     /* Assumes we have enough space, which is why this is deprecated.  But the
1189      * UTF8_CHK_SKIP(s)) makes it safe for the common case of NUL-terminated
1190      * strings */
1191     return isUTF8_CHAR(s, s + UTF8_CHK_SKIP(s));
1192 }
1193 
1194 /*
1195 =for apidoc_section $unicode
1196 =for apidoc is_utf8_char_buf
1197 
1198 This is identical to the macro L<perlapi/isUTF8_CHAR>.
1199 
1200 =cut */
1201 
1202 STRLEN
1203 Perl_is_utf8_char_buf(const U8 *buf, const U8* buf_end)
1204 {
1205 
1206     PERL_ARGS_ASSERT_IS_UTF8_CHAR_BUF;
1207 
1208     return isUTF8_CHAR(buf, buf_end);
1209 }
1210 
1211 /* DEPRECATED!
1212  * Like L</utf8_to_uvuni_buf>(), but should only be called when it is known that
1213  * there are no malformations in the input UTF-8 string C<s>.  Surrogates,
1214  * non-character code points, and non-Unicode code points are allowed */
1215 
1216 UV
1217 Perl_valid_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1218 {
1219     PERL_UNUSED_CONTEXT;
1220     PERL_ARGS_ASSERT_VALID_UTF8_TO_UVUNI;
1221 
1222     return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1223 }
1224 
1225 /*
1226 =for apidoc_section $unicode
1227 =for apidoc utf8_to_uvuni
1228 
1229 Returns the Unicode code point of the first character in the string C<s>
1230 which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1231 length, in bytes, of that character.
1232 
1233 Some, but not all, UTF-8 malformations are detected, and in fact, some
1234 malformed input could cause reading beyond the end of the input buffer, which
1235 is one reason why this function is deprecated.  The other is that only in
1236 extremely limited circumstances should the Unicode versus native code point be
1237 of any interest to you.  See L</utf8_to_uvuni_buf> for alternatives.
1238 
1239 If C<s> points to one of the detected malformations, and UTF8 warnings are
1240 enabled, zero is returned and C<*retlen> is set (if C<retlen> doesn't point to
1241 NULL) to -1.  If those warnings are off, the computed value if well-defined (or
1242 the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1243 is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1244 next possible position in C<s> that could begin a non-malformed character.
1245 See L<perlapi/utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1246 
1247 =cut
1248 */
1249 
1250 UV
1251 Perl_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1252 {
1253     PERL_UNUSED_CONTEXT;
1254     PERL_ARGS_ASSERT_UTF8_TO_UVUNI;
1255 
1256     return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1257 }
1258 
1259 /*
1260 =for apidoc_section $pad
1261 =for apidoc pad_compname_type
1262 
1263 Looks up the type of the lexical variable at position C<po> in the
1264 currently-compiling pad.  If the variable is typed, the stash of the
1265 class to which it is typed is returned.  If not, C<NULL> is returned.
1266 
1267 Use L<perlintern/C<PAD_COMPNAME_TYPE>> instead.
1268 
1269 =cut
1270 */
1271 
1272 HV *
1273 Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1274 {
1275     return PAD_COMPNAME_TYPE(po);
1276 }
1277 
1278 /* return ptr to little string in big string, NULL if not found */
1279 /* The original version of this routine was donated by Corey Satten. */
1280 
1281 char *
1282 Perl_instr(const char *big, const char *little)
1283 {
1284     PERL_ARGS_ASSERT_INSTR;
1285 
1286     return instr(big, little);
1287 }
1288 
1289 SV *
1290 Perl_newSVsv(pTHX_ SV *const old)
1291 {
1292     return newSVsv(old);
1293 }
1294 
1295 bool
1296 Perl_sv_utf8_downgrade(pTHX_ SV *const sv, const bool fail_ok)
1297 {
1298     PERL_ARGS_ASSERT_SV_UTF8_DOWNGRADE;
1299 
1300     return sv_utf8_downgrade(sv, fail_ok);
1301 }
1302 
1303 char *
1304 Perl_sv_2pvutf8(pTHX_ SV *sv, STRLEN *const lp)
1305 {
1306     PERL_ARGS_ASSERT_SV_2PVUTF8;
1307 
1308     return sv_2pvutf8(sv, lp);
1309 }
1310 
1311 char *
1312 Perl_sv_2pvbyte(pTHX_ SV *sv, STRLEN *const lp)
1313 {
1314     PERL_ARGS_ASSERT_SV_2PVBYTE;
1315 
1316     return sv_2pvbyte(sv, lp);
1317 }
1318 
1319 U8 *
1320 Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv)
1321 {
1322     PERL_ARGS_ASSERT_UVUNI_TO_UTF8;
1323 
1324     return uvoffuni_to_utf8_flags(d, uv, 0);
1325 }
1326 
1327 /*
1328 =for apidoc_section $unicode
1329 =for apidoc utf8n_to_uvuni
1330 
1331 Instead use L<perlapi/utf8_to_uvchr_buf>, or rarely, L<perlapi/utf8n_to_uvchr>.
1332 
1333 This function was useful for code that wanted to handle both EBCDIC and
1334 ASCII platforms with Unicode properties, but starting in Perl v5.20, the
1335 distinctions between the platforms have mostly been made invisible to most
1336 code, so this function is quite unlikely to be what you want.  If you do need
1337 this precise functionality, use instead
1338 C<L<NATIVE_TO_UNI(utf8_to_uvchr_buf(...))|perlapi/utf8_to_uvchr_buf>>
1339 or C<L<NATIVE_TO_UNI(utf8n_to_uvchr(...))|perlapi/utf8n_to_uvchr>>.
1340 
1341 =cut
1342 */
1343 
1344 UV
1345 Perl_utf8n_to_uvuni(pTHX_ const U8 *s, STRLEN curlen, STRLEN *retlen, U32 flags)
1346 {
1347     PERL_ARGS_ASSERT_UTF8N_TO_UVUNI;
1348 
1349     return NATIVE_TO_UNI(utf8n_to_uvchr(s, curlen, retlen, flags));
1350 }
1351 
1352 /*
1353 =for apidoc_section $unicode
1354 =for apidoc uvuni_to_utf8_flags
1355 
1356 Instead you almost certainly want to use L<perlapi/uvchr_to_utf8> or
1357 L<perlapi/uvchr_to_utf8_flags>.
1358 
1359 This function is a deprecated synonym for L</uvoffuni_to_utf8_flags>,
1360 which itself, while not deprecated, should be used only in isolated
1361 circumstances.  These functions were useful for code that wanted to handle
1362 both EBCDIC and ASCII platforms with Unicode properties, but starting in Perl
1363 v5.20, the distinctions between the platforms have mostly been made invisible
1364 to most code, so this function is quite unlikely to be what you want.
1365 
1366 =cut
1367 */
1368 
1369 U8 *
1370 Perl_uvuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
1371 {
1372     PERL_ARGS_ASSERT_UVUNI_TO_UTF8_FLAGS;
1373 
1374     return uvoffuni_to_utf8_flags(d, uv, flags);
1375 }
1376 
1377 /*
1378 =for apidoc_section $unicode
1379 =for apidoc utf8_to_uvchr
1380 
1381 Returns the native code point of the first character in the string C<s>
1382 which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1383 length, in bytes, of that character.
1384 
1385 Some, but not all, UTF-8 malformations are detected, and in fact, some
1386 malformed input could cause reading beyond the end of the input buffer, which
1387 is why this function is deprecated.  Use L</utf8_to_uvchr_buf> instead.
1388 
1389 If C<s> points to one of the detected malformations, and UTF8 warnings are
1390 enabled, zero is returned and C<*retlen> is set (if C<retlen> isn't
1391 C<NULL>) to -1.  If those warnings are off, the computed value if well-defined (or
1392 the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1393 is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1394 next possible position in C<s> that could begin a non-malformed character.
1395 See L</utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1396 
1397 =cut
1398 */
1399 
1400 UV
1401 Perl_utf8_to_uvchr(pTHX_ const U8 *s, STRLEN *retlen)
1402 {
1403     PERL_ARGS_ASSERT_UTF8_TO_UVCHR;
1404 
1405     /* This function is unsafe if malformed UTF-8 input is given it, which is
1406      * why the function is deprecated.  If the first byte of the input
1407      * indicates that there are more bytes remaining in the sequence that forms
1408      * the character than there are in the input buffer, it can read past the
1409      * end.  But we can make it safe if the input string happens to be
1410      * NUL-terminated, as many strings in Perl are, by refusing to read past a
1411      * NUL, which is what UTF8_CHK_SKIP() does.  A NUL indicates the start of
1412      * the next character anyway.  If the input isn't NUL-terminated, the
1413      * function remains unsafe, as it always has been. */
1414 
1415     return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
1416 }
1417 
1418 GCC_DIAG_RESTORE
1419 
1420 #endif /* NO_MATHOMS */
1421 
1422 /*
1423  * ex: set ts=8 sts=4 sw=4 et:
1424  */
1425