From 98ed3be52fa15521ef405fc8029176279d80778e Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Thu, 24 Dec 2020 10:32:28 +0000 Subject: Add PHP8 support --- src/sp_pcre_compat.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/sp_pcre_compat.c') diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index c575a79..d2efc71 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c @@ -3,14 +3,21 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { assert(NULL != pattern); + sp_pcre* ret = NULL; +#ifdef SP_HAS_PCRE2 unsigned char pcre_error[128] = {0}; int errornumber; PCRE2_SIZE erroroffset; - sp_pcre* ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, + ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errornumber, &erroroffset, NULL); + pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)); +#else + const char* pcre_error = NULL; + int erroroffset; + ret = php_pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); +#endif if (NULL == ret) { - pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)); sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, pcre_error, sp_line_no); } @@ -19,15 +26,26 @@ sp_pcre* sp_pcre_compile(const char* const pattern) { bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, size_t len) { + int ret = 0; + assert(NULL != regexp); assert(NULL != str); +#ifdef SP_HAS_PCRE2 pcre2_match_data* match_data = pcre2_match_data_create_from_pattern(regexp, NULL); - int ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); + ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); +#else + int vec[30]; + ret = php_pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); +#endif if (ret < 0) { +#ifdef SP_HAS_PCRE2 if (ret != PCRE2_ERROR_NOMATCH) { +#else + if (ret != PCRE_ERROR_NOMATCH) { +#endif // LCOV_EXCL_START sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret); // LCOV_EXCL_STOP -- cgit v1.3