Re: [PATCH] regex: fix a SIZE_MAX macro redefinition warning
- From
Ramsay Jones <ramsay@ramsayjones.plus.com>
- Date
- Jun 5, 2016, 13:35 UTC
- Message-ID
- <57542A85.3040206@ramsayjones.plus.com>
- In-Reply-To
- <alpine.DEB.2.20.1606050815360.4250@virtualbox>
On 05/06/16 08:15, Johannes Schindelin wrote:
Show 19 quoted lines
> Hi Ramsay, > > thanks for working on this! > > On Sat, 4 Jun 2016, Ramsay Jones wrote: > >> diff --git a/Makefile b/Makefile >> index 0d59718..3f6c70a 100644 >> --- a/Makefile >> +++ b/Makefile >> @@ -1987,7 +1987,7 @@ endif >> >> ifdef NO_REGEX >> compat/regex/regex.sp compat/regex/regex.o: EXTRA_CPPFLAGS = \ >> - -DGAWK -DNO_MBSUPPORT >> + -DGAWK -DNO_MBSUPPORT -DHAVE_STDINT_H > > Maybe a comment here, something like "the fallback regex implementation > *requires* stdint.h"?
The original version of this patch looked like this:
diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c
index fba5986..d8bde06 100644
--- a/compat/regex/regcomp.c
+++ b/compat/regex/regcomp.c
@@ -18,8 +18,6 @@
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
-#include <stdint.h>
-
static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
size_t length, reg_syntax_t syntax);
static void re_compile_fastmap_iter (regex_t *bufp,
diff --git a/compat/regex/regex.c b/compat/regex/regex.c
index 6aaae00..5cb23e5 100644
--- a/compat/regex/regex.c
+++ b/compat/regex/regex.c
@@ -60,6 +60,7 @@
GNU regex allows. Include it before <regex.h>, which correctly
#undefs RE_DUP_MAX and sets it to the right value. */
#include <limits.h>
+#include <stdint.h>
#ifdef GAWK
#undef allocaSo, just move the unconditional inclusion to the start of the compilation unit root file, before the #include of the regex_internal.h header.
In some ways this is a better fix, because it makes it clear that, currently, the compat/regex code requires <stdint.h>. This would remove the need for such a comment.
This effectively makes the conditional inclusion of <stdint.h>, and the SIZE_MAX fallback, in regex_internal.h dead code. (The C99 standard _requires_ the definition of SIZE_MAX in <stdint.h>, thankfully! ;-). So, I was tempted to remove them as part of the patch. However, I also wanted to minimize the changes to the regex code, just in case we ever wanted to re-import a newer version from upstream. Setting HAVE_STDINT_H seemed like a good solution, but maybe the first patch would be more honest?
As I said earlier, I was a little concerned about the 'unconditional' aspect of the inclusion of <stdint.h>. At one time we wanted to support systems that didn't have <stdint.h> (or didn't have <inttypes.h> but did have <stdint.h>). However, it has been several months and we have not heard anyone scream, so ...
It is slightly amusing that the reason you #included <stdint.h> was to get the definition of 'intptr_t' and the C standard states that this type is optional. In practice, I suspect that the number of platforms which do not define 'intptr_t' and 'uintptr_t' in the <stdint.h> header is rather small.
Having said that ... If I'm reading the code/config correctly, HP-NONSTOP would be failing to compile at the moment. (Although it has <stdint.h>, it does not define 'intptr_t' - ie it defines 'NO_REGEX = YesPlease' and 'NO_INTPTR_T = \ UnfortunatelyYes').
> Other than that, I think this patch is an improvement.
Thanks. What do you think of replacing it with the original patch (above)?
ATB, Ramsay Jones