This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Eliminate SVrepl_EVAL and SvEVALED()
[perl5.git] / sv.h
diff --git a/sv.h b/sv.h
index 331b823..c33a9a4 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -269,7 +269,8 @@ struct p5rx {
 =head1 SV Manipulation Functions
 
 =for apidoc Am|U32|SvREFCNT|SV* sv
-Returns the value of the object's reference count.
+Returns the value of the object's reference count. Exposed
+to perl code via Internals::SvREFCNT().
 
 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
 Increments the reference count of the given SV, returning the SV.
@@ -368,8 +369,7 @@ perform the upgrade if necessary.  See C<L</svtype>>.
 #define SVp_IOK                0x00001000  /* has valid non-public integer value */
 #define SVp_NOK                0x00002000  /* has valid non-public numeric value */
 #define SVp_POK                0x00004000  /* has valid non-public pointer value */
-#define SVp_SCREAM     0x00008000  /* method name is DOES */
-                                    /* eval cx text is ref counted */
+#define SVp_SCREAM     0x00008000  /* currently unused on plain scalars */
 #define SVphv_CLONEABLE        SVp_SCREAM  /* PVHV (stashes) clone its objects */
 #define SVpgv_GP       SVp_SCREAM  /* GV has a valid GP */
 #define SVprv_PCS_IMPORTED  SVp_SCREAM  /* RV is a proxy for a constant
@@ -443,7 +443,6 @@ perform the upgrade if necessary.  See C<L</svtype>>.
 
    SVf_POK, SVp_POK also set:
    0x00004400   Normal
-   0x0000C400   method name for DOES (SvSCREAM)
    0x40004400   FBM compiled (SvVALID)
    0x4000C400   *** Formerly used for pad names ***
 
@@ -457,8 +456,6 @@ perform the upgrade if necessary.  See C<L</svtype>>.
 /* This is only set true on a PVGV when it's playing "PVBM", but is tested for
    on any regular scalar (anything <= PVLV) */
 #define SVpbm_VALID    0x40000000
-/* Only used in toke.c on an SV stored in PL_lex_repl */
-#define SVrepl_EVAL    0x40000000  /* Replacement part of s///e */
 
 /* IV, PVIV, PVNV, PVMG, PVGV and (I assume) PVLV  */
 #define SVf_IVisUV     0x80000000  /* use XPVUV instead of XPVIV */
@@ -467,7 +464,7 @@ perform the upgrade if necessary.  See C<L</svtype>>.
 /* PVHV */
 #define SVphv_HASKFLAGS        0x80000000  /* keys have flag byte after hash */
 /* PVGV when SVpbm_VALID is true */
-#define SVpbm_TAIL     0x80000000
+#define SVpbm_TAIL     0x80000000  /* string has a fake "\n" appended */
 /* RV upwards. However, SVf_ROK and SVp_IOK are exclusive  */
 #define SVprv_WEAKREF   0x80000000  /* Weak reference */
 /* pad name vars only */
@@ -486,16 +483,14 @@ perform the upgrade if necessary.  See C<L</svtype>>.
 union _xnvu {
     NV     xnv_nv;             /* numeric value, if any */
     HV *    xgv_stash;
-    struct {
-       U32 xlow;
-       U32 xhigh;
-    }      xpad_cop_seq;       /* used by pad.c for cop_sequence */
+    line_t  xnv_lines;           /* used internally by S_scan_subst() */
 };
 
 union _xivu {
     IV     xivu_iv;            /* integer value */
     UV     xivu_uv;
     HEK *   xivu_namehek;      /* xpvlv, xpvgv: GvNAME */
+    bool    xivu_eval_seen;     /* used internally by S_scan_subst() */
 };
 
 union _xmgu {
@@ -617,7 +612,7 @@ struct xpvio {
      * Perl_filter_add() tries to do with the dirp), hence the
      *  following union trick (as suggested by Gurusamy Sarathy).
      * For further information see Geir Johansen's problem report
-     * titled [ID 20000612.002] Perl problem on Cray system
+     * titled [ID 20000612.002 (#3366)] Perl problem on Cray system
      * The any pointer (known as IoANY()) will also be a good place
      * to hang any IO disciplines to.
      */
@@ -838,7 +833,7 @@ Set the current length of the string which is in the SV.  See C<L</SvCUR>>
 and C<SvIV_set>>.
 
 =for apidoc Am|void|SvLEN_set|SV* sv|STRLEN len
-Set the actual length of the string which is in the SV.  See C<L</SvIV_set>>.
+Set the size of the string buffer for the SV. See C<L</SvLEN>>.
 
 =cut
 */
@@ -949,7 +944,7 @@ in gv.h: */
 
 #define SvOOK(sv)              (SvFLAGS(sv) & SVf_OOK)
 #define SvOOK_on(sv)           (SvFLAGS(sv) |= SVf_OOK)
-#define SvOOK_off(sv)          ((void)(SvOOK(sv) && sv_backoff(sv)))
+#define SvOOK_off(sv)          ((void)(SvOOK(sv) && (sv_backoff(sv),0)))
 
 #define SvFAKE(sv)             (SvFLAGS(sv) & SVf_FAKE)
 #define SvFAKE_on(sv)          (SvFLAGS(sv) |= SVf_FAKE)
@@ -1051,7 +1046,7 @@ For example, if your scalar is a reference and you want to modify the C<SvIVX>
 slot, you can't just do C<SvROK_off>, as that will leak the referent.
 
 This is used internally by various sv-modifying functions, such as
-C<sv_setsv>, C<sv_setiv> and C<sv_pvn_force..
+C<sv_setsv>, C<sv_setiv> and C<sv_pvn_force>.
 
 One case that this does not handle is a gv without SvFAKE set.  After
 
@@ -1089,6 +1084,22 @@ C<sv_force_normal> does nothing.
 #define SvOBJECT_on(sv)                (SvFLAGS(sv) |= SVs_OBJECT)
 #define SvOBJECT_off(sv)       (SvFLAGS(sv) &= ~SVs_OBJECT)
 
+/*
+=for apidoc Am|U32|SvREADONLY|SV* sv
+Returns true if the argument is readonly, otherwise returns false.
+Exposed to to perl code via Internals::SvREADONLY().
+
+=for apidoc Am|U32|SvREADONLY_on|SV* sv
+Mark an object as readonly. Exactly what this means depends on the object
+type. Exposed to perl code via Internals::SvREADONLY().
+
+=for apidoc Am|U32|SvREADONLY_off|SV* sv
+Mark an object as not-readonly. Exactly what this mean depends on the
+object type. Exposed to perl code via Internals::SvREADONLY().
+
+=cut
+*/
+
 #define SvREADONLY(sv)         (SvFLAGS(sv) & (SVf_READONLY|SVf_PROTECT))
 #ifdef PERL_CORE
 # define SvREADONLY_on(sv)     (SvFLAGS(sv) |= (SVf_READONLY|SVf_PROTECT))
@@ -1108,10 +1119,6 @@ C<sv_force_normal> does nothing.
 #  define SvCOMPILED_off(sv)
 #endif
 
-#define SvEVALED(sv)           (SvFLAGS(sv) & SVrepl_EVAL)
-#define SvEVALED_on(sv)                (SvFLAGS(sv) |= SVrepl_EVAL)
-#define SvEVALED_off(sv)       (SvFLAGS(sv) &= ~SVrepl_EVAL)
-
 #if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
 #  define SvVALID(sv)          ({ const SV *const _svvalid = (const SV*)(sv); \
                                   if (SvFLAGS(_svvalid) & SVpbm_VALID && !SvSCREAM(_svvalid)) \
@@ -1473,10 +1480,9 @@ attention to precisely which outputs are influenced by which inputs.
 
 #define SvTAINT(sv)                    \
     STMT_START {                       \
-       if (UNLIKELY(TAINTING_get)) {   \
-           if (UNLIKELY(TAINT_get))    \
-               SvTAINTED_on(sv);       \
-       }                               \
+        assert(TAINTING_get || !TAINT_get); \
+        if (UNLIKELY(TAINT_get))       \
+            SvTAINTED_on(sv);          \
     } STMT_END
 
 /*
@@ -2022,9 +2028,14 @@ Returns a pointer to the character
 buffer.  SV must be of type >= C<SVt_PV>.  One
 alternative is to call C<sv_grow> if you are not sure of the type of SV.
 
+=for apidoc Am|char *|SvPVCLEAR|SV* sv
+Ensures that sv is a SVt_PV and that its SvCUR is 0, and that it is
+properly null terminated. Equivalent to sv_setpvs(""), but more efficient.
+
 =cut
 */
 
+#define SvPVCLEAR(sv) sv_setpv_bufsize(sv,0,0)
 #define SvSHARE(sv) PL_sharehook(aTHX_ sv)
 #define SvLOCK(sv) PL_lockhook(aTHX_ sv)
 #define SvUNLOCK(sv) PL_unlockhook(aTHX_ sv)
@@ -2261,5 +2272,39 @@ Evaluates C<sv> more than once.  Sets C<len> to 0 if C<SvOOK(sv)> is false.
 #define SV_CONSTS_COUNT 35
 
 /*
+ * Bodyless IVs and NVs!
+ *
+ * Since 5.9.2, we can avoid allocating a body for SVt_IV-type SVs.
+ * Since the larger IV-holding variants of SVs store their integer
+ * values in their respective bodies, the family of SvIV() accessor
+ * macros would  naively have to branch on the SV type to find the
+ * integer value either in the HEAD or BODY. In order to avoid this
+ * expensive branch, a clever soul has deployed a great hack:
+ * We set up the SvANY pointer such that instead of pointing to a
+ * real body, it points into the memory before the location of the
+ * head. We compute this pointer such that the location of
+ * the integer member of the hypothetical body struct happens to
+ * be the same as the location of the integer member of the bodyless
+ * SV head. This now means that the SvIV() family of accessors can
+ * always read from the (hypothetical or real) body via SvANY.
+ *
+ * Since the 5.21 dev series, we employ the same trick for NVs
+ * if the architecture can support it (NVSIZE <= IVSIZE).
+ */
+
+/* The following two macros compute the necessary offsets for the above
+ * trick and store them in SvANY for SvIV() (and friends) to use. */
+
+#ifdef PERL_CORE
+#  define SET_SVANY_FOR_BODYLESS_IV(sv) \
+       SvANY(sv) =   (XPVIV*)((char*)&(sv->sv_u.svu_iv) \
+                    - STRUCT_OFFSET(XPVIV, xiv_iv))
+
+#  define SET_SVANY_FOR_BODYLESS_NV(sv) \
+       SvANY(sv) =   (XPVNV*)((char*)&(sv->sv_u.svu_nv) \
+                    - STRUCT_OFFSET(XPVNV, xnv_u.xnv_nv))
+#endif
+
+/*
  * ex: set ts=8 sts=4 sw=4 et:
  */