aboutsummaryrefslogtreecommitdiffstats
path: root/support/dfa.c
diff options
context:
space:
mode:
Diffstat (limited to 'support/dfa.c')
-rw-r--r--support/dfa.c75
1 files changed, 5 insertions, 70 deletions
diff --git a/support/dfa.c b/support/dfa.c
index 0bf72ffd..33de2fb8 100644
--- a/support/dfa.c
+++ b/support/dfa.c
@@ -22,6 +22,11 @@
#include <config.h>
+#include "dfa.h"
+
+#include "flexmember.h"
+#include "idx.h"
+
#include <assert.h>
#include <ctype.h>
#include <stdint.h>
@@ -30,15 +35,6 @@
#include <limits.h>
#include <string.h>
-#include "dfa.h"
-#include "flexmember.h"
-
-/* Another name for ptrdiff_t, for sizes of objects and nonnegative
- indexes into objects. It is signed to help catch integer overflow.
- It has its own name because it is for nonnegative values only. */
-typedef ptrdiff_t idx_t;
-static idx_t const IDX_MAX = PTRDIFF_MAX;
-
static bool
streq (char const *a, char const *b)
{
@@ -56,7 +52,6 @@ isasciidigit (char c)
#include <wchar.h>
-#include "intprops.h"
#include "xalloc.h"
#include "localeinfo.h"
@@ -790,66 +785,6 @@ emptyset (charclass const *s)
return w == 0;
}
-/* Grow PA, which points to an array of *NITEMS items, and return the
- location of the reallocated array, updating *NITEMS to reflect its
- new size. The new array will contain at least NITEMS_INCR_MIN more
- items, but will not contain more than NITEMS_MAX items total.
- ITEM_SIZE is the size of each item, in bytes.
-
- ITEM_SIZE and NITEMS_INCR_MIN must be positive. *NITEMS must be
- nonnegative. If NITEMS_MAX is -1, it is treated as if it were
- infinity.
-
- If PA is null, then allocate a new array instead of reallocating
- the old one.
-
- Thus, to grow an array A without saving its old contents, do
- { free (A); A = xpalloc (NULL, &AITEMS, ...); }. */
-
-static void *
-xpalloc (void *pa, idx_t *nitems, idx_t nitems_incr_min,
- ptrdiff_t nitems_max, idx_t item_size)
-{
- idx_t n0 = *nitems;
-
- /* The approximate size to use for initial small allocation
- requests. This is the largest "small" request for the GNU C
- library malloc. */
- enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };
-
- /* If the array is tiny, grow it to about (but no greater than)
- DEFAULT_MXFAST bytes. Otherwise, grow it by about 50%.
- Adjust the growth according to three constraints: NITEMS_INCR_MIN,
- NITEMS_MAX, and what the C language can represent safely. */
-
- idx_t n, nbytes;
- if (INT_ADD_WRAPV (n0, n0 >> 1, &n))
- n = IDX_MAX;
- if (0 <= nitems_max && nitems_max < n)
- n = nitems_max;
-
- idx_t adjusted_nbytes
- = ((INT_MULTIPLY_WRAPV (n, item_size, &nbytes) || SIZE_MAX < nbytes)
- ? MIN (IDX_MAX, SIZE_MAX)
- : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0);
- if (adjusted_nbytes)
- {
- n = adjusted_nbytes / item_size;
- nbytes = adjusted_nbytes - adjusted_nbytes % item_size;
- }
-
- if (! pa)
- *nitems = 0;
- if (n - n0 < nitems_incr_min
- && (INT_ADD_WRAPV (n0, nitems_incr_min, &n)
- || (0 <= nitems_max && nitems_max < n)
- || INT_MULTIPLY_WRAPV (n, item_size, &nbytes)))
- xalloc_die ();
- pa = xrealloc (pa, nbytes);
- *nitems = n;
- return pa;
-}
-
/* Ensure that the array addressed by PA holds at least I + 1 items.
Either return PA, or reallocate the array and return its new address.
Although PA may be null, the returned value is never null.