Add parameter to internal function
authorKarl Williamson <public@khwilliamson.com>
Fri, 12 Jul 2013 20:07:49 +0000 (14:07 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 16 Jul 2013 19:58:11 +0000 (13:58 -0600)
The function invlist_set_len() has to be called after the offset header
field in an inversion list has been set.  To make sure that future
maintainers don't forget to do this, add the parameter for the 'offset'
to its call, so it can't be called without having this value.

embed.fnc
embed.h
proto.h
regcomp.c

index 03214b7..c471de2 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1436,7 +1436,7 @@ EiMR      |UV*    |invlist_array  |NN SV* const invlist
 EsM    |void   |invlist_extend    |NN SV* const invlist|const UV len
 EiMR   |bool*  |get_invlist_offset_addr|NN SV* invlist
 EiMR   |UV     |invlist_max    |NN SV* const invlist
-EiM    |void   |invlist_set_len|NN SV* const invlist|const UV len
+EiM    |void   |invlist_set_len|NN SV* const invlist|const UV len|const bool offset
 EiMR   |IV*    |get_invlist_previous_index_addr|NN SV* invlist
 EiMR   |IV     |invlist_previous_index|NN SV* const invlist
 EiM    |void   |invlist_set_previous_index|NN SV* const invlist|const IV index
diff --git a/embed.h b/embed.h
index 4870648..468d2de 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define invlist_iternext(a,b,c)        S_invlist_iternext(aTHX_ a,b,c)
 #define invlist_max(a)         S_invlist_max(aTHX_ a)
 #define invlist_previous_index(a)      S_invlist_previous_index(aTHX_ a)
-#define invlist_set_len(a,b)   S_invlist_set_len(aTHX_ a,b)
+#define invlist_set_len(a,b,c) S_invlist_set_len(aTHX_ a,b,c)
 #define invlist_set_previous_index(a,b)        S_invlist_set_previous_index(aTHX_ a,b)
 #define invlist_trim(a)                S_invlist_trim(aTHX_ a)
 #define join_exact(a,b,c,d,e,f,g)      S_join_exact(aTHX_ a,b,c,d,e,f,g)
diff --git a/proto.h b/proto.h
index f6e0883..bbe0b3e 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -6593,7 +6593,7 @@ PERL_STATIC_INLINE IV     S_invlist_previous_index(pTHX_ SV* const invlist)
 #define PERL_ARGS_ASSERT_INVLIST_PREVIOUS_INDEX        \
        assert(invlist)
 
-PERL_STATIC_INLINE void        S_invlist_set_len(pTHX_ SV* const invlist, const UV len)
+PERL_STATIC_INLINE void        S_invlist_set_len(pTHX_ SV* const invlist, const UV len, const bool offset)
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_INVLIST_SET_LEN       \
        assert(invlist)
index b4a5f57..2de7501 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7120,7 +7120,7 @@ S_invlist_array(pTHX_ SV* const invlist)
 }
 
 PERL_STATIC_INLINE void
-S_invlist_set_len(pTHX_ SV* const invlist, const UV len)
+S_invlist_set_len(pTHX_ SV* const invlist, const UV len, const bool offset)
 {
     /* Sets the current number of elements stored in the inversion list.
      * Updates SvCUR correspondingly */
@@ -7132,7 +7132,7 @@ S_invlist_set_len(pTHX_ SV* const invlist, const UV len)
     SvCUR_set(invlist,
               (len == 0)
                ? 0
-               : TO_INTERNAL_SIZE(len + *get_invlist_offset_addr(invlist)));
+               : TO_INTERNAL_SIZE(len + offset));
     assert(SvLEN(invlist) == 0 || SvCUR(invlist) <= SvLEN(invlist));
 }
 
@@ -7216,7 +7216,7 @@ Perl__new_invlist(pTHX_ IV initial_size)
     /* First 1 is in case the zero element isn't in the list; second 1 is for
      * trailing NUL */
     SvGROW(new_list, TO_INTERNAL_SIZE(initial_size + 1) + 1);
-    invlist_set_len(new_list, 0);
+    invlist_set_len(new_list, 0, 0);
 
     /* Force iterinit() to be used to get iteration to work */
     *get_invlist_iter_addr(new_list) = (STRLEN) UV_MAX;
@@ -7271,7 +7271,7 @@ S__new_invlist_C_array(pTHX_ const UV* const list)
     /* The 'length' passed to us is the physical number of elements in the
      * inversion list.  But if there is an offset the logical number is one
      * less than that */
-    invlist_set_len(invlist, length  - offset);
+    invlist_set_len(invlist, length  - offset, offset);
 
     invlist_set_previous_index(invlist, 0);
 
@@ -7315,11 +7315,13 @@ S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, const UV end
     UV* array;
     UV max = invlist_max(invlist);
     UV len = _invlist_len(invlist);
+    bool offset;
 
     PERL_ARGS_ASSERT__APPEND_RANGE_TO_INVLIST;
 
     if (len == 0) { /* Empty lists must be initialized */
-        array = _invlist_array_init(invlist, start == 0);
+        offset = start != 0;
+        array = _invlist_array_init(invlist, ! offset);
     }
     else {
        /* Here, the existing list is non-empty. The current max entry in the
@@ -7342,6 +7344,7 @@ S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, const UV end
         * value not in the set, it is extending the set, so the new first
         * value not in the set is one greater than the newly extended range.
         * */
+        offset = *get_invlist_offset_addr(invlist);
        if (array[final_element] == start) {
            if (end != UV_MAX) {
                array[final_element] = end + 1;
@@ -7349,7 +7352,7 @@ S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, const UV end
            else {
                /* But if the end is the maximum representable on the machine,
                 * just let the range that this would extend to have no end */
-               invlist_set_len(invlist, len - 1);
+               invlist_set_len(invlist, len - 1, offset);
            }
            return;
        }
@@ -7363,12 +7366,14 @@ S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, const UV end
      * be moved */
     if (max < len) {
        invlist_extend(invlist, len);
-       invlist_set_len(invlist, len);  /* Have to set len here to avoid assert
-                                          failure in invlist_array() */
+
+        /* Have to set len here to avoid assert failure in invlist_array() */
+        invlist_set_len(invlist, len, offset);
+
        array = invlist_array(invlist);
     }
     else {
-       invlist_set_len(invlist, len);
+       invlist_set_len(invlist, len, offset);
     }
 
     /* The next item on the list starts the range, the one after that is
@@ -7380,7 +7385,7 @@ S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, const UV end
     else {
        /* But if the end is the maximum representable on the machine, just let
         * the range have no end */
-       invlist_set_len(invlist, len - 1);
+       invlist_set_len(invlist, len - 1, offset);
     }
 }
 
@@ -7765,7 +7770,7 @@ Perl__invlist_union_maybe_complement_2nd(pTHX_ SV* const a, SV* const b, const b
     /* Set result to final length, which can change the pointer to array_u, so
      * re-find it */
     if (len_u != _invlist_len(u)) {
-       invlist_set_len(u, len_u);
+       invlist_set_len(u, len_u, *get_invlist_offset_addr(u));
        invlist_trim(u);
        array_u = invlist_array(u);
     }
@@ -7981,7 +7986,7 @@ Perl__invlist_intersection_maybe_complement_2nd(pTHX_ SV* const a, SV* const b,
     /* Set result to final length, which can change the pointer to array_r, so
      * re-find it */
     if (len_r != _invlist_len(r)) {
-       invlist_set_len(r, len_r);
+       invlist_set_len(r, len_r, *get_invlist_offset_addr(r));
        invlist_trim(r);
        array_r = invlist_array(r);
     }
@@ -8115,11 +8120,11 @@ Perl__invlist_invert_prop(pTHX_ SV* const invlist)
                invlist_extend(invlist, len);
                array = invlist_array(invlist);
            }
-           invlist_set_len(invlist, len);
+           invlist_set_len(invlist, len, *get_invlist_offset_addr(invlist));
            array[len - 1] = PERL_UNICODE_MAX + 1;
        }
        else {  /* Remove the 0x110000 */
-           invlist_set_len(invlist, len - 1);
+           invlist_set_len(invlist, len - 1, *get_invlist_offset_addr(invlist));
        }
     }
 
@@ -8138,12 +8143,12 @@ S_invlist_clone(pTHX_ SV* const invlist)
      * trailing NUL to SvPV's, since it thinks they are always strings */
     SV* new_invlist = _new_invlist(_invlist_len(invlist) + 1);
     STRLEN physical_length = SvCUR(invlist);
+    bool offset = *(get_invlist_offset_addr(invlist));
 
     PERL_ARGS_ASSERT_INVLIST_CLONE;
 
-    *(get_invlist_offset_addr(new_invlist))
-                                = *(get_invlist_offset_addr(invlist));
-    invlist_set_len(new_invlist, _invlist_len(invlist));
+    *(get_invlist_offset_addr(new_invlist)) = offset;
+    invlist_set_len(new_invlist, _invlist_len(invlist), offset);
     Copy(SvPVX(invlist), SvPVX(new_invlist), physical_length, char);
 
     return new_invlist;