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