41
41
42
42
#define PREG_JIT (1<<3)
43
43
44
+ #define PREG_JIT_ATTEMPTED (1<<4)
45
+
44
46
#define PCRE_CACHE_SIZE 4096
45
47
46
48
struct _pcre_cache_entry {
@@ -618,7 +620,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
618
620
char * p , * pp ;
619
621
char * pattern ;
620
622
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
621
627
uint32_t poptions = 0 ;
628
+ #endif
622
629
const uint8_t * tables = NULL ;
623
630
zval * zv ;
624
631
pcre_cache_entry new_entry ;
@@ -638,10 +645,19 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
638
645
back the compiled pattern, otherwise go on and compile it. */
639
646
zv = zend_hash_find (& PCRE_G (pcre_cache ), key );
640
647
if (zv ) {
641
- if (key != regex ) {
642
- zend_string_release_ex (key , 0 );
648
+ pcre_cache_entry * pce = (pcre_cache_entry * )Z_PTR_P (zv );
649
+ #ifdef HAVE_PCRE_JIT_SUPPORT
650
+ if ((bool )(pce -> preg_options & PREG_JIT_ATTEMPTED ) == jit_enabled ) {
651
+ #endif
652
+ if (key != regex ) {
653
+ zend_string_release_ex (key , 0 );
654
+ }
655
+ return pce ;
656
+ #ifdef HAVE_PCRE_JIT_SUPPORT
657
+ } else {
658
+ zend_hash_del (& PCRE_G (pcre_cache ), key );
643
659
}
644
- return ( pcre_cache_entry * ) Z_PTR_P ( zv );
660
+ #endif
645
661
}
646
662
647
663
p = ZSTR_VAL (regex );
@@ -821,7 +837,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
821
837
}
822
838
823
839
#ifdef HAVE_PCRE_JIT_SUPPORT
824
- if (PCRE_G ( jit ) ) {
840
+ if (jit_enabled ) {
825
841
/* Enable PCRE JIT compiler */
826
842
rc = pcre2_jit_compile (re , PCRE2_JIT_COMPLETE );
827
843
if (EXPECTED (rc >= 0 )) {
0 commit comments