Skip to content

Commit 61c0db9

Browse files
committed
ext/pcre: Refactor populate_subpat_array() to take subject as a HashTable*
This makes the assumption the zval is always an array explicit
1 parent 69283ba commit 61c0db9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ext/pcre/php_pcre.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,12 @@ static inline void add_offset_pair(
10321032
/* }}} */
10331033

10341034
static void populate_subpat_array(
1035-
zval *subpats, const char *subject, PCRE2_SIZE *offsets, zend_string **subpat_names,
1035+
HashTable *subpats_ht, const char *subject, PCRE2_SIZE *offsets, zend_string **subpat_names,
10361036
uint32_t num_subpats, int count, const PCRE2_SPTR mark, zend_long flags) {
10371037
zend_long offset_capture = flags & PREG_OFFSET_CAPTURE;
10381038
zend_long unmatched_as_null = flags & PREG_UNMATCHED_AS_NULL;
10391039
zval val;
10401040
int i;
1041-
HashTable *subpats_ht = Z_ARRVAL_P(subpats);
10421041
if (subpat_names) {
10431042
if (offset_capture) {
10441043
for (i = 0; i < count; i++) {
@@ -1088,15 +1087,17 @@ static void populate_subpat_array(
10881087
zend_hash_next_index_insert_new(subpats_ht, &val);
10891088
}
10901089
if (unmatched_as_null) {
1090+
ZVAL_NULL(&val);
10911091
for (i = count; i < num_subpats; i++) {
1092-
add_next_index_null(subpats);
1092+
zend_hash_next_index_insert_new(subpats_ht, &val);
10931093
}
10941094
}
10951095
}
10961096
}
10971097
/* Add MARK, if available */
10981098
if (mark) {
1099-
add_assoc_string_ex(subpats, "MARK", sizeof("MARK") - 1, (char *)mark);
1099+
ZVAL_STRING(&val, (char *)mark);
1100+
zend_hash_str_add_new(subpats_ht, ZEND_STRL("MARK"), &val);
11001101
}
11011102
}
11021103

@@ -1350,7 +1351,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13501351
mark = pcre2_get_mark(match_data);
13511352
array_init_size(&result_set, count + (mark ? 1 : 0));
13521353
populate_subpat_array(
1353-
&result_set, subject, offsets, subpat_names,
1354+
Z_ARRVAL(result_set), subject, offsets, subpat_names,
13541355
num_subpats, count, mark, flags);
13551356
/* And add it to the output array */
13561357
zend_hash_next_index_insert_new(Z_ARRVAL_P(subpats), &result_set);
@@ -1359,7 +1360,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13591360
/* For each subpattern, insert it into the subpatterns array. */
13601361
mark = pcre2_get_mark(match_data);
13611362
populate_subpat_array(
1362-
subpats, subject, offsets, subpat_names, num_subpats, count, mark, flags);
1363+
Z_ARRVAL_P(subpats), subject, offsets, subpat_names, num_subpats, count, mark, flags);
13631364
break;
13641365
}
13651366
}
@@ -1552,7 +1553,7 @@ static zend_string *preg_do_repl_func(zend_fcall_info_cache *fcc, const char *su
15521553
zval arg; /* Argument to pass to function */
15531554

15541555
array_init_size(&arg, count + (mark ? 1 : 0));
1555-
populate_subpat_array(&arg, subject, offsets, subpat_names, num_subpats, count, mark, flags);
1556+
populate_subpat_array(Z_ARRVAL(arg), subject, offsets, subpat_names, num_subpats, count, mark, flags);
15561557

15571558
zend_call_known_fcc(fcc, &retval, 1, &arg, NULL);
15581559
zval_ptr_dtor(&arg);

0 commit comments

Comments
 (0)