From 7d3276309bd0685c7739e85435e8bc9d034d5281 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Wed, 11 Mar 2026 15:51:02 +1100 Subject: [PATCH 1/2] pcre2test: detect setrlimit instead of hardcoding platform list Replace the growing platform preprocessor check for -S flag support with AC_CHECK_FUNCS/check_symbol_exists detection of setrlimit. This automatically handles any platform lacking setrlimit (WASI, VMS, etc.) without maintaining a manual list. Haiku and z/OS are kept as explicit exclusions because they provide setrlimit but don't support RLIMIT_STACK. --- CMakeLists.txt | 1 + configure.ac | 2 +- src/config-cmake.h.in | 1 + src/config.h.generic | 3 +++ src/pcre2test.c | 4 +++- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34ef6596c..92beeb24f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -196,6 +196,7 @@ endif() check_symbol_exists(mkostemp stdlib.h HAVE_MKOSTEMP) # glibc 2.7 check_symbol_exists(memfd_create "sys/mman.h" HAVE_MEMFD_CREATE) # glibc 2.27 check_symbol_exists(secure_getenv "stdlib.h" HAVE_SECURE_GETENV) # glibc 2.17 +check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) cmake_pop_check_state() check_c_source_compiles( diff --git a/configure.ac b/configure.ac index dfe545b11..3fdf115a4 100644 --- a/configure.ac +++ b/configure.ac @@ -627,7 +627,7 @@ AC_TYPE_SIZE_T # Checks for library functions. -AC_CHECK_FUNCS(memfd_create mkostemp secure_getenv) +AC_CHECK_FUNCS(memfd_create mkostemp secure_getenv setrlimit) AC_MSG_CHECKING([for realpath]) AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include diff --git a/src/config-cmake.h.in b/src/config-cmake.h.in index bcc62c046..fb994d828 100644 --- a/src/config-cmake.h.in +++ b/src/config-cmake.h.in @@ -13,6 +13,7 @@ #cmakedefine HAVE_MEMFD_CREATE 1 #cmakedefine HAVE_SECURE_GETENV 1 +#cmakedefine HAVE_SETRLIMIT 1 #cmakedefine SUPPORT_PCRE2_8 1 #cmakedefine SUPPORT_PCRE2_16 1 diff --git a/src/config.h.generic b/src/config.h.generic index 16eecd813..ad3e19b90 100644 --- a/src/config.h.generic +++ b/src/config.h.generic @@ -119,6 +119,9 @@ surrounded by #ifndef/#endif lines so that the value can be overridden by -D. */ /* Define to 1 if you have the `secure_getenv' function. */ /* #undef HAVE_SECURE_GETENV */ +/* Define to 1 if you have the `setrlimit' function. */ +/* #undef HAVE_SETRLIMIT */ + /* Define to 1 if you have the header file. */ /* #undef HAVE_STDINT_H */ diff --git a/src/pcre2test.c b/src/pcre2test.c index bd7360606..8fafd9dd3 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -150,8 +150,10 @@ patterns. */ /* Not Windows */ #else +#ifdef HAVE_SETRLIMIT #include /* These two includes are needed */ #include /* for setrlimit(). */ +#endif #if defined NATIVE_ZOS /* z/OS uses non-binary I/O */ #define INPUT_MODE "r" #define OUTPUT_MODE "w" @@ -3772,7 +3774,7 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) else if (strcmp(arg, "-S") == 0 && argc > 2 && ((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0)) { -#if defined(_WIN32) || defined(WIN32) || defined(__HAIKU__) || defined(NATIVE_ZOS) || defined(__VMS) +#if !defined(HAVE_SETRLIMIT) || defined(__HAIKU__) || defined(NATIVE_ZOS) cfprintf(clr_test_error, stderr, "pcre2test: -S is not supported on this OS\n"); exit(1); #else From 49537b60f19ba89372cf50126ce11d7eac049eb2 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Fri, 3 Apr 2026 20:01:59 +0000 Subject: [PATCH 2/2] Add comment and exclude Win32 as before --- src/pcre2test.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pcre2test.c b/src/pcre2test.c index 8fafd9dd3..f28f94b4b 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -3774,7 +3774,12 @@ while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0) else if (strcmp(arg, "-S") == 0 && argc > 2 && ((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0)) { -#if !defined(HAVE_SETRLIMIT) || defined(__HAIKU__) || defined(NATIVE_ZOS) + /* On Win32, we exclude setrlimit() regardless of whether it may have been detected + due to some Unix emulation environment. On Haiku and z/OS, setrlimit() is reported + to be detected (with the function linking successfully and RLIMIT_STACK defined in + the headers), but it does not actually work, so we exclude it as well. */ +#if defined(_WIN32) || defined(WIN32) || !defined(HAVE_SETRLIMIT) || \ + defined(__HAIKU__) || defined(NATIVE_ZOS) cfprintf(clr_test_error, stderr, "pcre2test: -S is not supported on this OS\n"); exit(1); #else