This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sv_2pv_nolen, sv_2pvbyte_nolen and sv_2pvutf8_nolen can all be replaced
[perl5.git] / mathoms.c
index f165ba4..2eee3cb 100644 (file)
--- a/mathoms.c
+++ b/mathoms.c
@@ -37,6 +37,23 @@ Perl_ref(pTHX_ OP *o, I32 type)
 }
 
 /*
+=for apidoc sv_unref
+
+Unsets the RV status of the SV, and decrements the reference count of
+whatever was being referenced by the RV.  This can almost be thought of
+as a reversal of C<newSVrv>.  This is C<sv_unref_flags> with the C<flag>
+being zero.  See C<SvROK_off>.
+
+=cut
+*/
+
+void
+Perl_sv_unref(pTHX_ SV *sv)
+{
+    sv_unref_flags(sv, 0);
+}
+
+/*
 =for apidoc sv_taint
 
 Taint an SV. Use C<SvTAINTED_on> instead.
@@ -79,6 +96,69 @@ Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp)
     return sv_2pv_flags(sv, lp, SV_GMAGIC);
 }
 
+/*
+=for apidoc sv_2pv_nolen
+
+Like C<sv_2pv()>, but doesn't return the length too. You should usually
+use the macro wrapper C<SvPV_nolen(sv)> instead.
+=cut
+*/
+
+char *
+Perl_sv_2pv_nolen(pTHX_ register SV *sv)
+{
+    return sv_2pv(sv, 0);
+}
+
+/*
+=for apidoc sv_2pvbyte_nolen
+
+Return a pointer to the byte-encoded representation of the SV.
+May cause the SV to be downgraded from UTF-8 as a side-effect.
+
+Usually accessed via the C<SvPVbyte_nolen> macro.
+
+=cut
+*/
+
+char *
+Perl_sv_2pvbyte_nolen(pTHX_ register SV *sv)
+{
+    return sv_2pvbyte(sv, 0);
+}
+
+/*
+=for apidoc sv_2pvutf8_nolen
+
+Return a pointer to the UTF-8-encoded representation of the SV.
+May cause the SV to be upgraded to UTF-8 as a side-effect.
+
+Usually accessed via the C<SvPVutf8_nolen> macro.
+
+=cut
+*/
+
+char *
+Perl_sv_2pvutf8_nolen(pTHX_ register SV *sv)
+{
+    return sv_2pvutf8(sv, 0);
+}
+
+/*
+=for apidoc sv_force_normal
+
+Undo various types of fakery on an SV: if the PV is a shared string, make
+a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
+an xpvmg. See also C<sv_force_normal_flags>.
+
+=cut
+*/
+
+void
+Perl_sv_force_normal(pTHX_ register SV *sv)
+{
+    sv_force_normal_flags(sv, 0);
+}
 
 /* sv_setsv() is now a macro using Perl_sv_setsv_flags();
  * this function provided for binary compatibility only
@@ -110,6 +190,97 @@ Perl_sv_catsv(pTHX_ SV *dstr, register SV *sstr)
     sv_catsv_flags(dstr, sstr, SV_GMAGIC);
 }
 
+/*
+=for apidoc sv_iv
+
+A private implementation of the C<SvIVx> macro for compilers which can't
+cope with complex macro expressions. Always use the macro instead.
+
+=cut
+*/
+
+IV
+Perl_sv_iv(pTHX_ register SV *sv)
+{
+    if (SvIOK(sv)) {
+       if (SvIsUV(sv))
+           return (IV)SvUVX(sv);
+       return SvIVX(sv);
+    }
+    return sv_2iv(sv);
+}
+
+/*
+=for apidoc sv_uv
+
+A private implementation of the C<SvUVx> macro for compilers which can't
+cope with complex macro expressions. Always use the macro instead.
+
+=cut
+*/
+
+UV
+Perl_sv_uv(pTHX_ register SV *sv)
+{
+    if (SvIOK(sv)) {
+       if (SvIsUV(sv))
+           return SvUVX(sv);
+       return (UV)SvIVX(sv);
+    }
+    return sv_2uv(sv);
+}
+
+/*
+=for apidoc sv_nv
+
+A private implementation of the C<SvNVx> macro for compilers which can't
+cope with complex macro expressions. Always use the macro instead.
+
+=cut
+*/
+
+NV
+Perl_sv_nv(pTHX_ register SV *sv)
+{
+    if (SvNOK(sv))
+       return SvNVX(sv);
+    return sv_2nv(sv);
+}
+
+/*
+=for apidoc sv_pv
+
+Use the C<SvPV_nolen> macro instead
+
+=for apidoc sv_pvn
+
+A private implementation of the C<SvPV> macro for compilers which can't
+cope with complex macro expressions. Always use the macro instead.
+
+=cut
+*/
+
+char *
+Perl_sv_pvn(pTHX_ SV *sv, STRLEN *lp)
+{
+    if (SvPOK(sv)) {
+       *lp = SvCUR(sv);
+       return SvPVX(sv);
+    }
+    return sv_2pv(sv, lp);
+}
+
+
+char *
+Perl_sv_pvn_nomg(pTHX_ register SV *sv, STRLEN *lp)
+{
+    if (SvPOK(sv)) {
+       *lp = SvCUR(sv);
+       return SvPVX(sv);
+    }
+    return sv_2pv_flags(sv, lp, 0);
+}
+
 /* sv_pv() is now a macro using SvPV_nolen();
  * this function provided for binary compatibility only
  */
@@ -144,6 +315,27 @@ Perl_sv_pvbyte(pTHX_ SV *sv)
     return sv_pv(sv);
 }
 
+/*
+=for apidoc sv_pvbyte
+
+Use C<SvPVbyte_nolen> instead.
+
+=for apidoc sv_pvbyten
+
+A private implementation of the C<SvPVbyte> macro for compilers
+which can't cope with complex macro expressions. Always use the macro
+instead.
+
+=cut
+*/
+
+char *
+Perl_sv_pvbyten(pTHX_ SV *sv, STRLEN *lp)
+{
+    sv_utf8_downgrade(sv,0);
+    return sv_pvn(sv,lp);
+}
+
 /* sv_pvutf8 () is now a macro using Perl_sv_2pv_flags();
  * this function provided for binary compatibility only
  */
@@ -156,6 +348,37 @@ Perl_sv_pvutf8(pTHX_ SV *sv)
 }
 
 /*
+=for apidoc sv_pvutf8
+
+Use the C<SvPVutf8_nolen> macro instead
+
+=for apidoc sv_pvutf8n
+
+A private implementation of the C<SvPVutf8> macro for compilers
+which can't cope with complex macro expressions. Always use the macro
+instead.
+
+=cut
+*/
+
+char *
+Perl_sv_pvutf8n(pTHX_ SV *sv, STRLEN *lp)
+{
+    sv_utf8_upgrade(sv);
+    return sv_pvn(sv,lp);
+}
+
+/* sv_utf8_upgrade() is now a macro using sv_utf8_upgrade_flags();
+ * this function provided for binary compatibility only
+ */
+
+STRLEN
+Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
+{
+    return sv_utf8_upgrade_flags(sv, SV_GMAGIC);
+}
+
+/*
 =for apidoc A|U8 *|uvchr_to_utf8|U8 *d|UV uv
 
 Adds the UTF-8 representation of the Native codepoint C<uv> to the end