This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
toke.c/universal.c: consting
[perl5.git] / pod / perlapi.pod
index 716c6b1..28d7277 100644 (file)
@@ -349,7 +349,7 @@ Creates a new AV.  The reference count is set to 1.
        AV*     newAV()
 
 =for hackers
-Found in file av.c
+Found in file av.h
 
 =item sortsv
 X<sortsv>
@@ -887,21 +887,21 @@ X<pv_pretty>
            |const U32 flags
 
 Converts a string into something presentable, handling escaping via
-pv_escape() and supporting quoting and elipses. 
+pv_escape() and supporting quoting and ellipses.
 
 If the PERL_PV_PRETTY_QUOTE flag is set then the result will be 
 double quoted with any double quotes in the string escaped. Otherwise
 if the PERL_PV_PRETTY_LTGT flag is set then the result be wrapped in
 angle brackets. 
            
-If the PERL_PV_PRETTY_ELIPSES flag is set and not all characters in
-string were output then an elipses C<...> will be appended to the 
+If the PERL_PV_PRETTY_ELLIPSES flag is set and not all characters in
+string were output then an ellipsis C<...> will be appended to the
 string. Note that this happens AFTER it has been quoted.
            
 If start_color is non-null then it will be inserted after the opening
 quote (if there is one) but before the escaped text. If end_color
 is non-null then it will be inserted after the escaped text but before
-any quotes or elipses.
+any quotes or ellipses.
 
 Returns a pointer to the prettified text as held by dsv.
            
@@ -1399,13 +1399,15 @@ X<Nullav>
 
 Null AV pointer.
 
+(deprecated - use C<(AV *)NULL> instead)
+
 =for hackers
 Found in file av.h
 
 =item Nullch
 X<Nullch>
 
-Null character pointer.
+Null character pointer. (No longer available when C<PERL_CORE> is defined.)
 
 =for hackers
 Found in file handy.h
@@ -1415,6 +1417,8 @@ X<Nullcv>
 
 Null CV pointer.
 
+(deprecated - use C<(CV *)NULL> instead)
+
 =for hackers
 Found in file cv.h
 
@@ -1423,13 +1427,15 @@ X<Nullhv>
 
 Null HV pointer.
 
+(deprecated - use C<(HV *)NULL> instead)
+
 =for hackers
 Found in file hv.h
 
 =item Nullsv
 X<Nullsv>
 
-Null SV pointer.
+Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
 
 =for hackers
 Found in file handy.h
@@ -1512,7 +1518,11 @@ variable C<PL_na>, though this is rather less efficient than using a local
 variable.  Remember though, that hash keys in perl are free to contain
 embedded nulls, so using C<strlen()> or similar is not a good way to find
 the length of hash keys. This is very similar to the C<SvPV()> macro
-described elsewhere in this document.
+described elsewhere in this document. See also C<HeUTF8>.
+
+If you are using C<HePV> to get values to pass to C<newSVpvn()> to create a
+new SV, you should consider using C<newSVhek(HeKEY_hek(he))> as it is more
+efficient.
 
        char*   HePV(HE* he, STRLEN len)
 
@@ -1553,6 +1563,20 @@ C<SV*>.
 =for hackers
 Found in file hv.h
 
+=item HeUTF8
+X<HeUTF8>
+
+Returns whether the C<char *> value returned by C<HePV> is encoded in UTF-8,
+doing any necessary dereferencing of possibly C<SV*> keys.  The value returned
+will be 0 or non-0, not necessarily 1 (or even a value with any low bits set),
+so B<do not> blindly assign this to a C<bool> variable, as C<bool> may be a
+typedef for C<char>.
+
+       char*   HeUTF8(HE* he, STRLEN len)
+
+=for hackers
+Found in file hv.h
+
 =item HeVAL
 X<HeVAL>
 
@@ -1912,7 +1936,7 @@ Creates a new HV.  The reference count is set to 1.
        HV*     newHV()
 
 =for hackers
-Found in file hv.c
+Found in file hv.h
 
 
 =back
@@ -2594,6 +2618,19 @@ wrapper for C<strncmp>).
 =for hackers
 Found in file handy.h
 
+=item sv_destroyable
+X<sv_destroyable>
+
+Dummy routine which reports that object can be destroyed when there is no
+sharing module present.  It ignores its single SV argument, and returns
+'true'.  Exists to avoid test for a NULL function pointer and because it
+could potentially warn under some level of strict-ness.
+
+       bool    sv_destroyable(SV *sv)
+
+=for hackers
+Found in file util.c
+
 =item sv_nosharing
 X<sv_nosharing>
 
@@ -3275,8 +3312,7 @@ Found in file pp.h
 X<mPUSHi>
 
 Push an integer onto the stack.  The stack must have room for this element.
-Handles 'set' magic.  Does not use C<TARG>.  See also C<PUSHi>, C<mXPUSHi>
-and C<XPUSHi>.
+Does not use C<TARG>.  See also C<PUSHi>, C<mXPUSHi> and C<XPUSHi>.
 
        void    mPUSHi(IV iv)
 
@@ -3287,8 +3323,7 @@ Found in file pp.h
 X<mPUSHn>
 
 Push a double onto the stack.  The stack must have room for this element.
-Handles 'set' magic.  Does not use C<TARG>.  See also C<PUSHn>, C<mXPUSHn>
-and C<XPUSHn>.
+Does not use C<TARG>.  See also C<PUSHn>, C<mXPUSHn> and C<XPUSHn>.
 
        void    mPUSHn(NV nv)
 
@@ -3299,20 +3334,30 @@ Found in file pp.h
 X<mPUSHp>
 
 Push a string onto the stack.  The stack must have room for this element.
-The C<len> indicates the length of the string.  Handles 'set' magic.  Does
-not use C<TARG>.  See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
+The C<len> indicates the length of the string.  Does not use C<TARG>.
+See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
 
        void    mPUSHp(char* str, STRLEN len)
 
 =for hackers
 Found in file pp.h
 
+=item mPUSHs
+X<mPUSHs>
+
+Push an SV onto the stack and mortalizes the SV.  The stack must have room
+for this element.  Does not use C<TARG>.  See also C<PUSHs> and C<mXPUSHs>.
+
+       void    mPUSHs(SV* sv)
+
+=for hackers
+Found in file pp.h
+
 =item mPUSHu
 X<mPUSHu>
 
 Push an unsigned integer onto the stack.  The stack must have room for this
-element.  Handles 'set' magic.  Does not use C<TARG>.  See also C<PUSHu>,
-C<mXPUSHu> and C<XPUSHu>.
+element.  Does not use C<TARG>.  See also C<PUSHu>, C<mXPUSHu> and C<XPUSHu>.
 
        void    mPUSHu(UV uv)
 
@@ -3322,9 +3367,8 @@ Found in file pp.h
 =item mXPUSHi
 X<mXPUSHi>
 
-Push an integer onto the stack, extending the stack if necessary.  Handles
-'set' magic.  Does not use C<TARG>.  See also C<XPUSHi>, C<mPUSHi> and
-C<PUSHi>.
+Push an integer onto the stack, extending the stack if necessary.
+Does not use C<TARG>.  See also C<XPUSHi>, C<mPUSHi> and C<PUSHi>.
 
        void    mXPUSHi(IV iv)
 
@@ -3334,9 +3378,8 @@ Found in file pp.h
 =item mXPUSHn
 X<mXPUSHn>
 
-Push a double onto the stack, extending the stack if necessary.  Handles
-'set' magic.  Does not use C<TARG>.  See also C<XPUSHn>, C<mPUSHn> and
-C<PUSHn>.
+Push a double onto the stack, extending the stack if necessary.
+Does not use C<TARG>.  See also C<XPUSHn>, C<mPUSHn> and C<PUSHn>.
 
        void    mXPUSHn(NV nv)
 
@@ -3347,20 +3390,30 @@ Found in file pp.h
 X<mXPUSHp>
 
 Push a string onto the stack, extending the stack if necessary.  The C<len>
-indicates the length of the string.  Handles 'set' magic.  Does not use
-C<TARG>.  See also C<XPUSHp>, C<mPUSHp> and C<PUSHp>.
+indicates the length of the string.  Does not use C<TARG>.  See also C<XPUSHp>,
+C<mPUSHp> and C<PUSHp>.
 
        void    mXPUSHp(char* str, STRLEN len)
 
 =for hackers
 Found in file pp.h
 
+=item mXPUSHs
+X<mXPUSHs>
+
+Push an SV onto the stack, extending the stack if necessary and mortalizes
+the SV.  Does not use C<TARG>.  See also C<XPUSHs> and C<mPUSHs>.
+
+       void    mXPUSHs(SV* sv)
+
+=for hackers
+Found in file pp.h
+
 =item mXPUSHu
 X<mXPUSHu>
 
 Push an unsigned integer onto the stack, extending the stack if necessary.
-Handles 'set' magic.  Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu>
-and C<PUSHu>.
+Does not use C<TARG>.  See also C<XPUSHu>, C<mPUSHu> and C<PUSHu>.
 
        void    mXPUSHu(UV uv)
 
@@ -3474,8 +3527,7 @@ Found in file pp.h
 X<PUSHmortal>
 
 Push a new mortal SV onto the stack.  The stack must have room for this
-element.  Does not handle 'set' magic.  Does not use C<TARG>.  See also
-C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
+element.  Does not use C<TARG>.  See also C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
 
        void    PUSHmortal()
 
@@ -3582,9 +3634,8 @@ Found in file pp.h
 =item XPUSHmortal
 X<XPUSHmortal>
 
-Push a new mortal SV onto the stack, extending the stack if necessary.  Does
-not handle 'set' magic.  Does not use C<TARG>.  See also C<XPUSHs>,
-C<PUSHmortal> and C<PUSHs>.
+Push a new mortal SV onto the stack, extending the stack if necessary.
+Does not use C<TARG>.  See also C<XPUSHs>, C<PUSHmortal> and C<PUSHs>.
 
        void    XPUSHmortal()
 
@@ -3905,6 +3956,17 @@ incremented.
 =for hackers
 Found in file sv.h
 
+=item newSVpvn_utf8
+X<newSVpvn_utf8>
+
+Creates a new SV and copies a string into it.  If utf8 is true, calls
+C<SvUTF8_on> on the new SV.  Implemented as a wrapper around C<newSVpvn_flags>.
+
+       SV*     newSVpvn_utf8(NULLOK const char* s, STRLEN len, U32 utf8)
+
+=for hackers
+Found in file sv.h
+
 =item SvCUR
 X<SvCUR>
 
@@ -4297,16 +4359,32 @@ Found in file sv.h
 =item SvOOK
 X<SvOOK>
 
-Returns a U32 indicating whether the SvIVX is a valid offset value for
-the SvPVX.  This hack is used internally to speed up removal of characters
-from the beginning of a SvPV.  When SvOOK is true, then the start of the
-allocated string buffer is really (SvPVX - SvIVX).
+Returns a U32 indicating whether the pointer to the string buffer is offset.
+This hack is used internally to speed up removal of characters from the
+beginning of a SvPV.  When SvOOK is true, then the start of the
+allocated string buffer is actually C<SvOOK_offset()> bytes before SvPVX.
+This offset used to be stored in SvIVX, but is now stored within the spare
+part of the buffer.
 
        U32     SvOOK(SV* sv)
 
 =for hackers
 Found in file sv.h
 
+=item SvOOK_offset
+X<SvOOK_offset>
+
+Reads into I<len> the offset from SvPVX back to the true start of the
+allocated buffer, which will be non-zero if C<sv_chop> has been used to
+efficiently remove characters from start of the buffer. Implemented as a
+macro, which takes the address of I<len>, which must be of type C<STRLEN>.
+Evaluates I<sv> more than once. Sets I<len> to 0 if C<SvOOK(sv)> is false.
+
+       void    SvOOK_offset(NN SV*sv, STRLEN len)
+
+=for hackers
+Found in file sv.h
+
 =item SvPOK
 X<SvPOK>
 
@@ -4969,7 +5047,7 @@ Returns a boolean indicating whether the SV is derived from the specified class
 I<at the C level>.  To check derivation at the Perl level, call C<isa()> as a
 normal Perl method.
 
-       bool    sv_derived_from(SV* sv, const char* name)
+       bool    sv_derived_from(SV* sv, const char *const name)
 
 =for hackers
 Found in file universal.c
@@ -4980,7 +5058,7 @@ X<sv_does>
 Returns a boolean indicating whether the SV performs a specific, named role.
 The SV can be a Perl object or the name of a Perl class.
 
-       bool    sv_does(SV* sv, const char* name)
+       bool    sv_does(SV* sv, const char *const name)
 
 =for hackers
 Found in file universal.c
@@ -5124,6 +5202,26 @@ C<len> bytes long.  If the C<s> argument is NULL the new SV will be undefined.
 =for hackers
 Found in file sv.c
 
+=item newSVpvn_flags
+X<newSVpvn_flags>
+
+Creates a new SV and copies a string into it.  The reference count for the
+SV is set to 1.  Note that if C<len> is zero, Perl will create a zero length
+string.  You are responsible for ensuring that the source string is at least
+C<len> bytes long.  If the C<s> argument is NULL the new SV will be undefined.
+Currently the only flag bits accepted are C<SVf_UTF8> and C<SVs_TEMP>.
+If C<SVs_TEMP> is set, then C<sv2mortal()> is called on the result before
+returning. If C<SVf_UTF8> is set, then it will be set on the new SV.
+C<newSVpvn_utf8()> is a convenience wrapper for this function, defined as
+
+    #define newSVpvn_utf8(s, len, u)                   \
+       newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0)
+
+       SV*     newSVpvn_flags(const char* s, STRLEN len, U32 flags)
+
+=for hackers
+Found in file sv.c
+
 =item newSVpvn_share
 X<newSVpvn_share>
 
@@ -5150,6 +5248,17 @@ Like C<newSVpvn>, but takes a literal string instead of a string/length pair.
 =for hackers
 Found in file handy.h
 
+=item newSVpvs_flags
+X<newSVpvs_flags>
+
+Like C<newSVpvn_flags>, but takes a literal string instead of a string/length
+pair.
+
+       SV*     newSVpvs_flags(const char* s, U32 flags)
+
+=for hackers
+Found in file handy.h
+
 =item newSVpvs_share
 X<newSVpvs_share>
 
@@ -5199,7 +5308,7 @@ Found in file sv.c
 =item newSV_type
 X<newSV_type>
 
-Creates a new SV, of the type specificied.  The reference count for the new SV
+Creates a new SV, of the type specified.  The reference count for the new SV
 is set to 1.
 
        SV*     newSV_type(svtype type)
@@ -5516,7 +5625,7 @@ X<sv_cmp_locale>
 
 Compares the strings in two SVs in a locale-aware manner. Is UTF-8 and
 'use bytes' aware, handles get magic, and will coerce its args to strings
-if necessary.  See also C<sv_cmp_locale>.  See also C<sv_cmp>.
+if necessary.  See also C<sv_cmp>.
 
        I32     sv_cmp_locale(SV* sv1, SV* sv2)