diff options
author | Remi Collet <remi@remirepo.net> | 2024-11-29 16:11:12 +0100 |
---|---|---|
committer | Remi Collet <remi@php.net> | 2024-11-29 16:11:12 +0100 |
commit | 7dd5d9e1fb334325c3b8f3833a364f1a87d28b49 (patch) | |
tree | 42048a80929085f8748ec6b1ccf4c3366017e935 /pcre2.patch | |
parent | 28d30d7d38d2bdc964bbaae14db0e1cd6ee39b3c (diff) |
https://github.com/jbboehr/handlebars.c/pull/99
Diffstat (limited to 'pcre2.patch')
-rw-r--r-- | pcre2.patch | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/pcre2.patch b/pcre2.patch new file mode 100644 index 0000000..bdff4d5 --- /dev/null +++ b/pcre2.patch @@ -0,0 +1,99 @@ +From 8dc64d7f39ad64814d6b6be2058c8d3d7a7d7ebc Mon Sep 17 00:00:00 2001 +From: Remi Collet <remi@remirepo.net> +Date: Fri, 29 Nov 2024 15:58:32 +0100 +Subject: [PATCH] switch from pcre to pcre2 + +--- + configure.ac | 3 ++- + tests/test_spec_handlebars_parser.c | 1 - + tests/utils.c | 32 ++++++++++++++--------------- + 3 files changed, 18 insertions(+), 18 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 45c3b3e..88307db 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -377,7 +377,8 @@ AS_IF([test "x$with_mustache_spec" != "xno"], [ + # pcre + AC_ARG_ENABLE([pcre], [AS_HELP_STRING([--disable-pcre], [disable support for pcre])], []) + AS_IF([test "x$enable_pcre" != "xno"], [ +- PKG_CHECK_MODULES(PCRE, [libpcre], [enable_pcre=yes], [AC_MSG_WARN([libpcre not found])]) ++ PKG_CHECK_MODULES(PCRE, [libpcre2-8], [enable_pcre=yes], [AC_MSG_WARN([libpcre2-8 not found])]) ++ AC_DEFINE(PCRE2_CODE_UNIT_WIDTH, 8, [ ]) + ]) + AS_IF([test "x$enable_pcre" == "xyes"], [ + AC_DEFINE([HANDLEBARS_HAVE_PCRE], [1], [Use PCRE]) +diff --git a/tests/test_spec_handlebars_parser.c b/tests/test_spec_handlebars_parser.c +index 21dddba..5f506f3 100644 +--- a/tests/test_spec_handlebars_parser.c ++++ b/tests/test_spec_handlebars_parser.c +@@ -22,7 +22,6 @@ + #include <errno.h> + #include <check.h> + #include <stdio.h> +-#include <pcre.h> + #include <talloc.h> + + // json-c undeprecated json_object_object_get, but the version in xenial +diff --git a/tests/utils.c b/tests/utils.c +index 437a528..369e910 100644 +--- a/tests/utils.c ++++ b/tests/utils.c +@@ -23,7 +23,7 @@ + #include <stdio.h> + #include <string.h> + +-#include <pcre.h> ++#include <pcre2.h> + #include <talloc.h> + + #include <errno.h> +@@ -187,33 +187,33 @@ int scan_directory_callback(char * dirname, scan_directory_cb cb) + + int regex_compare(const char * regex, const char * string, char ** error) + { +- pcre * re; +- const char * errmsg = NULL; +- int erroffset; +- int ovector[30]; ++ pcre2_code *re; ++ int errorcode = 0; ++ PCRE2_UCHAR errmsg[128]; ++ PCRE2_SIZE erroffset; ++ pcre2_match_data *ovector; + int rc, ret; + +- re = pcre_compile(regex, 0, &errmsg, &erroffset, NULL); ++ re = pcre2_compile((PCRE2_SPTR)regex, PCRE2_ZERO_TERMINATED, 0, &errorcode, &erroffset, NULL); + +- if( !re ) { +- *error = talloc_asprintf(NULL, "Regex '%s' compilation failed at offset %d: %s\n", regex, erroffset, errmsg); ++ if (!re) { ++ pcre2_get_error_message(errorcode, errmsg, sizeof(errmsg)); ++ *error = talloc_asprintf(NULL, "Regex '%s' compilation failed at offset %ld: %s\n", regex, erroffset, errmsg); + return 1; +- } else if( errmsg ) { +- *error = talloc_strdup(NULL, errmsg); +- ret = 2; +- goto error; + } + +- rc = pcre_exec(re, NULL, string, (int) strlen(string), 0, 0, ovector, 30); +- if( rc <= 0 ) { ++ ovector = pcre2_match_data_create_from_pattern(re, NULL); ++ rc = pcre2_match(re, (PCRE2_SPTR)string, (PCRE2_SIZE)strlen(string), 0, 0, ovector, NULL); ++ if (rc <= 0) { + ret = 2; + *error = talloc_asprintf(NULL, "Regex '%s' didn't match string '%s'", regex, string); + } else { + ret = 0; + } + +-error: +- pcre_free(re); ++ pcre2_match_data_free(ovector); ++ pcre2_code_free(re); ++ + return ret; + } + |