38
38
39
39
#define PREG_JIT (1<<3)
40
40
41
+ #define PREG_JIT_ATTEMPTED (1<<4)
42
+
41
43
#define PCRE_CACHE_SIZE 4096
42
44
43
45
#ifdef HAVE_PCRE_JIT_SUPPORT
@@ -601,7 +603,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
601
603
char * p , * pp ;
602
604
char * pattern ;
603
605
size_t pattern_len ;
606
+ #ifdef HAVE_PCRE_JIT_SUPPORT
607
+ bool jit_enabled = PCRE_G (jit );
608
+ uint32_t poptions = jit_enabled ? PREG_JIT_ATTEMPTED : 0 ;
609
+ #else
604
610
uint32_t poptions = 0 ;
611
+ #endif
605
612
const uint8_t * tables = NULL ;
606
613
zval * zv ;
607
614
pcre_cache_entry new_entry ;
@@ -621,10 +628,19 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
621
628
back the compiled pattern, otherwise go on and compile it. */
622
629
zv = zend_hash_find (& PCRE_G (pcre_cache ), key );
623
630
if (zv ) {
624
- if (key != regex ) {
625
- zend_string_release_ex (key , 0 );
631
+ pcre_cache_entry * pce = (pcre_cache_entry * )Z_PTR_P (zv );
632
+ #ifdef HAVE_PCRE_JIT_SUPPORT
633
+ if ((bool )(pce -> preg_options & PREG_JIT_ATTEMPTED ) == jit_enabled ) {
634
+ #endif
635
+ if (key != regex ) {
636
+ zend_string_release_ex (key , 0 );
637
+ }
638
+ return pce ;
639
+ #ifdef HAVE_PCRE_JIT_SUPPORT
640
+ } else {
641
+ zend_hash_del (& PCRE_G (pcre_cache ), key );
626
642
}
627
- return ( pcre_cache_entry * ) Z_PTR_P ( zv );
643
+ #endif
628
644
}
629
645
630
646
p = ZSTR_VAL (regex );
@@ -791,7 +807,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
791
807
}
792
808
793
809
#ifdef HAVE_PCRE_JIT_SUPPORT
794
- if (PCRE_G ( jit ) ) {
810
+ if (jit_enabled ) {
795
811
/* Enable PCRE JIT compiler */
796
812
rc = pcre2_jit_compile (re , PCRE2_JIT_COMPLETE );
797
813
if (EXPECTED (rc >= 0 )) {
0 commit comments