Skip to content

Commit 5614414

Browse files
committed
test cache entry validity by "PREG_JIT_ATTEMPTED"
1 parent 4f12777 commit 5614414

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ext/pcre/php_pcre.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
#define PREG_JIT (1<<3)
4343

44+
#define PREG_JIT_ATTEMPTED (1<<4)
45+
4446
#define PCRE_CACHE_SIZE 4096
4547

4648
struct _pcre_cache_entry {
@@ -618,7 +620,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
618620
char *p, *pp;
619621
char *pattern;
620622
size_t pattern_len;
623+
#ifdef HAVE_PCRE_JIT_SUPPORT
624+
bool jit_enabled = PCRE_G(jit);
625+
uint32_t poptions = jit_enabled ? PREG_JIT_ATTEMPTED : 0;
626+
#else
621627
uint32_t poptions = 0;
628+
#endif
622629
const uint8_t *tables = NULL;
623630
zval *zv;
624631
pcre_cache_entry new_entry;
@@ -639,14 +646,18 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
639646
zv = zend_hash_find(&PCRE_G(pcre_cache), key);
640647
if (zv) {
641648
pcre_cache_entry *pce = (pcre_cache_entry*)Z_PTR_P(zv);
642-
if (!(pce->preg_options & PREG_JIT) == !PCRE_G(jit)) {
649+
#ifdef HAVE_PCRE_JIT_SUPPORT
650+
if (!!(pce->preg_options & PREG_JIT_ATTEMPTED) == jit_enabled) {
651+
#endif
643652
if (key != regex) {
644653
zend_string_release_ex(key, 0);
645654
}
646655
return pce;
656+
#ifdef HAVE_PCRE_JIT_SUPPORT
647657
} else {
648658
zend_hash_del(&PCRE_G(pcre_cache), key);
649659
}
660+
#endif
650661
}
651662

652663
p = ZSTR_VAL(regex);
@@ -826,7 +837,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
826837
}
827838

828839
#ifdef HAVE_PCRE_JIT_SUPPORT
829-
if (PCRE_G(jit)) {
840+
if (jit_enabled) {
830841
/* Enable PCRE JIT compiler */
831842
rc = pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);
832843
if (EXPECTED(rc >= 0)) {

0 commit comments

Comments
 (0)