From efec261b07e76f6c3e53beb831bbc2c65d8884d3 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 13 Dec 2020 16:26:19 +0100 Subject: Get rid of pcre1 --- src/sp_pcre_compat.c | 24 ++++-------------------- src/sp_pcre_compat.h | 8 -------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/sp_pcre_compat.c b/src/sp_pcre_compat.c index 3f8ff1e..d3a10af 100644 --- a/src/sp_pcre_compat.c +++ b/src/sp_pcre_compat.c @@ -1,19 +1,14 @@ #include "php_snuffleupagus.h" sp_pcre* sp_pcre_compile(const char* const pattern) { - sp_pcre* ret = NULL; -#ifdef SP_HAS_PCRE2 + assert(NULL != pattern); + unsigned char pcre_error[128] = {0}; int errornumber; PCRE2_SIZE erroroffset; - ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, + sp_pcre* 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 = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL); -#endif if (NULL == ret) { sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, @@ -24,26 +19,15 @@ 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); - ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); -#else - int vec[30]; - ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int)); -#endif + int ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); 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 diff --git a/src/sp_pcre_compat.h b/src/sp_pcre_compat.h index b429683..6fcb383 100644 --- a/src/sp_pcre_compat.h +++ b/src/sp_pcre_compat.h @@ -7,26 +7,18 @@ #undef pcre_exec #undef pcre_compile -/* We're not supporting pcre when it's not bundled with php7, - * yet. Pull-requests are welcome. */ #if HAVE_BUNDLED_PCRE #if PHP_VERSION_ID >= 70300 -#define SP_HAS_PCRE2 #include "ext/pcre/php_pcre.h" #else #include "ext/pcre/pcrelib/pcre.h" #endif #else -#define SP_HAS_PCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 #include "pcre2.h" #endif -#ifdef SP_HAS_PCRE2 #define sp_pcre pcre2_code -#else -#define sp_pcre pcre -#endif sp_pcre* sp_pcre_compile(const char* str); #define sp_is_regexp_matching_zend(regexp, zstr) \ -- cgit v1.3