On 2025-05-19 11:56, arn...@skeeve.com wrote:
Very well. I will deal with it myself.
How about the following idea for a Gawk patch? This patch allows Gawk to
use Gnulib's regex_internal.c unchanged, by altering pma_malloc to be
compatible with GNU malloc. This should speed up Gawk slightly, by
avoiding a no-longer-needed runtime check inside pma_malloc.From de452358c2e518263093d423c402bf0aeb5f87b1 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Mon, 19 May 2025 12:22:50 -0700
Subject: [PATCH] Change pma_malloc to behave more like GNU malloc
This simplifies using Gnulib code, and makes it less
likely for glitches to occur elsewhere.
* pma.c (pma_malloc): Do not return NULL for size zero.
* regex_internal.c: Sync with Gnulib.
---
support/ChangeLog | 10 +++++++++-
support/pma.c | 3 ---
support/regex_internal.c | 9 ++-------
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/support/ChangeLog b/support/ChangeLog
index b134f79f..d2858610 100644
--- a/support/ChangeLog
+++ b/support/ChangeLog
@@ -1,3 +1,11 @@
+2025-05-19 Paul Eggert <egg...@cs.ucla.edu>
+
+ Change pma_malloc to behave more like GNU malloc
+ This simplifies using Gnulib code, and makes it less
+ likely for glitches to occur elsewhere.
+ * pma.c (pma_malloc): Do not return NULL for size zero.
+ * regex_internal.c: Sync with Gnulib.
+
2025-05-19 Arnold D. Robbins <arn...@skeeve.com>
* regex_internal.c (re_node_set_alloc): PMA returns NULL if
@@ -256,7 +264,7 @@
2021-09-22 Arnold D. Robbins <arn...@skeeve.com>
* idx.h, intprops.h: Sync with GNULIB.
-
+
2021-09-03 Arnold D. Robbins <arn...@skeeve.com>
* dfa.h: Sync with GNULIB.
diff --git a/support/pma.c b/support/pma.c
index 6221e752..849762d3 100644
--- a/support/pma.c
+++ b/support/pma.c
@@ -531,8 +531,6 @@ void * pma_malloc(size_t size) {
ASI(NULL);
if (2 == state.init) return malloc(size);
assert(!IC);
- if (0 >= size) {
- WRN("malloc(%zu) argument <= zero\n", size); SERN; }
for (int c = sc(size); c < NFL; c++) {
ao_t *h = &(state.hdr->free[c]);
// FYI("check size class %d UB %zu\n", c, UB[c]);
@@ -702,4 +700,3 @@ void pma_set_avail_mem(const ul_t v) {
}
assert(!IC);
}
-
diff --git a/support/regex_internal.c b/support/regex_internal.c
index 21b0baf2..9b89cc93 100644
--- a/support/regex_internal.c
+++ b/support/regex_internal.c
@@ -936,11 +936,6 @@ re_node_set_alloc (re_node_set *set, Idx size)
{
set->alloc = size;
set->nelem = 0;
-#if GAWK && USE_PERSISTENT_MALLOC
- // PMA returns NULL for malloc of zero bytes...
- if (size == 0)
- size = 1; // fudge it
-#endif
set->elems = re_malloc (Idx, size);
if (__glibc_unlikely (set->elems == NULL))
return REG_ESPACE;
@@ -1600,7 +1595,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));
if (__glibc_unlikely (newstate == NULL))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
@@ -1648,7 +1643,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
reg_errcode_t err;
re_dfastate_t *newstate;
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));
if (__glibc_unlikely (newstate == NULL))
return NULL;
err = re_node_set_init_copy (&newstate->nodes, nodes);
--
2.49.0