X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/5df2f14060151be4cc3b594dc3d3b06711029df2..b8372399b387c0e276aee3d41b3c7833dd08087b:/sv.h diff --git a/sv.h b/sv.h index 28cdf3b..449b23e 100644 --- a/sv.h +++ b/sv.h @@ -22,7 +22,6 @@ in the C enum. Test these flags with the C macro. The types are: SVt_NULL - SVt_BIND (unused) SVt_IV SVt_NV SVt_RV @@ -120,7 +119,7 @@ Type flag for I/O objects. See L. typedef enum { SVt_NULL, /* 0 */ - SVt_BIND, /* 1 */ + SVt_DUMMY, /* 1 */ SVt_IV, /* 2 */ SVt_NV, /* 3 */ /* RV was here, before it was merged with IV. */ @@ -284,7 +283,7 @@ to return a meaningful value, or check for NULLness, so it's smaller and faster. =for apidoc Am|void|SvREFCNT_dec|SV* sv -Decrements the reference count of the given SV. +Decrements the reference count of the given SV. I may be NULL. =for apidoc Am|void|SvREFCNT_dec_NN|SV* sv Same as SvREFCNT_dec, but can only be used if you know I @@ -652,13 +651,17 @@ Unsets the IV status of an SV. Tells an SV that it is an integer and disables all other OK bits. =for apidoc Am|void|SvIOK_only_UV|SV* sv -Tells and SV that it is an unsigned integer and disables all other OK bits. +Tells an SV that it is an unsigned integer and disables all other OK bits. =for apidoc Am|bool|SvIOK_UV|SV* sv -Returns a boolean indicating whether the SV contains an unsigned integer. +Returns a boolean indicating whether the SV contains an integer that must be +interpreted as unsigned. A non-negative integer whose value is within the +range of both an IV and a UV may be be flagged as either SvUOK or SVIOK. =for apidoc Am|bool|SvUOK|SV* sv -Returns a boolean indicating whether the SV contains an unsigned integer. +Returns a boolean indicating whether the SV contains an integer that must be +interpreted as unsigned. A non-negative integer whose value is within the +range of both an IV and a UV may be be flagged as either SvUOK or SVIOK. =for apidoc Am|bool|SvIOK_notUV|SV* sv Returns a boolean indicating whether the SV contains a signed integer. @@ -726,7 +729,8 @@ Only use when you are sure SvNOK is true. See also C. =for apidoc Am|char*|SvPVX|SV* sv Returns a pointer to the physical string in the SV. The SV must contain a -string. +string. Prior to 5.9.3 it is not safe to execute this macro unless the SV's +type >= SVt_PV. This is also used to store the name of an autoloaded subroutine in an XS AUTOLOAD routine. See L. @@ -797,11 +801,7 @@ Set the actual length of the string which is in the SV. See C. #define assert_not_ROK(sv) assert_(!SvROK(sv) || !SvRV(sv)) #define assert_not_glob(sv) assert_(!isGV_with_GP(sv)) -#define SvOK(sv) ((SvTYPE(sv) == SVt_BIND) \ - ? (SvFLAGS(SvRV(sv)) & SVf_OK \ - || isREGEXP(SvRV(sv))) \ - : (SvFLAGS(sv) & SVf_OK \ - || isREGEXP(sv))) +#define SvOK(sv) (SvFLAGS(sv) & SVf_OK || isREGEXP(sv)) #define SvOK_off(sv) (assert_not_ROK(sv) assert_not_glob(sv) \ SvFLAGS(sv) &= ~(SVf_OK| \ SVf_IVisUV|SVf_UTF8), \ @@ -851,8 +851,8 @@ Set the actual length of the string which is in the SV. See C. =for apidoc Am|U32|SvUTF8|SV* sv Returns a U32 value indicating the UTF-8 status of an SV. If things are set-up properly, this indicates whether or not the SV contains UTF-8 encoded data. -Call this after SvPV() in case any call to string overloading updates the -internal flag. +You should use this I a call to SvPV() or one of its variants, in +case any call to string overloading updates the internal flag. =for apidoc Am|void|SvUTF8_on|SV *sv Turn on the UTF-8 status of an SV (the data is not changed, just the flag). @@ -1470,13 +1470,17 @@ attention to precisely which outputs are influenced by which inputs. /* =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len Like C but will force the SV into containing a string (C), and -only a string (C), by hook or by crook. You want force if you are +only a string (C), by hook or by crook. You need force if you are going to update the C directly. Processes get magic. +Note that coercing an arbitrary scalar into a plain PV will potentially +strip useful data from it. For example if the SV was C, then the +referent will have its reference count decremented, and the SV itself may +be converted to an C scalar with a string buffer containing a value +such as C<"ARRAY(0x1234)">. + =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len -Like C but will force the SV into containing a string (C), and -only a string (C), by hook or by crook. You want force if you are -going to update the C directly. Doesn't process get magic. +Like C, but doesn't process get magic. =for apidoc Am|char*|SvPV|SV* sv|STRLEN len Returns a pointer to the string in the SV, or a stringified form of @@ -1484,6 +1488,15 @@ the SV if the SV does not contain a string. The SV may cache the stringified version becoming C. Handles 'get' magic. See also C for a version which guarantees to evaluate sv only once. +Note that there is no guarantee that the return value of C is +equal to C, or that C contains valid data, or that +successive calls to C. + =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len A version of C which guarantees to evaluate C only once. Only use this if C is an expression with side effects, otherwise use the @@ -1493,9 +1506,7 @@ more efficient C. Like C but doesn't process magic. =for apidoc Am|char*|SvPV_nolen|SV* sv -Returns a pointer to the string in the SV, or a stringified form of -the SV if the SV does not contain a string. The SV may cache the -stringified form becoming C. Handles 'get' magic. +Like C but doesn't set a length variable. =for apidoc Am|char*|SvPV_nomg_nolen|SV* sv Like C but doesn't process magic. @@ -1535,7 +1546,7 @@ Like C but doesn't process magic. =for apidoc Am|UV|SvUVx|SV* sv Coerces the given SV to an unsigned integer and -returns it. Guarantees to C only once. Only +returns it. Guarantees to evaluate C only once. Only use this if C is an expression with side effects, otherwise use the more efficient C. @@ -1727,9 +1738,10 @@ Like sv_utf8_upgrade, but doesn't do magic on C. #define SvTRUE_common(sv,fallback) ( \ !SvOK(sv) \ ? 0 \ - : (SvFLAGS(sv) & (SVf_POK|SVf_IOK|SVf_NOK)) \ - ? ( (SvPOK(sv) && SvPVXtrue(sv)) \ - || (SvIOK(sv) && SvIVX(sv) != 0) \ + : SvPOK(sv) \ + ? SvPVXtrue(sv) \ + : (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) \ + ? ( (SvIOK(sv) && SvIVX(sv) != 0) \ || (SvNOK(sv) && SvNVX(sv) != 0.0)) \ : (fallback)) @@ -2059,7 +2071,7 @@ alternative is to call C if you are not sure of the type of SV. #define SvPEEK(sv) "" #endif -#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no || (sv)==&PL_sv_placeholder) +#define SvIMMORTAL(sv) (SvREADONLY(sv) && ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no || (sv)==&PL_sv_placeholder)) #ifdef DEBUGGING /* exercise the immortal resurrection code in sv_free2() */