This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlapi: Fix typo.
[perl5.git] / mathoms.c
CommitLineData
7ee2227d
SP
1/* mathoms.c
2 *
2eee27d7
SS
3 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
4 * 2011, 2012 by Larry Wall and others
7ee2227d
SP
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/*
4ac71550
TC
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"]
7ee2227d
SP
18 */
19
359d40ba 20
20fac488 21
7832ad85 22/*
7ee2227d 23 * This file contains mathoms, various binary artifacts from previous
d7244c9a
DM
24 * versions of Perl which we cannot completely remove from the core
25 * code. There are two reasons functions should be here:
26 *
a3815e44 27 * 1) A function has been replaced by a macro within a minor release,
d7244c9a
DM
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_ ...)
7ee2227d 34 *
8687a6e6
DM
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 *
55cb5ee0
KW
49 * The compilation of this file can be suppressed; see INSTALL
50 *
8687a6e6
DM
51 * Some blurb for perlapi.pod:
52
51b56f5c 53 head1 Obsolete backwards compatibility functions
8687a6e6 54
dcccc8ff
KW
55Some of these are also deprecated. You can exclude these from
56your compiled Perl by adding this option to Configure:
57C<-Accflags='-DNO_MATHOMS'>
58
59=cut
60
7ee2227d
SP
61 */
62
dcccc8ff 63
7ee2227d
SP
64#include "EXTERN.h"
65#define PERL_IN_MATHOMS_C
66#include "perl.h"
67
359d40ba
NC
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
238965b4
KW
74/* The functions in this file should be able to call other deprecated functions
75 * without a compiler warning */
76GCC_DIAG_IGNORE(-Wdeprecated-declarations)
77
7ee2227d
SP
78/* ref() is now a macro using Perl_doref;
79 * this version provided for binary compatibility only.
80 */
81OP *
82Perl_ref(pTHX_ OP *o, I32 type)
83{
84 return doref(o, type, TRUE);
85}
86
aae9cea0 87/*
51b56f5c 88=for apidoc_section SV Handling
174c73e3
NC
89=for apidoc sv_unref
90
91Unsets the RV status of the SV, and decrements the reference count of
92whatever was being referenced by the RV. This can almost be thought of
93as a reversal of C<newSVrv>. This is C<sv_unref_flags> with the C<flag>
fbe13c60 94being zero. See C<L</SvROK_off>>.
174c73e3
NC
95
96=cut
97*/
98
99void
100Perl_sv_unref(pTHX_ SV *sv)
101{
7918f24d
NC
102 PERL_ARGS_ASSERT_SV_UNREF;
103
174c73e3
NC
104 sv_unref_flags(sv, 0);
105}
106
107/*
aae9cea0
NC
108=for apidoc sv_taint
109
72d33970 110Taint an SV. Use C<SvTAINTED_on> instead.
dff47061 111
aae9cea0
NC
112=cut
113*/
114
115void
116Perl_sv_taint(pTHX_ SV *sv)
117{
7918f24d
NC
118 PERL_ARGS_ASSERT_SV_TAINT;
119
a0714e2c 120 sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0);
aae9cea0
NC
121}
122
7ee2227d
SP
123/* sv_2iv() is now a macro using Perl_sv_2iv_flags();
124 * this function provided for binary compatibility only
125 */
126
127IV
5aaab254 128Perl_sv_2iv(pTHX_ SV *sv)
7ee2227d 129{
1061065f
DD
130 PERL_ARGS_ASSERT_SV_2IV;
131
7ee2227d
SP
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
139UV
5aaab254 140Perl_sv_2uv(pTHX_ SV *sv)
7ee2227d 141{
1061065f
DD
142 PERL_ARGS_ASSERT_SV_2UV;
143
7ee2227d
SP
144 return sv_2uv_flags(sv, SV_GMAGIC);
145}
146
39d5de13
DM
147/* sv_2nv() is now a macro using Perl_sv_2nv_flags();
148 * this function provided for binary compatibility only
149 */
150
151NV
5aaab254 152Perl_sv_2nv(pTHX_ SV *sv)
39d5de13
DM
153{
154 return sv_2nv_flags(sv, SV_GMAGIC);
155}
156
157
7ee2227d
SP
158/* sv_2pv() is now a macro using Perl_sv_2pv_flags();
159 * this function provided for binary compatibility only
160 */
161
162char *
5aaab254 163Perl_sv_2pv(pTHX_ SV *sv, STRLEN *lp)
7ee2227d 164{
1061065f
DD
165 PERL_ARGS_ASSERT_SV_2PV;
166
7ee2227d
SP
167 return sv_2pv_flags(sv, lp, SV_GMAGIC);
168}
169
5abc721d 170/*
cb2f1b7b
NC
171=for apidoc sv_2pv_nolen
172
72d33970 173Like C<sv_2pv()>, but doesn't return the length too. You should usually
cb2f1b7b 174use the macro wrapper C<SvPV_nolen(sv)> instead.
dff47061 175
cb2f1b7b
NC
176=cut
177*/
178
179char *
5aaab254 180Perl_sv_2pv_nolen(pTHX_ SV *sv)
cb2f1b7b 181{
c85ae797 182 PERL_ARGS_ASSERT_SV_2PV_NOLEN;
b5445a23 183 return sv_2pv(sv, NULL);
cb2f1b7b
NC
184}
185
186/*
187=for apidoc sv_2pvbyte_nolen
188
189Return a pointer to the byte-encoded representation of the SV.
190May cause the SV to be downgraded from UTF-8 as a side-effect.
191
192Usually accessed via the C<SvPVbyte_nolen> macro.
193
194=cut
195*/
196
197char *
5aaab254 198Perl_sv_2pvbyte_nolen(pTHX_ SV *sv)
cb2f1b7b 199{
7918f24d
NC
200 PERL_ARGS_ASSERT_SV_2PVBYTE_NOLEN;
201
b5445a23 202 return sv_2pvbyte(sv, NULL);
cb2f1b7b
NC
203}
204
205/*
206=for apidoc sv_2pvutf8_nolen
207
208Return a pointer to the UTF-8-encoded representation of the SV.
209May cause the SV to be upgraded to UTF-8 as a side-effect.
210
211Usually accessed via the C<SvPVutf8_nolen> macro.
212
213=cut
214*/
215
216char *
5aaab254 217Perl_sv_2pvutf8_nolen(pTHX_ SV *sv)
cb2f1b7b 218{
7918f24d
NC
219 PERL_ARGS_ASSERT_SV_2PVUTF8_NOLEN;
220
b5445a23 221 return sv_2pvutf8(sv, NULL);
cb2f1b7b
NC
222}
223
224/*
5abc721d
NC
225=for apidoc sv_force_normal
226
227Undo various types of fakery on an SV: if the PV is a shared string, make
228a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
796b6530 229an C<xpvmg>. See also C<L</sv_force_normal_flags>>.
5abc721d
NC
230
231=cut
232*/
233
234void
5aaab254 235Perl_sv_force_normal(pTHX_ SV *sv)
5abc721d 236{
7918f24d
NC
237 PERL_ARGS_ASSERT_SV_FORCE_NORMAL;
238
5abc721d
NC
239 sv_force_normal_flags(sv, 0);
240}
7ee2227d
SP
241
242/* sv_setsv() is now a macro using Perl_sv_setsv_flags();
243 * this function provided for binary compatibility only
244 */
245
246void
5aaab254 247Perl_sv_setsv(pTHX_ SV *dstr, SV *sstr)
7ee2227d 248{
7918f24d
NC
249 PERL_ARGS_ASSERT_SV_SETSV;
250
7ee2227d
SP
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
258void
259Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
260{
7918f24d
NC
261 PERL_ARGS_ASSERT_SV_CATPVN;
262
7ee2227d
SP
263 sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC);
264}
265
b347df82
NC
266/*
267=for apidoc sv_catpvn_mg
268
269Like C<sv_catpvn>, but also handles 'set' magic.
270
271=cut
272*/
273
274void
5aaab254 275Perl_sv_catpvn_mg(pTHX_ SV *sv, const char *ptr, STRLEN len)
b347df82 276{
7918f24d
NC
277 PERL_ARGS_ASSERT_SV_CATPVN_MG;
278
b347df82
NC
279 sv_catpvn_flags(sv,ptr,len,SV_GMAGIC|SV_SMAGIC);
280}
281
7ee2227d
SP
282/* sv_catsv() is now a macro using Perl_sv_catsv_flags();
283 * this function provided for binary compatibility only
284 */
285
286void
5aaab254 287Perl_sv_catsv(pTHX_ SV *dstr, SV *sstr)
7ee2227d 288{
7918f24d
NC
289 PERL_ARGS_ASSERT_SV_CATSV;
290
7ee2227d
SP
291 sv_catsv_flags(dstr, sstr, SV_GMAGIC);
292}
293
0feed65a 294/*
b347df82
NC
295=for apidoc sv_catsv_mg
296
297Like C<sv_catsv>, but also handles 'set' magic.
298
299=cut
300*/
301
302void
5aaab254 303Perl_sv_catsv_mg(pTHX_ SV *dsv, SV *ssv)
b347df82 304{
7918f24d
NC
305 PERL_ARGS_ASSERT_SV_CATSV_MG;
306
b347df82
NC
307 sv_catsv_flags(dsv,ssv,SV_GMAGIC|SV_SMAGIC);
308}
309
310/*
0feed65a
NC
311=for apidoc sv_iv
312
313A private implementation of the C<SvIVx> macro for compilers which can't
72d33970 314cope with complex macro expressions. Always use the macro instead.
0feed65a
NC
315
316=cut
317*/
318
319IV
5aaab254 320Perl_sv_iv(pTHX_ SV *sv)
0feed65a 321{
7918f24d
NC
322 PERL_ARGS_ASSERT_SV_IV;
323
0feed65a
NC
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
335A private implementation of the C<SvUVx> macro for compilers which can't
72d33970 336cope with complex macro expressions. Always use the macro instead.
0feed65a
NC
337
338=cut
339*/
340
341UV
5aaab254 342Perl_sv_uv(pTHX_ SV *sv)
0feed65a 343{
7918f24d
NC
344 PERL_ARGS_ASSERT_SV_UV;
345
0feed65a
NC
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
357A private implementation of the C<SvNVx> macro for compilers which can't
72d33970 358cope with complex macro expressions. Always use the macro instead.
0feed65a
NC
359
360=cut
361*/
362
363NV
5aaab254 364Perl_sv_nv(pTHX_ SV *sv)
0feed65a 365{
7918f24d
NC
366 PERL_ARGS_ASSERT_SV_NV;
367
0feed65a
NC
368 if (SvNOK(sv))
369 return SvNVX(sv);
370 return sv_2nv(sv);
371}
372
373/*
374=for apidoc sv_pv
375
376Use the C<SvPV_nolen> macro instead
377
378=for apidoc sv_pvn
379
380A private implementation of the C<SvPV> macro for compilers which can't
72d33970 381cope with complex macro expressions. Always use the macro instead.
0feed65a
NC
382
383=cut
384*/
385
386char *
387Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
388{
7918f24d
NC
389 PERL_ARGS_ASSERT_SV_PVN;
390
0feed65a
NC
391 if (SvPOK(sv)) {
392 *lp = SvCUR(sv);
393 return SvPVX(sv);
394 }
395 return sv_2pv(sv, lp);
396}
397
398
399char *
5aaab254 400Perl_sv_pvn_nomg(pTHX_ SV *sv, STRLEN *lp)
0feed65a 401{
7918f24d
NC
402 PERL_ARGS_ASSERT_SV_PVN_NOMG;
403
0feed65a
NC
404 if (SvPOK(sv)) {
405 *lp = SvCUR(sv);
406 return SvPVX(sv);
407 }
408 return sv_2pv_flags(sv, lp, 0);
409}
410
7ee2227d
SP
411/* sv_pv() is now a macro using SvPV_nolen();
412 * this function provided for binary compatibility only
413 */
414
415char *
416Perl_sv_pv(pTHX_ SV *sv)
417{
7918f24d
NC
418 PERL_ARGS_ASSERT_SV_PV;
419
7ee2227d
SP
420 if (SvPOK(sv))
421 return SvPVX(sv);
422
b5445a23 423 return sv_2pv(sv, NULL);
7ee2227d
SP
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
430char *
431Perl_sv_pvn_force(pTHX_ SV *sv, STRLEN *lp)
432{
7918f24d
NC
433 PERL_ARGS_ASSERT_SV_PVN_FORCE;
434
7ee2227d
SP
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
442char *
443Perl_sv_pvbyte(pTHX_ SV *sv)
444{
7918f24d
NC
445 PERL_ARGS_ASSERT_SV_PVBYTE;
446
b5445a23 447 sv_utf8_downgrade(sv, FALSE);
7ee2227d
SP
448 return sv_pv(sv);
449}
450
0feed65a
NC
451/*
452=for apidoc sv_pvbyte
453
454Use C<SvPVbyte_nolen> instead.
455
456=for apidoc sv_pvbyten
457
458A private implementation of the C<SvPVbyte> macro for compilers
72d33970 459which can't cope with complex macro expressions. Always use the macro
0feed65a
NC
460instead.
461
462=cut
463*/
464
465char *
466Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
467{
7918f24d
NC
468 PERL_ARGS_ASSERT_SV_PVBYTEN;
469
b5445a23 470 sv_utf8_downgrade(sv, FALSE);
0feed65a
NC
471 return sv_pvn(sv,lp);
472}
473
7ee2227d
SP
474/* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
475 * this function provided for binary compatibility only
476 */
477
478char *
479Perl_sv_pvutf8(pTHX_ SV *sv)
480{
7918f24d
NC
481 PERL_ARGS_ASSERT_SV_PVUTF8;
482
7ee2227d
SP
483 sv_utf8_upgrade(sv);
484 return sv_pv(sv);
485}
486
0feed65a
NC
487/*
488=for apidoc sv_pvutf8
489
490Use the C<SvPVutf8_nolen> macro instead
491
492=for apidoc sv_pvutf8n
493
494A private implementation of the C<SvPVutf8> macro for compilers
72d33970 495which can't cope with complex macro expressions. Always use the macro
0feed65a
NC
496instead.
497
498=cut
499*/
500
501char *
502Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
503{
7918f24d
NC
504 PERL_ARGS_ASSERT_SV_PVUTF8N;
505
0feed65a
NC
506 sv_utf8_upgrade(sv);
507 return sv_pvn(sv,lp);
508}
509
205c02c2
NC
510/* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
511 * this function provided for binary compatibility only
512 */
513
514STRLEN
5aaab254 515Perl_sv_utf8_upgrade(pTHX_ SV *sv)
205c02c2 516{
7918f24d
NC
517 PERL_ARGS_ASSERT_SV_UTF8_UPGRADE;
518
205c02c2
NC
519 return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
520}
521
7ee2227d
SP
522int
523Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...)
524{
3ed3a8af 525 int ret = 0;
fc917fff 526 va_list arglist;
7918f24d
NC
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
7ee2227d 534 va_start(arglist, format);
3ed3a8af
JH
535 ret = PerlIO_vprintf(stream, format, arglist);
536 va_end(arglist);
537 return ret;
7ee2227d
SP
538}
539
540int
541Perl_printf_nocontext(const char *format, ...)
542{
543 dTHX;
fc917fff 544 va_list arglist;
3ed3a8af 545 int ret = 0;
7918f24d
NC
546
547#ifdef PERL_IMPLICIT_CONTEXT
548 PERL_ARGS_ASSERT_PRINTF_NOCONTEXT;
549#endif
550
7ee2227d 551 va_start(arglist, format);
3ed3a8af
JH
552 ret = PerlIO_vprintf(PerlIO_stdout(), format, arglist);
553 va_end(arglist);
554 return ret;
7ee2227d
SP
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 */
563NV
564Perl_huge(void)
565{
c773ee7a 566# if defined(USE_LONG_DOUBLE) && defined(HUGE_VALL)
7ee2227d 567 return HUGE_VALL;
c773ee7a 568# else
7ee2227d 569 return HUGE_VAL;
c773ee7a 570# endif
7ee2227d
SP
571}
572#endif
573
f2f0f092
NC
574/* compatibility with versions <= 5.003. */
575void
576Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
577{
7918f24d
NC
578 PERL_ARGS_ASSERT_GV_FULLNAME;
579
666ea192 580 gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
f2f0f092
NC
581}
582
583/* compatibility with versions <= 5.003. */
584void
585Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
586{
7918f24d
NC
587 PERL_ARGS_ASSERT_GV_EFULLNAME;
588
666ea192 589 gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
f2f0f092
NC
590}
591
2674aeec
NC
592void
593Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
594{
7918f24d
NC
595 PERL_ARGS_ASSERT_GV_FULLNAME3;
596
2674aeec
NC
597 gv_fullname4(sv, gv, prefix, TRUE);
598}
599
600void
601Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
602{
7918f24d
NC
603 PERL_ARGS_ASSERT_GV_EFULLNAME3;
604
2674aeec
NC
605 gv_efullname4(sv, gv, prefix, TRUE);
606}
607
887986eb 608/*
51b56f5c 609=for apidoc_section GV Handling
887986eb
NC
610=for apidoc gv_fetchmethod
611
ca8b95d7 612See L</gv_fetchmethod_autoload>.
887986eb
NC
613
614=cut
615*/
616
617GV *
618Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
619{
7918f24d
NC
620 PERL_ARGS_ASSERT_GV_FETCHMETHOD;
621
887986eb
NC
622 return gv_fetchmethod_autoload(stash, name, TRUE);
623}
624
7a7b9979
NC
625HE *
626Perl_hv_iternext(pTHX_ HV *hv)
627{
7918f24d
NC
628 PERL_ARGS_ASSERT_HV_ITERNEXT;
629
7a7b9979
NC
630 return hv_iternext_flags(hv, 0);
631}
632
bc5cdc23
NC
633void
634Perl_hv_magic(pTHX_ HV *hv, GV *gv, int how)
635{
7918f24d
NC
636 PERL_ARGS_ASSERT_HV_MAGIC;
637
ad64d0ec 638 sv_magic(MUTABLE_SV(hv), MUTABLE_SV(gv), how, NULL, 0);
bc5cdc23
NC
639}
640
34d367cd 641bool
5aaab254 642Perl_do_open(pTHX_ GV *gv, const char *name, I32 len, int as_raw,
e4dba786
NC
643 int rawmode, int rawperm, PerlIO *supplied_fp)
644{
7918f24d
NC
645 PERL_ARGS_ASSERT_DO_OPEN;
646
e4dba786
NC
647 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
648 supplied_fp, (SV **) NULL, 0);
649}
650
651bool
5aaab254 652Perl_do_open9(pTHX_ GV *gv, const char *name, I32 len, int
34d367cd
SP
653as_raw,
654 int rawmode, int rawperm, PerlIO *supplied_fp, SV *svs,
655 I32 num_svs)
656{
7918f24d
NC
657 PERL_ARGS_ASSERT_DO_OPEN9;
658
34d367cd
SP
659 PERL_UNUSED_ARG(num_svs);
660 return do_openn(gv, name, len, as_raw, rawmode, rawperm,
661 supplied_fp, &svs, 1);
662}
663
664int
665Perl_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";
7918f24d
NC
671
672 PERL_ARGS_ASSERT_DO_BINMODE;
673
34d367cd
SP
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
a9f96b3f
NC
681#ifndef OS2
682bool
5aaab254 683Perl_do_aexec(pTHX_ SV *really, SV **mark, SV **sp)
a9f96b3f 684{
7918f24d
NC
685 PERL_ARGS_ASSERT_DO_AEXEC;
686
a9f96b3f
NC
687 return do_aexec5(really, mark, sp, 0, 0);
688}
689#endif
690
89552e80
NC
691/* Backwards compatibility. */
692int
693Perl_init_i18nl14n(pTHX_ int printwarn)
694{
695 return init_i18nl10n(printwarn);
696}
697
814fafa7 698bool
c41b2540 699Perl_is_utf8_string_loc(const U8 *s, const STRLEN len, const U8 **ep)
814fafa7 700{
7918f24d
NC
701 PERL_ARGS_ASSERT_IS_UTF8_STRING_LOC;
702
814fafa7
NC
703 return is_utf8_string_loclen(s, len, ep, 0);
704}
705
7ee2227d 706/*
51b56f5c 707=for apidoc_section SV Handling
d5b2b27b
NC
708=for apidoc sv_nolocking
709
710Dummy routine which "locks" an SV when there is no locking module present.
796b6530 711Exists to avoid test for a C<NULL> function pointer and because it could
d5b2b27b
NC
712potentially warn under some level of strict-ness.
713
796b6530 714"Superseded" by C<sv_nosharing()>.
d5b2b27b
NC
715
716=cut
717*/
718
719void
720Perl_sv_nolocking(pTHX_ SV *sv)
721{
96a5add6 722 PERL_UNUSED_CONTEXT;
d5b2b27b
NC
723 PERL_UNUSED_ARG(sv);
724}
725
726
727/*
728=for apidoc sv_nounlocking
729
730Dummy routine which "unlocks" an SV when there is no locking module present.
796b6530 731Exists to avoid test for a C<NULL> function pointer and because it could
d5b2b27b
NC
732potentially warn under some level of strict-ness.
733
796b6530 734"Superseded" by C<sv_nosharing()>.
d5b2b27b
NC
735
736=cut
af50ae69
KW
737
738PERL_UNLOCK_HOOK in intrpvar.h is the macro that refers to this, and guarantees
739that mathoms gets loaded.
740
d5b2b27b
NC
741*/
742
743void
744Perl_sv_nounlocking(pTHX_ SV *sv)
745{
96a5add6 746 PERL_UNUSED_CONTEXT;
d5b2b27b
NC
747 PERL_UNUSED_ARG(sv);
748}
749
2053acbf
NC
750void
751Perl_save_long(pTHX_ long int *longp)
752{
7918f24d
NC
753 PERL_ARGS_ASSERT_SAVE_LONG;
754
2053acbf
NC
755 SSCHECK(3);
756 SSPUSHLONG(*longp);
757 SSPUSHPTR(longp);
c6bf6a65 758 SSPUSHUV(SAVEt_LONG);
2053acbf
NC
759}
760
761void
2053acbf
NC
762Perl_save_nogv(pTHX_ GV *gv)
763{
7918f24d
NC
764 PERL_ARGS_ASSERT_SAVE_NOGV;
765
2053acbf
NC
766 SSCHECK(2);
767 SSPUSHPTR(gv);
c6bf6a65 768 SSPUSHUV(SAVEt_NSTAB);
2053acbf
NC
769}
770
771void
5aaab254 772Perl_save_list(pTHX_ SV **sarg, I32 maxsarg)
2053acbf 773{
eb578fdb 774 I32 i;
2053acbf 775
7918f24d
NC
776 PERL_ARGS_ASSERT_SAVE_LIST;
777
2053acbf 778 for (i = 1; i <= maxsarg; i++) {
3ed356df
FC
779 SV *sv;
780 SvGETMAGIC(sarg[i]);
781 sv = newSV(0);
782 sv_setsv_nomg(sv,sarg[i]);
2053acbf
NC
783 SSCHECK(3);
784 SSPUSHPTR(sarg[i]); /* remember the pointer */
785 SSPUSHPTR(sv); /* remember the value */
c6bf6a65 786 SSPUSHUV(SAVEt_ITEM);
2053acbf
NC
787 }
788}
789
47518d95
NC
790/*
791=for apidoc sv_usepvn_mg
792
793Like C<sv_usepvn>, but also handles 'set' magic.
794
795=cut
796*/
797
798void
799Perl_sv_usepvn_mg(pTHX_ SV *sv, char *ptr, STRLEN len)
800{
7918f24d
NC
801 PERL_ARGS_ASSERT_SV_USEPVN_MG;
802
47518d95
NC
803 sv_usepvn_flags(sv,ptr,len, SV_SMAGIC);
804}
805
806/*
807=for apidoc sv_usepvn
808
72d33970 809Tells an SV to use C<ptr> to find its string value. Implemented by
47518d95 810calling C<sv_usepvn_flags> with C<flags> of 0, hence does not handle 'set'
fbe13c60 811magic. See C<L</sv_usepvn_flags>>.
47518d95
NC
812
813=cut
814*/
815
816void
817Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len)
818{
7918f24d
NC
819 PERL_ARGS_ASSERT_SV_USEPVN;
820
47518d95
NC
821 sv_usepvn_flags(sv,ptr,len, 0);
822}
823
c03e83bf 824/*
51b56f5c 825=for apidoc_section Pack and Unpack
c03e83bf
NC
826=for apidoc unpack_str
827
796b6530
KW
828The engine implementing C<unpack()> Perl function. Note: parameters C<strbeg>,
829C<new_s> and C<ocnt> are not used. This call should not be used, use
830C<unpackstring> instead.
c03e83bf
NC
831
832=cut */
833
e1b825c1 834SSize_t
c03e83bf
NC
835Perl_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{
7918f24d
NC
839 PERL_ARGS_ASSERT_UNPACK_STR;
840
c03e83bf
NC
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}
b47163a2
NC
847
848/*
849=for apidoc pack_cat
850
796b6530
KW
851The engine implementing C<pack()> Perl function. Note: parameters
852C<next_in_list> and C<flags> are not used. This call should not be used; use
550697d6 853C<L</packlist>> instead.
b47163a2
NC
854
855=cut
856*/
857
858void
5aaab254 859Perl_pack_cat(pTHX_ SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
b47163a2 860{
7918f24d
NC
861 PERL_ARGS_ASSERT_PACK_CAT;
862
b47163a2
NC
863 PERL_UNUSED_ARG(next_in_list);
864 PERL_UNUSED_ARG(flags);
865
866 packlist(cat, pat, patend, beglist, endlist);
867}
4c2df08c
NC
868
869HE *
870Perl_hv_store_ent(pTHX_ HV *hv, SV *keysv, SV *val, U32 hash)
871{
59af68cc 872 return (HE *)hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISSTORE, val, hash);
4c2df08c
NC
873}
874
875bool
876Perl_hv_exists_ent(pTHX_ HV *hv, SV *keysv, U32 hash)
877{
7918f24d
NC
878 PERL_ARGS_ASSERT_HV_EXISTS_ENT;
879
8298454c 880 return cBOOL(hv_common(hv, keysv, NULL, 0, 0, HV_FETCH_ISEXISTS, 0, hash));
4c2df08c
NC
881}
882
883HE *
884Perl_hv_fetch_ent(pTHX_ HV *hv, SV *keysv, I32 lval, U32 hash)
885{
7918f24d
NC
886 PERL_ARGS_ASSERT_HV_FETCH_ENT;
887
59af68cc 888 return (HE *)hv_common(hv, keysv, NULL, 0, 0,
4c2df08c
NC
889 (lval ? HV_FETCH_LVALUE : 0), NULL, hash);
890}
891
892SV *
893Perl_hv_delete_ent(pTHX_ HV *hv, SV *keysv, I32 flags, U32 hash)
894{
7918f24d
NC
895 PERL_ARGS_ASSERT_HV_DELETE_ENT;
896
ad64d0ec
NC
897 return MUTABLE_SV(hv_common(hv, keysv, NULL, 0, 0, flags | HV_DELETE, NULL,
898 hash));
4c2df08c
NC
899}
900
a038e571
NC
901SV**
902Perl_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
909SV**
910Perl_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
926bool
927Perl_hv_exists(pTHX_ HV *hv, const char *key, I32 klen_i32)
928{
929 STRLEN klen;
930 int flags;
931
7918f24d
NC
932 PERL_ARGS_ASSERT_HV_EXISTS;
933
a038e571
NC
934 if (klen_i32 < 0) {
935 klen = -klen_i32;
936 flags = HVhek_UTF8;
937 } else {
938 klen = klen_i32;
939 flags = 0;
940 }
8298454c 941 return cBOOL(hv_common(hv, NULL, key, klen, flags, HV_FETCH_ISEXISTS, 0, 0));
a038e571
NC
942}
943
944SV**
945Perl_hv_fetch(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 lval)
946{
947 STRLEN klen;
948 int flags;
949
7918f24d
NC
950 PERL_ARGS_ASSERT_HV_FETCH;
951
a038e571
NC
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
964SV *
965Perl_hv_delete(pTHX_ HV *hv, const char *key, I32 klen_i32, I32 flags)
966{
967 STRLEN klen;
968 int k_flags;
969
7918f24d
NC
970 PERL_ARGS_ASSERT_HV_DELETE;
971
a038e571
NC
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 }
ad64d0ec
NC
979 return MUTABLE_SV(hv_common(hv, NULL, key, klen, k_flags, flags | HV_DELETE,
980 NULL, 0));
a038e571
NC
981}
982
ac572bf4
NC
983AV *
984Perl_newAV(pTHX)
985{
502c6561 986 return MUTABLE_AV(newSV_type(SVt_PVAV));
ac572bf4
NC
987 /* sv_upgrade does AvREAL_only():
988 AvALLOC(av) = 0;
989 AvARRAY(av) = NULL;
990 AvMAX(av) = AvFILLp(av) = -1; */
991}
992
78ac7dd9
NC
993HV *
994Perl_newHV(pTHX)
995{
85fbaab2 996 HV * const hv = MUTABLE_HV(newSV_type(SVt_PVHV));
78ac7dd9
NC
997 assert(!SvOK(hv));
998
999 return hv;
1000}
1001
84335ee9
NC
1002void
1003Perl_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
2fd8beea
NC
1010void
1011Perl_save_freesv(pTHX_ SV *sv)
1012{
2fd8beea
NC
1013 save_freesv(sv);
1014}
1015
1016void
1017Perl_save_mortalizesv(pTHX_ SV *sv)
1018{
2fd8beea
NC
1019 PERL_ARGS_ASSERT_SAVE_MORTALIZESV;
1020
1021 save_mortalizesv(sv);
1022}
1023
1024void
1025Perl_save_freeop(pTHX_ OP *o)
1026{
2fd8beea
NC
1027 save_freeop(o);
1028}
1029
1030void
1031Perl_save_freepv(pTHX_ char *pv)
1032{
2fd8beea
NC
1033 save_freepv(pv);
1034}
1035
1036void
1037Perl_save_op(pTHX)
1038{
2fd8beea
NC
1039 save_op();
1040}
1041
d5713896
NC
1042#ifdef PERL_DONT_CREATE_GVSV
1043GV *
1044Perl_gv_SVadd(pTHX_ GV *gv)
1045{
d5713896
NC
1046 return gv_SVadd(gv);
1047}
1048#endif
1049
1050GV *
1051Perl_gv_AVadd(pTHX_ GV *gv)
1052{
d5713896
NC
1053 return gv_AVadd(gv);
1054}
1055
1056GV *
5aaab254 1057Perl_gv_HVadd(pTHX_ GV *gv)
d5713896 1058{
d5713896
NC
1059 return gv_HVadd(gv);
1060}
1061
bb85b28a 1062GV *
5aaab254 1063Perl_gv_IOadd(pTHX_ GV *gv)
bb85b28a
NC
1064{
1065 return gv_IOadd(gv);
1066}
1067
85dca89a
NC
1068IO *
1069Perl_newIO(pTHX)
1070{
1071 return MUTABLE_IO(newSV_type(SVt_PVIO));
1072}
1073
0d7d409d
DM
1074I32
1075Perl_my_stat(pTHX)
1076{
1077 return my_stat_flags(SV_GMAGIC);
1078}
1079
1080I32
1081Perl_my_lstat(pTHX)
1082{
1083 return my_lstat_flags(SV_GMAGIC);
1084}
1085
078504b2 1086I32
5aaab254 1087Perl_sv_eq(pTHX_ SV *sv1, SV *sv2)
078504b2
FC
1088{
1089 return sv_eq_flags(sv1, sv2, SV_GMAGIC);
1090}
1091
6129b56c 1092#ifdef USE_LOCALE_COLLATE
078504b2
FC
1093char *
1094Perl_sv_collxfrm(pTHX_ SV *const sv, STRLEN *const nxp)
1095{
1545ba5b 1096 PERL_ARGS_ASSERT_SV_COLLXFRM;
078504b2
FC
1097 return sv_collxfrm_flags(sv, nxp, SV_GMAGIC);
1098}
78d57975
KW
1099
1100char *
1101Perl_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
6129b56c 1111#endif
078504b2 1112
06c841cf 1113bool
5aaab254 1114Perl_sv_2bool(pTHX_ SV *const sv)
06c841cf 1115{
1545ba5b 1116 PERL_ARGS_ASSERT_SV_2BOOL;
06c841cf
FC
1117 return sv_2bool_flags(sv, SV_GMAGIC);
1118}
1119
1830b3d9 1120
9733086d 1121/*
51b56f5c 1122=for apidoc_section Custom Operators
9733086d 1123=for apidoc custom_op_name
796b6530 1124Return the name for a given custom op. This was once used by the C<OP_NAME>
9733086d
BM
1125macro, but is no longer: it has only been kept for compatibility, and
1126should not be used.
1127
1128=for apidoc custom_op_desc
72d33970 1129Return the description of a given custom op. This was once used by the
796b6530 1130C<OP_DESC> macro, but is no longer: it has only been kept for
9733086d
BM
1131compatibility, and should not be used.
1132
1133=cut
1134*/
1135
1830b3d9
BM
1136const char*
1137Perl_custom_op_name(pTHX_ const OP* o)
1138{
1139 PERL_ARGS_ASSERT_CUSTOM_OP_NAME;
ae103e09 1140 return XopENTRYCUSTOM(o, xop_name);
1830b3d9
BM
1141}
1142
1143const char*
1144Perl_custom_op_desc(pTHX_ const OP* o)
1145{
1146 PERL_ARGS_ASSERT_CUSTOM_OP_DESC;
ae103e09 1147 return XopENTRYCUSTOM(o, xop_desc);
1830b3d9 1148}
7bff8c33
NC
1149
1150CV *
1151Perl_newSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *block)
1152{
e8f91c91 1153 return newATTRSUB(floor, o, proto, NULL, block);
7bff8c33 1154}
0c9b0438 1155
108cb980
FC
1156SV *
1157Perl_sv_mortalcopy(pTHX_ SV *const oldstr)
1158{
33971c01 1159 return Perl_sv_mortalcopy_flags(aTHX_ oldstr, SV_GMAGIC);
108cb980
FC
1160}
1161
e4524c4c
DD
1162void
1163Perl_sv_copypv(pTHX_ SV *const dsv, SV *const ssv)
1164{
1165 PERL_ARGS_ASSERT_SV_COPYPV;
1166
6338d1c6 1167 sv_copypv_flags(dsv, ssv, SV_GMAGIC);
e4524c4c
DD
1168}
1169
3d81eea6
KW
1170UV /* Made into a function, so can be deprecated */
1171NATIVE_TO_NEED(const UV enc, const UV ch)
1172{
1173 PERL_UNUSED_ARG(enc);
1174 return ch;
1175}
1176
1177UV /* Made into a function, so can be deprecated */
1178ASCII_TO_NEED(const UV enc, const UV ch)
1179{
1180 PERL_UNUSED_ARG(enc);
1181 return ch;
1182}
1183
f2645549 1184/*
51b56f5c 1185=for apidoc_section Unicode Support
f2645549
KW
1186=for apidoc is_utf8_char
1187
1188Tests if some arbitrary number of bytes begins in a valid UTF-8
1189character. Note that an INVARIANT (i.e. ASCII on non-EBCDIC machines)
1190character is a valid UTF-8 character. The actual number of bytes in the UTF-8
1191character will be returned if it is valid, otherwise 0.
1192
1193This function is deprecated due to the possibility that malformed input could
1194cause reading beyond the end of the input buffer. Use L</isUTF8_CHAR>
1195instead.
1196
1197=cut */
1198
1199STRLEN
1200Perl_is_utf8_char(const U8 *s)
1201{
1202 PERL_ARGS_ASSERT_IS_UTF8_CHAR;
1203
c6734c35 1204 /* Assumes we have enough space, which is why this is deprecated. But the
00e53078
KW
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));
f2645549
KW
1208}
1209
e4524c4c
DD
1210/*
1211=for apidoc is_utf8_char_buf
1212
09232555 1213This is identical to the macro L<perlapi/isUTF8_CHAR>.
e4524c4c
DD
1214
1215=cut */
1216
1217STRLEN
1218Perl_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
f2645549
KW
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
1231UV
1232Perl_valid_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1233{
e9b8343f 1234 PERL_UNUSED_CONTEXT;
f2645549
KW
1235 PERL_ARGS_ASSERT_VALID_UTF8_TO_UVUNI;
1236
1237 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1238}
1239
1240/*
f2645549
KW
1241=for apidoc utf8_to_uvuni
1242
1243Returns the Unicode code point of the first character in the string C<s>
1244which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1245length, in bytes, of that character.
1246
1247Some, but not all, UTF-8 malformations are detected, and in fact, some
1248malformed input could cause reading beyond the end of the input buffer, which
1249is one reason why this function is deprecated. The other is that only in
1250extremely limited circumstances should the Unicode versus native code point be
1251of any interest to you. See L</utf8_to_uvuni_buf> for alternatives.
1252
1253If C<s> points to one of the detected malformations, and UTF8 warnings are
1254enabled, zero is returned and C<*retlen> is set (if C<retlen> doesn't point to
1255NULL) to -1. If those warnings are off, the computed value if well-defined (or
1256the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1257is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1258next possible position in C<s> that could begin a non-malformed character.
09232555 1259See L<perlapi/utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
f2645549
KW
1260
1261=cut
1262*/
1263
1264UV
1265Perl_utf8_to_uvuni(pTHX_ const U8 *s, STRLEN *retlen)
1266{
e9b8343f 1267 PERL_UNUSED_CONTEXT;
f2645549
KW
1268 PERL_ARGS_ASSERT_UTF8_TO_UVUNI;
1269
1270 return NATIVE_TO_UNI(valid_utf8_to_uvchr(s, retlen));
1271}
1272
09d7a3ba 1273/*
44170c9a 1274=for apidoc pad_compname_type
09d7a3ba 1275
2d7f6611 1276Looks up the type of the lexical variable at position C<po> in the
09d7a3ba
FC
1277currently-compiling pad. If the variable is typed, the stash of the
1278class to which it is typed is returned. If not, C<NULL> is returned.
1279
1280=cut
1281*/
1282
1283HV *
1284Perl_pad_compname_type(pTHX_ const PADOFFSET po)
1285{
1286 return PAD_COMPNAME_TYPE(po);
1287}
1288
534dad48 1289/* return ptr to little string in big string, NULL if not found */
fb245905 1290/* The original version of this routine was donated by Corey Satten. */
534dad48
CB
1291
1292char *
1293Perl_instr(const char *big, const char *little)
1294{
534dad48 1295 PERL_ARGS_ASSERT_INSTR;
534dad48 1296
fb245905 1297 return instr((char *) big, (char *) little);
534dad48 1298}
0ddd4a5b 1299
238f2c13
P
1300SV *
1301Perl_newSVsv(pTHX_ SV *const old)
1302{
1303 return newSVsv(old);
1304}
1305
423ce623
P
1306bool
1307Perl_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
757fc329
P
1314char *
1315Perl_sv_2pvutf8(pTHX_ SV *sv, STRLEN *const lp)
1316{
1317 PERL_ARGS_ASSERT_SV_2PVUTF8;
1318
1319 return sv_2pvutf8(sv, lp);
1320}
1321
1322char *
1323Perl_sv_2pvbyte(pTHX_ SV *sv, STRLEN *const lp)
1324{
1325 PERL_ARGS_ASSERT_SV_2PVBYTE;
1326
1327 return sv_2pvbyte(sv, lp);
1328}
1329
86a5062a
KW
1330U8 *
1331Perl_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
1341Instead use L<perlapi/utf8_to_uvchr_buf>, or rarely, L<perlapi/utf8n_to_uvchr>.
1342
1343This function was useful for code that wanted to handle both EBCDIC and
1344ASCII platforms with Unicode properties, but starting in Perl v5.20, the
1345distinctions between the platforms have mostly been made invisible to most
1346code, so this function is quite unlikely to be what you want. If you do need
1347this precise functionality, use instead
1348C<L<NATIVE_TO_UNI(utf8_to_uvchr_buf(...))|perlapi/utf8_to_uvchr_buf>>
1349or C<L<NATIVE_TO_UNI(utf8n_to_uvchr(...))|perlapi/utf8n_to_uvchr>>.
1350
1351=cut
1352*/
1353
1354UV
1355Perl_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
1365Instead you almost certainly want to use L<perlapi/uvchr_to_utf8> or
1366L<perlapi/uvchr_to_utf8_flags>.
1367
1368This function is a deprecated synonym for L</uvoffuni_to_utf8_flags>,
1369which itself, while not deprecated, should be used only in isolated
1370circumstances. These functions were useful for code that wanted to handle
1371both EBCDIC and ASCII platforms with Unicode properties, but starting in Perl
1372v5.20, the distinctions between the platforms have mostly been made invisible
1373to most code, so this function is quite unlikely to be what you want.
1374
1375=cut
1376*/
1377
1378U8 *
1379Perl_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
1389Returns the native code point of the first character in the string C<s>
1390which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1391length, in bytes, of that character.
1392
1393Some, but not all, UTF-8 malformations are detected, and in fact, some
1394malformed input could cause reading beyond the end of the input buffer, which
1395is why this function is deprecated. Use L</utf8_to_uvchr_buf> instead.
1396
1397If C<s> points to one of the detected malformations, and UTF8 warnings are
1398enabled, zero is returned and C<*retlen> is set (if C<retlen> isn't
1399C<NULL>) to -1. If those warnings are off, the computed value if well-defined (or
1400the Unicode REPLACEMENT CHARACTER, if not) is silently returned, and C<*retlen>
1401is set (if C<retlen> isn't NULL) so that (S<C<s> + C<*retlen>>) is the
1402next possible position in C<s> that could begin a non-malformed character.
1403See L</utf8n_to_uvchr> for details on when the REPLACEMENT CHARACTER is returned.
1404
1405=cut
1406*/
1407
1408UV
1409Perl_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
238965b4
KW
1426GCC_DIAG_RESTORE
1427
20fac488
GA
1428#endif /* NO_MATHOMS */
1429
d5b2b27b 1430/*
14d04a33 1431 * ex: set ts=8 sts=4 sw=4 et:
7ee2227d 1432 */