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