regcomp.c: accept NULL as inversion list param
authorKarl Williamson <public@khwilliamson.com>
Sat, 26 Feb 2011 17:16:20 +0000 (10:16 -0700)
committerKarl Williamson <public@khwilliamson.com>
Mon, 28 Feb 2011 02:21:31 +0000 (19:21 -0700)
Change the function add_range_to_invlist() to accept NULL as the
inversion list, in which case it creates it.  A common usage of this
function is to create the list if it doesn't exist before calling it, so
this just makes that code once.

embed.fnc
proto.h
regcomp.c

index 8663b21..83c6368 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1300,7 +1300,7 @@ EXMpR     |HV*    |_new_invlist   |IV initial_size
 EXMpR  |HV*    |_swash_to_invlist      |NN SV* const swash
 EXMp   |void   |_append_range_to_invlist   |NN HV* const invlist|const UV start|const UV end
 #ifdef PERL_IN_REGCOMP_C
-EsMR   |HV*    |add_range_to_invlist   |NN HV* const invlist|const UV start|const UV end
+EsMR   |HV*    |add_range_to_invlist   |NULLOK HV* invlist|const UV start|const UV end
 EiMR   |UV*    |invlist_array  |NN HV* const invlist
 EiM    |void   |invlist_destroy        |NN HV* const invlist
 EsM    |void   |invlist_extend    |NN HV* const invlist|const UV len
diff --git a/proto.h b/proto.h
index d4642aa..9c13f8f 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -5961,11 +5961,8 @@ STATIC U32       S_add_data(struct RExC_state_t *pRExC_state, U32 n, const char *s)
 #define PERL_ARGS_ASSERT_ADD_DATA      \
        assert(pRExC_state); assert(s)
 
-STATIC HV*     S_add_range_to_invlist(pTHX_ HV* const invlist, const UV start, const UV end)
-                       __attribute__warn_unused_result__
-                       __attribute__nonnull__(pTHX_1);
-#define PERL_ARGS_ASSERT_ADD_RANGE_TO_INVLIST  \
-       assert(invlist)
+STATIC HV*     S_add_range_to_invlist(pTHX_ HV* invlist, const UV start, const UV end)
+                       __attribute__warn_unused_result__;
 
 STATIC void    S_checkposixcc(pTHX_ struct RExC_state_t *pRExC_state)
                        __attribute__nonnull__(pTHX_1);
index 932da1a..bdc8343 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6249,18 +6249,25 @@ S_invlist_intersection(pTHX_ HV* const a, HV* const b)
 }
 
 STATIC HV*
-S_add_range_to_invlist(pTHX_ HV* const invlist, const UV start, const UV end)
+S_add_range_to_invlist(pTHX_ HV* invlist, const UV start, const UV end)
 {
     /* Add the range from 'start' to 'end' inclusive to the inversion list's
      * set.  A pointer to the inversion list is returned.  This may actually be
-     * a new list, in which case the passed in one has been destroyed */
+     * a new list, in which case the passed in one has been destroyed.  The
+     * passed in inversion list can be NULL, in which case a new one is created
+     * with just the one range in it */
 
     HV* range_invlist;
     HV* added_invlist;
+    UV len;
 
-    UV len = invlist_len(invlist);
-
-    PERL_ARGS_ASSERT_ADD_RANGE_TO_INVLIST;
+    if (invlist == NULL) {
+       invlist = _new_invlist(2);
+       len = 0;
+    }
+    else {
+       len = invlist_len(invlist);
+    }
 
     /* If comes after the final entry, can just append it to the end */
     if (len == 0