regcomp.c: Add some asserts()
authorKarl Williamson <public@khwilliamson.com>
Tue, 23 Jul 2013 15:25:36 +0000 (09:25 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 23 Jul 2013 15:54:16 +0000 (09:54 -0600)
Now that inversion lists are their own scalar types, we can verify that
the parameters to their manipulation functions are indeed inversion
lists.  This adds such assertions to the bottom level code that deals
with the bare metal of the scalars.  Functions that call these (even if
only in other asserts) didn't have asserts added to them, as they call
these anyway.

inline_invlist.c
regcomp.c

index 470659b..1aea9f7 100644 (file)
@@ -25,6 +25,8 @@ S_get_invlist_offset_addr(pTHX_ SV* invlist)
 
     PERL_ARGS_ASSERT_GET_INVLIST_OFFSET_ADDR;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     return &(((XINVLIST*) SvANY(invlist))->is_offset);
 }
 
@@ -36,6 +38,8 @@ S__invlist_len(pTHX_ SV* const invlist)
 
     PERL_ARGS_ASSERT__INVLIST_LEN;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     return (SvCUR(invlist) == 0)
            ? 0
            : FROM_INTERNAL_SIZE(SvCUR(invlist)) - *get_invlist_offset_addr(invlist);
index b40425f..d9901fd 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7122,6 +7122,8 @@ S_invlist_set_len(pTHX_ SV* const invlist, const UV len, const bool offset)
 
     PERL_ARGS_ASSERT_INVLIST_SET_LEN;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     SvCUR_set(invlist,
               (len == 0)
                ? 0
@@ -7137,6 +7139,8 @@ S_get_invlist_previous_index_addr(pTHX_ SV* invlist)
 
     PERL_ARGS_ASSERT_GET_INVLIST_PREVIOUS_INDEX_ADDR;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     return &(((XINVLIST*) SvANY(invlist))->prev_index);
 }
 
@@ -7170,6 +7174,8 @@ S_invlist_max(pTHX_ SV* const invlist)
 
     PERL_ARGS_ASSERT_INVLIST_MAX;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     /* Assumes worst case, in which the 0 element is not counted in the
      * inversion list, so subtracts 1 for that */
     return SvLEN(invlist) == 0  /* This happens under _new_invlist_C_array */
@@ -7270,6 +7276,8 @@ S_invlist_extend(pTHX_ SV* const invlist, const UV new_max)
 
     PERL_ARGS_ASSERT_INVLIST_EXTEND;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     /* Add one to account for the zero element at the beginning which may not
      * be counted by the calling parameters */
     SvGROW((SV *)invlist, TO_INTERNAL_SIZE(new_max + 1));
@@ -7280,6 +7288,8 @@ S_invlist_trim(pTHX_ SV* const invlist)
 {
     PERL_ARGS_ASSERT_INVLIST_TRIM;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     /* Change the length of the inversion list to how many entries it currently
      * has */
     SvPV_shrink_to_cur((SV *) invlist);
@@ -8134,6 +8144,8 @@ S_get_invlist_iter_addr(pTHX_ SV* invlist)
 
     PERL_ARGS_ASSERT_GET_INVLIST_ITER_ADDR;
 
+    assert(SvTYPE(invlist) == SVt_INVLIST);
+
     return &(((XINVLIST*) SvANY(invlist))->iterator);
 }