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 *
Perl_ref(pTHX_ OP * o,I32 type)82 Perl_ref(pTHX_ OP *o, I32 type)
83 {
84 return doref(o, type, TRUE);
85 }
86
87 /*
88 =for apidoc_section $SV
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
Perl_sv_unref(pTHX_ SV * sv)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
Perl_sv_taint(pTHX_ SV * sv)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
Perl_sv_2iv(pTHX_ SV * sv)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
Perl_sv_2uv(pTHX_ SV * sv)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
Perl_sv_2nv(pTHX_ SV * sv)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 *
Perl_sv_2pv(pTHX_ SV * sv,STRLEN * lp)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 *
Perl_sv_2pv_nolen(pTHX_ SV * sv)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 *
Perl_sv_2pvbyte_nolen(pTHX_ SV * sv)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 *
Perl_sv_2pvutf8_nolen(pTHX_ SV * sv)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
Perl_sv_force_normal(pTHX_ SV * sv)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
Perl_sv_setsv(pTHX_ SV * dsv,SV * ssv)247 Perl_sv_setsv(pTHX_ SV *dsv, SV *ssv)
248 {
249 PERL_ARGS_ASSERT_SV_SETSV;
250
251 sv_setsv_flags(dsv, ssv, 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
Perl_sv_catpvn(pTHX_ SV * dsv,const char * sstr,STRLEN slen)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 void
Perl_sv_catpvn_mg(pTHX_ SV * dsv,const char * sstr,STRLEN len)267 Perl_sv_catpvn_mg(pTHX_ SV *dsv, const char *sstr, STRLEN len)
268 {
269 PERL_ARGS_ASSERT_SV_CATPVN_MG;
270
271 sv_catpvn_flags(dsv,sstr,len,SV_GMAGIC|SV_SMAGIC);
272 }
273
274 /* sv_catsv() is now a macro using Perl_sv_catsv_flags();
275 * this function provided for binary compatibility only
276 */
277
278 void
Perl_sv_catsv(pTHX_ SV * dsv,SV * sstr)279 Perl_sv_catsv(pTHX_ SV *dsv, SV *sstr)
280 {
281 PERL_ARGS_ASSERT_SV_CATSV;
282
283 sv_catsv_flags(dsv, sstr, SV_GMAGIC);
284 }
285
286 void
Perl_sv_catsv_mg(pTHX_ SV * dsv,SV * sstr)287 Perl_sv_catsv_mg(pTHX_ SV *dsv, SV *sstr)
288 {
289 PERL_ARGS_ASSERT_SV_CATSV_MG;
290
291 sv_catsv_flags(dsv,sstr,SV_GMAGIC|SV_SMAGIC);
292 }
293
294 /*
295 =for apidoc sv_iv
296
297 A private implementation of the C<SvIVx> macro for compilers which can't
298 cope with complex macro expressions. Always use the macro instead.
299
300 =cut
301 */
302
303 IV
Perl_sv_iv(pTHX_ SV * sv)304 Perl_sv_iv(pTHX_ SV *sv)
305 {
306 PERL_ARGS_ASSERT_SV_IV;
307
308 if (SvIOK(sv)) {
309 if (SvIsUV(sv))
310 return (IV)SvUVX(sv);
311 return SvIVX(sv);
312 }
313 return sv_2iv(sv);
314 }
315
316 /*
317 =for apidoc sv_uv
318
319 A private implementation of the C<SvUVx> macro for compilers which can't
320 cope with complex macro expressions. Always use the macro instead.
321
322 =cut
323 */
324
325 UV
Perl_sv_uv(pTHX_ SV * sv)326 Perl_sv_uv(pTHX_ SV *sv)
327 {
328 PERL_ARGS_ASSERT_SV_UV;
329
330 if (SvIOK(sv)) {
331 if (SvIsUV(sv))
332 return SvUVX(sv);
333 return (UV)SvIVX(sv);
334 }
335 return sv_2uv(sv);
336 }
337
338 /*
339 =for apidoc sv_nv
340
341 A private implementation of the C<SvNVx> macro for compilers which can't
342 cope with complex macro expressions. Always use the macro instead.
343
344 =cut
345 */
346
347 NV
Perl_sv_nv(pTHX_ SV * sv)348 Perl_sv_nv(pTHX_ SV *sv)
349 {
350 PERL_ARGS_ASSERT_SV_NV;
351
352 if (SvNOK(sv))
353 return SvNVX(sv);
354 return sv_2nv(sv);
355 }
356
357 /*
358 =for apidoc sv_pv
359
360 Use the C<SvPV_nolen> macro instead
361
362 =for apidoc sv_pvn
363
364 A private implementation of the C<SvPV> macro for compilers which can't
365 cope with complex macro expressions. Always use the macro instead.
366
367 =cut
368 */
369
370 char *
Perl_sv_pvn(pTHX_ SV * sv,STRLEN * lp)371 Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
372 {
373 PERL_ARGS_ASSERT_SV_PVN;
374
375 if (SvPOK(sv)) {
376 *lp = SvCUR(sv);
377 return SvPVX(sv);
378 }
379 return sv_2pv(sv, lp);
380 }
381
382
383 char *
Perl_sv_pvn_nomg(pTHX_ SV * sv,STRLEN * lp)384 Perl_sv_pvn_nomg(pTHX_ SV *sv, STRLEN *lp)
385 {
386 PERL_ARGS_ASSERT_SV_PVN_NOMG;
387
388 if (SvPOK(sv)) {
389 *lp = SvCUR(sv);
390 return SvPVX(sv);
391 }
392 return sv_2pv_flags(sv, lp, 0);
393 }
394
395 /* sv_pv() is now a macro using SvPV_nolen();
396 * this function provided for binary compatibility only
397 */
398
399 char *
Perl_sv_pv(pTHX_ SV * sv)400 Perl_sv_pv(pTHX_ SV *sv)
401 {
402 PERL_ARGS_ASSERT_SV_PV;
403
404 if (SvPOK(sv))
405 return SvPVX(sv);
406
407 return sv_2pv(sv, NULL);
408 }
409
410 /* sv_pvn_force() is now a macro using Perl_sv_pvn_force_flags();
411 * this function provided for binary compatibility only
412 */
413
414 char *
Perl_sv_pvn_force(pTHX_ SV * sv,STRLEN * lp)415 Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
416 {
417 PERL_ARGS_ASSERT_SV_PVN_FORCE;
418
419 return sv_pvn_force_flags(sv, lp, SV_GMAGIC);
420 }
421
422 /* sv_pvbyte () is now a macro using Perl_sv_2pv_flags();
423 * this function provided for binary compatibility only
424 */
425
426 char *
Perl_sv_pvbyte(pTHX_ SV * sv)427 Perl_sv_pvbyte(pTHX_ SV *sv)
428 {
429 PERL_ARGS_ASSERT_SV_PVBYTE;
430
431 sv_utf8_downgrade(sv, FALSE);
432 return sv_pv(sv);
433 }
434
435 /*
436 =for apidoc sv_pvbyte
437
438 Use C<SvPVbyte_nolen> instead.
439
440 =for apidoc sv_pvbyten
441
442 A private implementation of the C<SvPVbyte> macro for compilers
443 which can't cope with complex macro expressions. Always use the macro
444 instead.
445
446 =cut
447 */
448
449 char *
Perl_sv_pvbyten(pTHX_ SV * sv,STRLEN * lp)450 Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
451 {
452 PERL_ARGS_ASSERT_SV_PVBYTEN;
453
454 sv_utf8_downgrade(sv, FALSE);
455 return sv_pvn(sv,lp);
456 }
457
458 /* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
459 * this function provided for binary compatibility only
460 */
461
462 char *
Perl_sv_pvutf8(pTHX_ SV * sv)463 Perl_sv_pvutf8(pTHX_ SV *sv)
464 {
465 PERL_ARGS_ASSERT_SV_PVUTF8;
466
467 sv_utf8_upgrade(sv);
468 return sv_pv(sv);
469 }
470
471 /*
472 =for apidoc sv_pvutf8
473
474 Use the C<SvPVutf8_nolen> macro instead
475
476 =for apidoc sv_pvutf8n
477
478 A private implementation of the C<SvPVutf8> macro for compilers
479 which can't cope with complex macro expressions. Always use the macro
480 instead.
481
482 =cut
483 */
484
485 char *
Perl_sv_pvutf8n(pTHX_ SV * sv,STRLEN * lp)486 Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
487 {
488 PERL_ARGS_ASSERT_SV_PVUTF8N;
489
490 sv_utf8_upgrade(sv);
491 return sv_pvn(sv,lp);
492 }
493
494 /* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
495 * this function provided for binary compatibility only
496 */
497
498 STRLEN
Perl_sv_utf8_upgrade(pTHX_ SV * sv)499 Perl_sv_utf8_upgrade(pTHX_ SV *sv)
500 {
501 PERL_ARGS_ASSERT_SV_UTF8_UPGRADE;
502
503 return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
504 }
505
506 int
Perl_fprintf_nocontext(PerlIO * stream,const char * format,...)507 Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...)
508 {
509 int ret = 0;
510 va_list arglist;
511
512 /* Easier to special case this here than in embed.pl. (Look at what it
513 generates for proto.h) */
514 #ifdef PERL_IMPLICIT_CONTEXT
515 PERL_ARGS_ASSERT_FPRINTF_NOCONTEXT;
516 #endif
517
518 va_start(arglist, format);
519 ret = PerlIO_vprintf(stream, format, arglist);
520 va_end(arglist);
521 return ret;
522 }
523
524 int
Perl_printf_nocontext(const char * format,...)525 Perl_printf_nocontext(const char *format, ...)
526 {
527 dTHX;
528 va_list arglist;
529 int ret = 0;
530
531 #ifdef PERL_IMPLICIT_CONTEXT
532 PERL_ARGS_ASSERT_PRINTF_NOCONTEXT;
533 #endif
534
535 va_start(arglist, format);
536 ret = PerlIO_vprintf(PerlIO_stdout(), format, arglist);
537 va_end(arglist);
538 return ret;
539 }
540
541 #if defined(HUGE_VAL) || (defined(USE_LONG_DOUBLE) && defined(HUGE_VALL))
542 /*
543 * This hack is to force load of "huge" support from libm.a
544 * So it is in perl for (say) POSIX to use.
545 * Needed for SunOS with Sun's 'acc' for example.
546 */
547 NV
Perl_huge(void)548 Perl_huge(void)
549 {
550 # if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
551 return HUGE_VALL;
552 # else
553 return HUGE_VAL;
554 # endif
555 }
556 #endif
557
558 /* compatibility with versions <= 5.003. */
559 void
Perl_gv_fullname(pTHX_ SV * sv,const GV * gv)560 Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
561 {
562 PERL_ARGS_ASSERT_GV_FULLNAME;
563
564 gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
565 }
566
567 /* compatibility with versions <= 5.003. */
568 void
Perl_gv_efullname(pTHX_ SV * sv,const GV * gv)569 Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
570 {
571 PERL_ARGS_ASSERT_GV_EFULLNAME;
572
573 gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
574 }
575
576 void
Perl_gv_fullname3(pTHX_ SV * sv,const GV * gv,const char * prefix)577 Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
578 {
579 PERL_ARGS_ASSERT_GV_FULLNAME3;
580
581 gv_fullname4(sv, gv, prefix, TRUE);
582 }
583
584 void
Perl_gv_efullname3(pTHX_ SV * sv,const GV * gv,const char * prefix)585 Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
586 {
587 PERL_ARGS_ASSERT_GV_EFULLNAME3;
588
589 gv_efullname4(sv, gv, prefix, TRUE);
590 }
591
592 /*
593 =for apidoc_section $GV
594 =for apidoc gv_fetchmethod
595
596 See L</gv_fetchmethod_autoload>.
597
598 =cut
599 */
600
601 GV *
Perl_gv_fetchmethod(pTHX_ HV * stash,const char * name)602 Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
603 {
604 PERL_ARGS_ASSERT_GV_FETCHMETHOD;
605
606 return gv_fetchmethod_autoload(stash, name, TRUE);
607 }
608
609 HE *
Perl_hv_iternext(pTHX_ HV * hv)610 Perl_hv_iternext(pTHX_ HV *hv)
611 {
612 PERL_ARGS_ASSERT_HV_ITERNEXT;
613
614 return hv_iternext_flags(hv, 0);
615 }
616
617 void
Perl_hv_magic(pTHX_ HV * hv,GV * gv,int how)618 Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how)
619 {
620 PERL_ARGS_ASSERT_HV_MAGIC;
621
622 sv_magic(MUTABLE_SV(hv), MUTABLE_SV(gv), how, NULL, 0);
623 }
624
625 bool
Perl_do_open(pTHX_ GV * gv,const char * name,I32 len,int as_raw,int rawmode,int rawperm,PerlIO * supplied_fp)626 Perl_do_open(pTHX_ GV *gv, const char *name, I32 len, int as_raw,
627 int rawmode, int rawperm, PerlIO *supplied_fp)
628 {
629 PERL_ARGS_ASSERT_DO_OPEN;
630
631 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
632 supplied_fp, (SV **) NULL, 0);
633 }
634
635 bool
Perl_do_open9(pTHX_ GV * gv,const char * name,I32 len,int as_raw,int rawmode,int rawperm,PerlIO * supplied_fp,SV * svs,I32 num_svs)636 Perl_do_open9(pTHX_ GV *gv, const char *name, I32 len, int
637 as_raw,
638 int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
639 I32 num_svs)
640 {
641 PERL_ARGS_ASSERT_DO_OPEN9;
642
643 PERL_UNUSED_ARG(num_svs);
644 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
645 supplied_fp, &svs, 1);
646 }
647
648 int
Perl_do_binmode(pTHX_ PerlIO * fp,int iotype,int mode)649 Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
650 {
651 /* The old body of this is now in non-LAYER part of perlio.c
652 * This is a stub for any XS code which might have been calling it.
653 */
654 const char *name = ":raw";
655
656 PERL_ARGS_ASSERT_DO_BINMODE;
657
658 #ifdef PERLIO_USING_CRLF
659 if (!(mode & O_BINARY))
660 name = ":crlf";
661 #endif
662 return PerlIO_binmode(aTHX_ fp, iotype, mode, name);
663 }
664
665 #ifndef OS2
666 bool
Perl_do_aexec(pTHX_ SV * really,SV ** mark,SV ** sp)667 Perl_do_aexec(pTHX_ SV *really, SV **mark, SV **sp)
668 {
669 PERL_ARGS_ASSERT_DO_AEXEC;
670
671 return do_aexec5(really, mark, sp, 0, 0);
672 }
673 #endif
674
675 /* Backwards compatibility. */
676 int
Perl_init_i18nl14n(pTHX_ int printwarn)677 Perl_init_i18nl14n(pTHX_ int printwarn)
678 {
679 return init_i18nl10n(printwarn);
680 }
681
682 bool
Perl_is_utf8_string_loc(const U8 * s,const STRLEN len,const U8 ** ep)683 Perl_is_utf8_string_loc(const U8 *s, const STRLEN len, const U8 **ep)
684 {
685 PERL_ARGS_ASSERT_IS_UTF8_STRING_LOC;
686
687 return is_utf8_string_loclen(s, len, ep, 0);
688 }
689
690 /*
691 =for apidoc_section $SV
692 =for apidoc sv_nolocking
693
694 Dummy routine which "locks" an SV when there is no locking module present.
695 Exists to avoid test for a C<NULL> function pointer and because it could
696 potentially warn under some level of strict-ness.
697
698 "Superseded" by C<sv_nosharing()>.
699
700 =cut
701 */
702
703 void
Perl_sv_nolocking(pTHX_ SV * sv)704 Perl_sv_nolocking(pTHX_ SV *sv)
705 {
706 PERL_UNUSED_CONTEXT;
707 PERL_UNUSED_ARG(sv);
708 }
709
710
711 /*
712 =for apidoc sv_nounlocking
713
714 Dummy routine which "unlocks" an SV when there is no locking module present.
715 Exists to avoid test for a C<NULL> function pointer and because it could
716 potentially warn under some level of strict-ness.
717
718 "Superseded" by C<sv_nosharing()>.
719
720 =cut
721
722 PERL_UNLOCK_HOOK in intrpvar.h is the macro that refers to this, and guarantees
723 that mathoms gets loaded.
724
725 */
726
727 void
Perl_sv_nounlocking(pTHX_ SV * sv)728 Perl_sv_nounlocking(pTHX_ SV *sv)
729 {
730 PERL_UNUSED_CONTEXT;
731 PERL_UNUSED_ARG(sv);
732 }
733
734 void
Perl_save_long(pTHX_ long int * longp)735 Perl_save_long(pTHX_ long int *longp)
736 {
737 PERL_ARGS_ASSERT_SAVE_LONG;
738
739 SSCHECK(3);
740 SSPUSHLONG(*longp);
741 SSPUSHPTR(longp);
742 SSPUSHUV(SAVEt_LONG);
743 }
744
745 void
Perl_save_nogv(pTHX_ GV * gv)746 Perl_save_nogv(pTHX_ GV *gv)
747 {
748 PERL_ARGS_ASSERT_SAVE_NOGV;
749
750 SSCHECK(2);
751 SSPUSHPTR(gv);
752 SSPUSHUV(SAVEt_NSTAB);
753 }
754
755 void
Perl_save_list(pTHX_ SV ** sarg,I32 maxsarg)756 Perl_save_list(pTHX_ SV **sarg, I32 maxsarg)
757 {
758 I32 i;
759
760 PERL_ARGS_ASSERT_SAVE_LIST;
761
762 for (i = 1; i <= maxsarg; i++) {
763 SV *sv;
764 SvGETMAGIC(sarg[i]);
765 sv = newSV(0);
766 sv_setsv_nomg(sv,sarg[i]);
767 SSCHECK(3);
768 SSPUSHPTR(sarg[i]); /* remember the pointer */
769 SSPUSHPTR(sv); /* remember the value */
770 SSPUSHUV(SAVEt_ITEM);
771 }
772 }
773
774 /*
775 =for apidoc sv_usepvn_mg
776
777 Like C<sv_usepvn>, but also handles 'set' magic.
778
779 =cut
780 */
781
782 void
Perl_sv_usepvn_mg(pTHX_ SV * sv,char * ptr,STRLEN len)783 Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len)
784 {
785 PERL_ARGS_ASSERT_SV_USEPVN_MG;
786
787 sv_usepvn_flags(sv,ptr,len, SV_SMAGIC);
788 }
789
790 /*
791 =for apidoc sv_usepvn
792
793 Tells an SV to use C<ptr> to find its string value. Implemented by
794 calling C<sv_usepvn_flags> with C<flags> of 0, hence does not handle 'set'
795 magic. See C<L</sv_usepvn_flags>>.
796
797 =cut
798 */
799
800 void
Perl_sv_usepvn(pTHX_ SV * sv,char * ptr,STRLEN len)801 Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len)
802 {
803 PERL_ARGS_ASSERT_SV_USEPVN;
804
805 sv_usepvn_flags(sv,ptr,len, 0);
806 }
807
808 /*
809 =for apidoc_section $pack
810 =for apidoc unpack_str
811
812 The engine implementing C<unpack()> Perl function. Note: parameters C<strbeg>,
813 C<new_s> and C<ocnt> are not used. This call should not be used, use
814 C<unpackstring> instead.
815
816 =cut */
817
818 SSize_t
Perl_unpack_str(pTHX_ const char * pat,const char * patend,const char * s,const char * strbeg,const char * strend,char ** new_s,I32 ocnt,U32 flags)819 Perl_unpack_str(pTHX_ const char *pat, const char *patend, const char *s,
820 const char *strbeg, const char *strend, char **new_s, I32 ocnt,
821 U32 flags)
822 {
823 PERL_ARGS_ASSERT_UNPACK_STR;
824
825 PERL_UNUSED_ARG(strbeg);
826 PERL_UNUSED_ARG(new_s);
827 PERL_UNUSED_ARG(ocnt);
828
829 return unpackstring(pat, patend, s, strend, flags);
830 }
831
832 /*
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
Perl_pack_cat(pTHX_ SV * cat,const char * pat,const char * patend,SV ** beglist,SV ** endlist,SV *** next_in_list,U32 flags)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 *
Perl_hv_store_ent(pTHX_ HV * hv,SV * keysv,SV * val,U32 hash)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
Perl_hv_exists_ent(pTHX_ HV * hv,SV * keysv,U32 hash)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 *
Perl_hv_fetch_ent(pTHX_ HV * hv,SV * keysv,I32 lval,U32 hash)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 *
Perl_hv_delete_ent(pTHX_ HV * hv,SV * keysv,I32 flags,U32 hash)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**
Perl_hv_store_flags(pTHX_ HV * hv,const char * key,I32 klen,SV * val,U32 hash,int flags)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**
Perl_hv_store(pTHX_ HV * hv,const char * key,I32 klen_i32,SV * val,U32 hash)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
Perl_hv_exists(pTHX_ HV * hv,const char * key,I32 klen_i32)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**
Perl_hv_fetch(pTHX_ HV * hv,const char * key,I32 klen_i32,I32 lval)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 *
Perl_hv_delete(pTHX_ HV * hv,const char * key,I32 klen_i32,I32 flags)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 *
Perl_newAV(pTHX)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 *
Perl_newHV(pTHX)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
Perl_sv_insert(pTHX_ SV * const bigstr,const STRLEN offset,const STRLEN len,const char * const little,const STRLEN littlelen)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
Perl_save_freesv(pTHX_ SV * sv)995 Perl_save_freesv(pTHX_ SV *sv)
996 {
997 save_freesv(sv);
998 }
999
1000 void
Perl_save_mortalizesv(pTHX_ SV * sv)1001 Perl_save_mortalizesv(pTHX_ SV *sv)
1002 {
1003 PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
1004
1005 save_mortalizesv(sv);
1006 }
1007
1008 void
Perl_save_freeop(pTHX_ OP * o)1009 Perl_save_freeop(pTHX_ OP *o)
1010 {
1011 save_freeop(o);
1012 }
1013
1014 void
Perl_save_freepv(pTHX_ char * pv)1015 Perl_save_freepv(pTHX_ char *pv)
1016 {
1017 save_freepv(pv);
1018 }
1019
1020 void
Perl_save_op(pTHX)1021 Perl_save_op(pTHX)
1022 {
1023 save_op();
1024 }
1025
1026 #ifdef PERL_DONT_CREATE_GVSV
1027 GV *
Perl_gv_SVadd(pTHX_ GV * gv)1028 Perl_gv_SVadd(pTHX_ GV *gv)
1029 {
1030 return gv_SVadd(gv);
1031 }
1032 #endif
1033
1034 GV *
Perl_gv_AVadd(pTHX_ GV * gv)1035 Perl_gv_AVadd(pTHX_ GV *gv)
1036 {
1037 return gv_AVadd(gv);
1038 }
1039
1040 GV *
Perl_gv_HVadd(pTHX_ GV * gv)1041 Perl_gv_HVadd(pTHX_ GV *gv)
1042 {
1043 return gv_HVadd(gv);
1044 }
1045
1046 GV *
Perl_gv_IOadd(pTHX_ GV * gv)1047 Perl_gv_IOadd(pTHX_ GV *gv)
1048 {
1049 return gv_IOadd(gv);
1050 }
1051
1052 IO *
Perl_newIO(pTHX)1053 Perl_newIO(pTHX)
1054 {
1055 return MUTABLE_IO(newSV_type(SVt_PVIO));
1056 }
1057
1058 I32
Perl_my_stat(pTHX)1059 Perl_my_stat(pTHX)
1060 {
1061 return my_stat_flags(SV_GMAGIC);
1062 }
1063
1064 I32
Perl_my_lstat(pTHX)1065 Perl_my_lstat(pTHX)
1066 {
1067 return my_lstat_flags(SV_GMAGIC);
1068 }
1069
1070 I32
Perl_sv_eq(pTHX_ SV * sv1,SV * sv2)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 *
Perl_sv_collxfrm(pTHX_ SV * const sv,STRLEN * const nxp)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 *
Perl_mem_collxfrm(pTHX_ const char * input_string,STRLEN len,STRLEN * xlen)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
Perl_sv_2bool(pTHX_ SV * const sv)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*
Perl_custom_op_name(pTHX_ const OP * o)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*
Perl_custom_op_desc(pTHX_ const OP * o)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 *
Perl_newSUB(pTHX_ I32 floor,OP * o,OP * proto,OP * block)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 *
Perl_sv_mortalcopy(pTHX_ SV * const oldsv)1141 Perl_sv_mortalcopy(pTHX_ SV *const oldsv)
1142 {
1143 return Perl_sv_mortalcopy_flags(aTHX_ oldsv, SV_GMAGIC);
1144 }
1145
1146 void
Perl_sv_copypv(pTHX_ SV * const dsv,SV * const ssv)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 */
NATIVE_TO_NEED(const UV enc,const UV ch)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 */
ASCII_TO_NEED(const UV enc,const UV ch)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
Perl_is_utf8_char(const U8 * s)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 is_utf8_char_buf
1196
1197 This is identical to the macro L<perlapi/isUTF8_CHAR>.
1198
1199 =cut */
1200
1201 STRLEN
Perl_is_utf8_char_buf(const U8 * buf,const U8 * buf_end)1202 Perl_is_utf8_char_buf(const U8 *buf, const U8* buf_end)
1203 {
1204
1205 PERL_ARGS_ASSERT_IS_UTF8_CHAR_BUF;
1206
1207 return isUTF8_CHAR(buf, buf_end);
1208 }
1209
1210 /* DEPRECATED!
1211 * Like L</utf8_to_uvuni_buf>(), but should only be called when it is known that
1212 * there are no malformations in the input UTF-8 string C<s>. Surrogates,
1213 * non-character code points, and non-Unicode code points are allowed */
1214
1215 UV
Perl_valid_utf8_to_uvuni(pTHX_ const U8 * s,STRLEN * retlen)1216 Perl_valid_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1217 {
1218 PERL_UNUSED_CONTEXT;
1219 PERL_ARGS_ASSERT_VALID_UTF8_TO_UVUNI;
1220
1221 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1222 }
1223
1224 /*
1225 =for apidoc utf8_to_uvuni
1226
1227 Returns the Unicode code point of the first character in the string C<s>
1228 which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1229 length, in bytes, of that character.
1230
1231 Some, but not all, UTF-8 malformations are detected, and in fact, some
1232 malformed input could cause reading beyond the end of the input buffer, which
1233 is one reason why this function is deprecated. The other is that only in
1234 extremely limited circumstances should the Unicode versus native code point be
1235 of any interest to you. See L</utf8_to_uvuni_buf> for alternatives.
1236
1237 If C<s> points to one of the detected malformations, and UTF8 warnings are
1238 enabled, zero is returned and C<*retlen> is set (if C<retlen> doesn't point to
1239 NULL) to -1. If those warnings are off, the computed value if well-defined (or
1240 the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1241 is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1242 next possible position in C<s> that could begin a non-malformed character.
1243 See L<perlapi/utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1244
1245 =cut
1246 */
1247
1248 UV
Perl_utf8_to_uvuni(pTHX_ const U8 * s,STRLEN * retlen)1249 Perl_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1250 {
1251 PERL_UNUSED_CONTEXT;
1252 PERL_ARGS_ASSERT_UTF8_TO_UVUNI;
1253
1254 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1255 }
1256
1257 /*
1258 =for apidoc pad_compname_type
1259
1260 Looks up the type of the lexical variable at position C<po> in the
1261 currently-compiling pad. If the variable is typed, the stash of the
1262 class to which it is typed is returned. If not, C<NULL> is returned.
1263
1264 Use L<perlintern/C<PAD_COMPNAME_TYPE>> instead.
1265
1266 =cut
1267 */
1268
1269 HV *
Perl_pad_compname_type(pTHX_ const PADOFFSET po)1270 Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1271 {
1272 return PAD_COMPNAME_TYPE(po);
1273 }
1274
1275 /* return ptr to little string in big string, NULL if not found */
1276 /* The original version of this routine was donated by Corey Satten. */
1277
1278 char *
Perl_instr(const char * big,const char * little)1279 Perl_instr(const char *big, const char *little)
1280 {
1281 PERL_ARGS_ASSERT_INSTR;
1282
1283 return instr(big, little);
1284 }
1285
1286 SV *
Perl_newSVsv(pTHX_ SV * const old)1287 Perl_newSVsv(pTHX_ SV *const old)
1288 {
1289 return newSVsv(old);
1290 }
1291
1292 bool
Perl_sv_utf8_downgrade(pTHX_ SV * const sv,const bool fail_ok)1293 Perl_sv_utf8_downgrade(pTHX_ SV *const sv, const bool fail_ok)
1294 {
1295 PERL_ARGS_ASSERT_SV_UTF8_DOWNGRADE;
1296
1297 return sv_utf8_downgrade(sv, fail_ok);
1298 }
1299
1300 char *
Perl_sv_2pvutf8(pTHX_ SV * sv,STRLEN * const lp)1301 Perl_sv_2pvutf8(pTHX_ SV *sv, STRLEN *const lp)
1302 {
1303 PERL_ARGS_ASSERT_SV_2PVUTF8;
1304
1305 return sv_2pvutf8(sv, lp);
1306 }
1307
1308 char *
Perl_sv_2pvbyte(pTHX_ SV * sv,STRLEN * const lp)1309 Perl_sv_2pvbyte(pTHX_ SV *sv, STRLEN *const lp)
1310 {
1311 PERL_ARGS_ASSERT_SV_2PVBYTE;
1312
1313 return sv_2pvbyte(sv, lp);
1314 }
1315
1316 U8 *
Perl_uvuni_to_utf8(pTHX_ U8 * d,UV uv)1317 Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv)
1318 {
1319 PERL_ARGS_ASSERT_UVUNI_TO_UTF8;
1320
1321 return uvoffuni_to_utf8_flags(d, uv, 0);
1322 }
1323
1324 /*
1325 =for apidoc utf8n_to_uvuni
1326
1327 Instead use L<perlapi/utf8_to_uvchr_buf>, or rarely, L<perlapi/utf8n_to_uvchr>.
1328
1329 This function was useful for code that wanted to handle both EBCDIC and
1330 ASCII platforms with Unicode properties, but starting in Perl v5.20, the
1331 distinctions between the platforms have mostly been made invisible to most
1332 code, so this function is quite unlikely to be what you want. If you do need
1333 this precise functionality, use instead
1334 C<L<NATIVE_TO_UNI(utf8_to_uvchr_buf(...))|perlapi/utf8_to_uvchr_buf>>
1335 or C<L<NATIVE_TO_UNI(utf8n_to_uvchr(...))|perlapi/utf8n_to_uvchr>>.
1336
1337 =cut
1338 */
1339
1340 UV
Perl_utf8n_to_uvuni(pTHX_ const U8 * s,STRLEN curlen,STRLEN * retlen,U32 flags)1341 Perl_utf8n_to_uvuni(pTHX_ const U8 *s, STRLEN curlen, STRLEN *retlen, U32 flags)
1342 {
1343 PERL_ARGS_ASSERT_UTF8N_TO_UVUNI;
1344
1345 return NATIVE_TO_UNI(utf8n_to_uvchr(s, curlen, retlen, flags));
1346 }
1347
1348 /*
1349 =for apidoc uvuni_to_utf8_flags
1350
1351 Instead you almost certainly want to use L<perlapi/uvchr_to_utf8> or
1352 L<perlapi/uvchr_to_utf8_flags>.
1353
1354 This function is a deprecated synonym for L</uvoffuni_to_utf8_flags>,
1355 which itself, while not deprecated, should be used only in isolated
1356 circumstances. These functions were useful for code that wanted to handle
1357 both EBCDIC and ASCII platforms with Unicode properties, but starting in Perl
1358 v5.20, the distinctions between the platforms have mostly been made invisible
1359 to most code, so this function is quite unlikely to be what you want.
1360
1361 =cut
1362 */
1363
1364 U8 *
Perl_uvuni_to_utf8_flags(pTHX_ U8 * d,UV uv,UV flags)1365 Perl_uvuni_to_utf8_flags(pTHX_ U8 *d, UV uv, UV flags)
1366 {
1367 PERL_ARGS_ASSERT_UVUNI_TO_UTF8_FLAGS;
1368
1369 return uvoffuni_to_utf8_flags(d, uv, flags);
1370 }
1371
1372 /*
1373 =for apidoc utf8_to_uvchr
1374
1375 Returns the native code point of the first character in the string C<s>
1376 which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1377 length, in bytes, of that character.
1378
1379 Some, but not all, UTF-8 malformations are detected, and in fact, some
1380 malformed input could cause reading beyond the end of the input buffer, which
1381 is why this function is deprecated. Use L</utf8_to_uvchr_buf> instead.
1382
1383 If C<s> points to one of the detected malformations, and UTF8 warnings are
1384 enabled, zero is returned and C<*retlen> is set (if C<retlen> isn't
1385 C<NULL>) to -1. If those warnings are off, the computed value if well-defined (or
1386 the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1387 is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1388 next possible position in C<s> that could begin a non-malformed character.
1389 See L</utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1390
1391 =cut
1392 */
1393
1394 UV
Perl_utf8_to_uvchr(pTHX_ const U8 * s,STRLEN * retlen)1395 Perl_utf8_to_uvchr(pTHX_ const U8 *s, STRLEN *retlen)
1396 {
1397 PERL_ARGS_ASSERT_UTF8_TO_UVCHR;
1398
1399 /* This function is unsafe if malformed UTF-8 input is given it, which is
1400 * why the function is deprecated. If the first byte of the input
1401 * indicates that there are more bytes remaining in the sequence that forms
1402 * the character than there are in the input buffer, it can read past the
1403 * end. But we can make it safe if the input string happens to be
1404 * NUL-terminated, as many strings in Perl are, by refusing to read past a
1405 * NUL, which is what UTF8_CHK_SKIP() does. A NUL indicates the start of
1406 * the next character anyway. If the input isn't NUL-terminated, the
1407 * function remains unsafe, as it always has been. */
1408
1409 return utf8_to_uvchr_buf(s, s + UTF8_CHK_SKIP(s), retlen);
1410 }
1411
1412 GCC_DIAG_RESTORE
1413
1414 #endif /* NO_MATHOMS */
1415
1416 /*
1417 * ex: set ts=8 sts=4 sw=4 et:
1418 */
1419