@@ -1167,6 +1167,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
11671167 HashTable * marks = NULL ; /* Array of marks for PREG_PATTERN_ORDER */
11681168 pcre2_match_data * match_data ;
11691169 PCRE2_SIZE start_offset2 , orig_start_offset ;
1170+ bool old_mdata_used ;
11701171
11711172 char * subject = ZSTR_VAL (subject_str );
11721173 size_t subject_len = ZSTR_LEN (subject_str );
@@ -1236,7 +1237,9 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
12361237 matched = 0 ;
12371238 PCRE_G (error_code ) = PHP_PCRE_NO_ERROR ;
12381239
1239- if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
1240+ old_mdata_used = mdata_used ;
1241+ if (!old_mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
1242+ mdata_used = true;
12401243 match_data = mdata ;
12411244 } else {
12421245 match_data = pcre2_match_data_create_from_pattern (pce -> re , PCRE_G (gctx_zmm ));
@@ -1433,6 +1436,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
14331436 if (match_data != mdata ) {
14341437 pcre2_match_data_free (match_data );
14351438 }
1439+ mdata_used = old_mdata_used ;
14361440
14371441 /* Add the match sets to the output array and clean up */
14381442 if (match_sets ) {
@@ -1629,6 +1633,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
16291633 size_t result_len ; /* Length of result */
16301634 zend_string * result ; /* Result of replacement */
16311635 pcre2_match_data * match_data ;
1636+ bool old_mdata_used ;
16321637
16331638 /* Calculate the size of the offsets array, and allocate memory for it. */
16341639 num_subpats = pce -> capture_count + 1 ;
@@ -1642,7 +1647,9 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
16421647 result_len = 0 ;
16431648 PCRE_G (error_code ) = PHP_PCRE_NO_ERROR ;
16441649
1645- if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
1650+ old_mdata_used = mdata_used ;
1651+ if (!old_mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
1652+ mdata_used = true;
16461653 match_data = mdata ;
16471654 } else {
16481655 match_data = pcre2_match_data_create_from_pattern (pce -> re , PCRE_G (gctx_zmm ));
@@ -1844,6 +1851,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
18441851 if (match_data != mdata ) {
18451852 pcre2_match_data_free (match_data );
18461853 }
1854+ mdata_used = old_mdata_used ;
18471855
18481856 return result ;
18491857}
@@ -2569,6 +2577,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
25692577 uint32_t num_subpats ; /* Number of captured subpatterns */
25702578 zval tmp ;
25712579 pcre2_match_data * match_data ;
2580+ bool old_mdata_used ;
25722581 char * subject = ZSTR_VAL (subject_str );
25732582
25742583 no_empty = flags & PREG_SPLIT_NO_EMPTY ;
@@ -2595,7 +2604,9 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
25952604 goto last ;
25962605 }
25972606
2598- if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
2607+ old_mdata_used = mdata_used ;
2608+ if (!old_mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
2609+ mdata_used = true;
25992610 match_data = mdata ;
26002611 } else {
26012612 match_data = pcre2_match_data_create_from_pattern (pce -> re , PCRE_G (gctx_zmm ));
@@ -2724,6 +2735,7 @@ PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, zend_string *subject_str,
27242735 if (match_data != mdata ) {
27252736 pcre2_match_data_free (match_data );
27262737 }
2738+ mdata_used = old_mdata_used ;
27272739
27282740 if (PCRE_G (error_code ) != PHP_PCRE_NO_ERROR ) {
27292741 zval_ptr_dtor (return_value );
@@ -2923,6 +2935,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
29232935 zend_ulong num_key ;
29242936 bool invert ; /* Whether to return non-matching
29252937 entries */
2938+ bool old_mdata_used ;
29262939 pcre2_match_data * match_data ;
29272940 invert = flags & PREG_GREP_INVERT ? 1 : 0 ;
29282941
@@ -2935,7 +2948,9 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
29352948
29362949 PCRE_G (error_code ) = PHP_PCRE_NO_ERROR ;
29372950
2938- if (!mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
2951+ old_mdata_used = mdata_used ;
2952+ if (!old_mdata_used && num_subpats <= PHP_PCRE_PREALLOC_MDATA_SIZE ) {
2953+ mdata_used = true;
29392954 match_data = mdata ;
29402955 } else {
29412956 match_data = pcre2_match_data_create_from_pattern (pce -> re , PCRE_G (gctx_zmm ));
@@ -3000,6 +3015,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
30003015 if (match_data != mdata ) {
30013016 pcre2_match_data_free (match_data );
30023017 }
3018+ mdata_used = old_mdata_used ;
30033019}
30043020/* }}} */
30053021
0 commit comments