Reinstate "regcomp.c: Move some #defines to only file that uses them"
authorKarl Williamson <public@khwilliamson.com>
Sat, 6 Jul 2013 21:10:14 +0000 (15:10 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 16 Jul 2013 19:58:08 +0000 (13:58 -0600)
This reverts commit 247f9b19318882fd9a52fe49aa31fc8d3d3db4f7, which
reverted 05944450e0fc82eb8fc1fb5a4bf63f23785262a0, thus reinstating the
latter commit.  It turns out that the error being chased down was not
due to this commit.

Its original message was:

These were used in a header file to provide synchronization between
files.  However, the only other file that would need them is a .pl file
which doesn't have access to them.  So simplify things so that the
variables are either removed entirely if only used in a single place, or
are #defined in the area where they are used

inline_invlist.c
regcomp.c

index c6bc47e..ced42d8 100644 (file)
@@ -8,30 +8,6 @@
 
 #if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C)
 
-#define INVLIST_LEN_OFFSET 0   /* Number of elements in the inversion list */
-
-/* This is a combination of a version and data structure type, so that one
- * being passed in can be validated to be an inversion list of the correct
- * vintage.  When the structure of the header is changed, a new random number
- * in the range 2**31-1 should be generated.  Then, if an auxiliary program
- * doesn't change correspondingly, it will be discovered immediately */
-#define INVLIST_VERSION_ID_OFFSET 1
-#define INVLIST_VERSION_ID 1826693541
-
-#define INVLIST_OFFSET_OFFSET 2        /* 0 or 1 */
-/* The UV at this position contains either 0 or 1.  If 0, the inversion list
- * contains the code point U+00000, and begins at element [0] in the array,
- * which always contains 0.  If 1, the inversion list doesn't contain U+0000,
- * and it begins at element [1].  Inverting an inversion list consists of
- * adding or removing the 0 at the beginning of it.  By reserving a space for
- * that 0, inversion can be made very fast: we just flip this UV */
-
-/* For safety, when adding new elements, remember to #undef them at the end of
- * the inversion list code section */
-
-#define HEADER_LENGTH (INVLIST_OFFSET_OFFSET + 1) /* includes 1 for the constant
-                                                   0 element */
-
 /* An element is in an inversion list iff its index is even numbered: 0, 2, 4,
  * etc */
 #define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1))
index 9637212..c747071 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7075,7 +7075,6 @@ S_reg_scan_name(pTHX_ RExC_state_t *pRExC_state, U32 flags)
 #define TO_INTERNAL_SIZE(x) (((x) + 1) * sizeof(UV))
 #define FROM_INTERNAL_SIZE(x) (((x)/ sizeof(UV)) - 1)
 
-#define INVLIST_INITIAL_LEN 10
 
 PERL_STATIC_INLINE UV*
 S__invlist_array_init(pTHX_ SV* const invlist, const bool will_have_0)
@@ -7211,7 +7210,7 @@ Perl__new_invlist(pTHX_ IV initial_size)
     U8* offset_addr;
 
     if (initial_size < 0) {
-       initial_size = INVLIST_INITIAL_LEN;
+       initial_size = 10;
     }
 
     /* Allocate the initial space */
@@ -7230,9 +7229,6 @@ Perl__new_invlist(pTHX_ IV initial_size)
     *offset_addr = (U8) UV_MAX;
 
     *get_invlist_previous_index_addr(new_list) = 0;
-#if HEADER_LENGTH != 3
-#   error Need to regenerate INVLIST_VERSION_ID by running perl -E 'say int(rand 2**31-1)', and then changing the #if to the new length
-#endif
 
     return new_list;
 }
@@ -7244,15 +7240,29 @@ S__new_invlist_C_array(pTHX_ const UV* const list)
     /* Return a pointer to a newly constructed inversion list, initialized to
      * point to <list>, which has to be in the exact correct inversion list
      * form, including internal fields.  Thus this is a dangerous routine that
-     * should not be used in the wrong hands */
+     * should not be used in the wrong hands.  The passed in 'list' contains
+     * several header fields at the beginning that are not part of the
+     * inversion list body proper */
+
+    const STRLEN length = (STRLEN) list[0];
+    const UV version_id =          list[1];
+    const U8 offset = (U8)         list[2];
+#define HEADER_LENGTH 3
+    /* If any of the above changes in any way, you must change HEADER_LENGTH
+     * (if appropriate) and regenerate INVLIST_VERSION_ID by running
+     *      perl -E 'say int(rand 2**31-1)'
+     */
+#define INVLIST_VERSION_ID 1826693541/* This is a combination of a version and
+                                        data structure type, so that one being
+                                        passed in can be validated to be an
+                                        inversion list of the correct vintage.
+                                       */
 
     SV* invlist = newSV_type(SVt_PVLV);
-    STRLEN length = (STRLEN) list[INVLIST_LEN_OFFSET];
-    U8 offset = (U8) list[INVLIST_OFFSET_OFFSET];
 
     PERL_ARGS_ASSERT__NEW_INVLIST_C_ARRAY;
 
-    if (list[INVLIST_VERSION_ID_OFFSET] != INVLIST_VERSION_ID) {
+    if (version_id != INVLIST_VERSION_ID) {
         Perl_croak(aTHX_ "panic: Incorrect version for previously generated inversion list");
     }
 
@@ -8389,11 +8399,8 @@ S__invlistEQ(pTHX_ SV* const a, SV* const b, const bool complement_b)
 #endif
 
 #undef HEADER_LENGTH
-#undef INVLIST_INITIAL_LENGTH
 #undef TO_INTERNAL_SIZE
 #undef FROM_INTERNAL_SIZE
-#undef INVLIST_LEN_OFFSET
-#undef INVLIST_OFFSET_OFFSET
 #undef INVLIST_VERSION_ID
 
 /* End of inversion list object */