Skip to content

Commit 9fa7735

Browse files
committed
ext/pgsql: convert regex match, using pcre jit if available and enabled.
1 parent 68ae477 commit 9fa7735

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ext/pgsql/pgsql.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4679,6 +4679,7 @@ static int php_pgsql_convert_match(const zend_string *str, const char *regex , s
46794679
uint32_t options = PCRE2_NO_AUTO_CAPTURE;
46804680
size_t i;
46814681
pcre2_match_data *match_data;
4682+
PCRE2_UCHAR err_msg[128];
46824683

46834684
/* Check invalid chars for POSIX regex */
46844685
for (i = 0; i < ZSTR_LEN(str); i++) {
@@ -4695,11 +4696,22 @@ static int php_pgsql_convert_match(const zend_string *str, const char *regex , s
46954696

46964697
re = pcre2_compile((PCRE2_SPTR)regex, regex_len, options, &errnumber, &err_offset, php_pcre_cctx());
46974698
if (NULL == re) {
4698-
PCRE2_UCHAR err_msg[128];
46994699
pcre2_get_error_message(errnumber, err_msg, sizeof(err_msg));
47004700
php_error_docref(NULL, E_WARNING, "Cannot compile regex: '%s'", err_msg);
47014701
return FAILURE;
47024702
}
4703+
#if defined(HAVE_PCRE_JIT_SUPPORT)
4704+
if (PCRE_G(jit)) {
4705+
/*
4706+
* Check if the JIT pass did not work, but the regex had been compiled successfully earlier
4707+
* so let's not end it here.
4708+
*/
4709+
if (UNEXPECTED(pcre2_jit_compile(re, PCRE2_JIT_COMPLETE) != 0)) {
4710+
pcre2_get_error_message(errnumber, err_msg, sizeof(err_msg));
4711+
php_error_docref(NULL, E_WARNING, "Cannot use JIT on regex: '%s'", err_msg);
4712+
}
4713+
}
4714+
#endif
47034715

47044716
match_data = php_pcre_create_match_data(0, re);
47054717
if (NULL == match_data) {

0 commit comments

Comments
 (0)