summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjvoisin2020-12-13 16:26:19 +0100
committerjvoisin2020-12-13 16:26:19 +0100
commitefec261b07e76f6c3e53beb831bbc2c65d8884d3 (patch)
tree50757bc6d8540124c70e8f81514c84f34eee4c89
parent5329a55bfd2b00d617a40d587cd37050d964ccbf (diff)
Get rid of pcre1
-rw-r--r--src/sp_pcre_compat.c24
-rw-r--r--src/sp_pcre_compat.h8
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 @@
1#include "php_snuffleupagus.h" 1#include "php_snuffleupagus.h"
2 2
3sp_pcre* sp_pcre_compile(const char* const pattern) { 3sp_pcre* sp_pcre_compile(const char* const pattern) {
4 sp_pcre* ret = NULL; 4 assert(NULL != pattern);
5#ifdef SP_HAS_PCRE2 5
6 unsigned char pcre_error[128] = {0}; 6 unsigned char pcre_error[128] = {0};
7 int errornumber; 7 int errornumber;
8 PCRE2_SIZE erroroffset; 8 PCRE2_SIZE erroroffset;
9 ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, 9 sp_pcre* ret = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
10 PCRE2_CASELESS, &errornumber, &erroroffset, NULL); 10 PCRE2_CASELESS, &errornumber, &erroroffset, NULL);
11 pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error)); 11 pcre2_get_error_message(errornumber, pcre_error, sizeof(pcre_error));
12#else
13 const char* pcre_error = NULL;
14 int erroroffset;
15 ret = pcre_compile(pattern, PCRE_CASELESS, &pcre_error, &erroroffset, NULL);
16#endif
17 12
18 if (NULL == ret) { 13 if (NULL == ret) {
19 sp_log_err("config", "Failed to compile '%s': %s on line %zu.", pattern, 14 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) {
24 19
25bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str, 20bool ZEND_HOT sp_is_regexp_matching_len(const sp_pcre* regexp, const char* str,
26 size_t len) { 21 size_t len) {
27 int ret = 0;
28
29 assert(NULL != regexp); 22 assert(NULL != regexp);
30 assert(NULL != str); 23 assert(NULL != str);
31 24
32#ifdef SP_HAS_PCRE2
33 pcre2_match_data* match_data = 25 pcre2_match_data* match_data =
34 pcre2_match_data_create_from_pattern(regexp, NULL); 26 pcre2_match_data_create_from_pattern(regexp, NULL);
35 ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL); 27 int ret = pcre2_match(regexp, (PCRE2_SPTR)str, len, 0, 0, match_data, NULL);
36#else
37 int vec[30];
38 ret = pcre_exec(regexp, NULL, str, len, 0, 0, vec, sizeof(vec) / sizeof(int));
39#endif
40 28
41 if (ret < 0) { 29 if (ret < 0) {
42#ifdef SP_HAS_PCRE2
43 if (ret != PCRE2_ERROR_NOMATCH) { 30 if (ret != PCRE2_ERROR_NOMATCH) {
44#else
45 if (ret != PCRE_ERROR_NOMATCH) {
46#endif
47 // LCOV_EXCL_START 31 // LCOV_EXCL_START
48 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret); 32 sp_log_err("regexp", "Something went wrong with a regexp (%d).", ret);
49 // LCOV_EXCL_STOP 33 // 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 @@
7#undef pcre_exec 7#undef pcre_exec
8#undef pcre_compile 8#undef pcre_compile
9 9
10/* We're not supporting pcre when it's not bundled with php7,
11 * yet. Pull-requests are welcome. */
12#if HAVE_BUNDLED_PCRE 10#if HAVE_BUNDLED_PCRE
13#if PHP_VERSION_ID >= 70300 11#if PHP_VERSION_ID >= 70300
14#define SP_HAS_PCRE2
15#include "ext/pcre/php_pcre.h" 12#include "ext/pcre/php_pcre.h"
16#else 13#else
17#include "ext/pcre/pcrelib/pcre.h" 14#include "ext/pcre/pcrelib/pcre.h"
18#endif 15#endif
19#else 16#else
20#define SP_HAS_PCRE2
21#define PCRE2_CODE_UNIT_WIDTH 8 17#define PCRE2_CODE_UNIT_WIDTH 8
22#include "pcre2.h" 18#include "pcre2.h"
23#endif 19#endif
24 20
25#ifdef SP_HAS_PCRE2
26#define sp_pcre pcre2_code 21#define sp_pcre pcre2_code
27#else
28#define sp_pcre pcre
29#endif
30 22
31sp_pcre* sp_pcre_compile(const char* str); 23sp_pcre* sp_pcre_compile(const char* str);
32#define sp_is_regexp_matching_zend(regexp, zstr) \ 24#define sp_is_regexp_matching_zend(regexp, zstr) \