@@ -527,7 +527,7 @@ static void free_subpats_table(zend_string **subpat_names, uint32_t num_subpats)
527527 uint32_t i ;
528528 for (i = 0 ; i < num_subpats ; i ++ ) {
529529 if (subpat_names [i ]) {
530- zend_string_release (subpat_names [i ]);
530+ zend_string_release_ex (subpat_names [i ], false );
531531 }
532532 }
533533 efree (subpat_names );
@@ -584,7 +584,7 @@ static zend_always_inline size_t calculate_unit_length(pcre_cache_entry *pce, co
584584/* }}} */
585585
586586/* {{{ pcre_get_compiled_regex_cache */
587- PHPAPI pcre_cache_entry * pcre_get_compiled_regex_cache_ex (zend_string * regex , int locale_aware )
587+ PHPAPI pcre_cache_entry * pcre_get_compiled_regex_cache_ex (zend_string * regex , bool locale_aware )
588588{
589589 pcre2_code * re = NULL ;
590590#if 10 == PCRE2_MAJOR && 37 == PCRE2_MINOR && !HAVE_BUNDLED_PCRE
@@ -655,7 +655,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
655655 }
656656
657657 start_delimiter = delimiter ;
658- if ((pp = strchr ("([{< )]}> )]}> " , delimiter )))
658+ if ((pp = strchr ("([{< )]}>" , delimiter )))
659659 delimiter = pp [5 ];
660660 end_delimiter = delimiter ;
661661
@@ -879,7 +879,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
879879/* {{{ pcre_get_compiled_regex_cache */
880880PHPAPI pcre_cache_entry * pcre_get_compiled_regex_cache (zend_string * regex )
881881{
882- return pcre_get_compiled_regex_cache_ex (regex , 1 );
882+ return pcre_get_compiled_regex_cache_ex (regex , true );
883883}
884884/* }}} */
885885
@@ -979,7 +979,7 @@ static inline void add_named(
979979/* {{{ add_offset_pair */
980980static inline void add_offset_pair (
981981 HashTable * const result , const char * subject , PCRE2_SIZE start_offset , PCRE2_SIZE end_offset ,
982- zend_string * name , uint32_t unmatched_as_null )
982+ zend_string * name , zend_long unmatched_as_null )
983983{
984984 zval match_pair ;
985985
@@ -1013,8 +1013,8 @@ static inline void add_offset_pair(
10131013static void populate_subpat_array (
10141014 zval * subpats , const char * subject , PCRE2_SIZE * offsets , zend_string * * subpat_names ,
10151015 uint32_t num_subpats , int count , const PCRE2_SPTR mark , zend_long flags ) {
1016- bool offset_capture = ( flags & PREG_OFFSET_CAPTURE ) != 0 ;
1017- bool unmatched_as_null = ( flags & PREG_UNMATCHED_AS_NULL ) != 0 ;
1016+ zend_long offset_capture = flags & PREG_OFFSET_CAPTURE ;
1017+ zend_long unmatched_as_null = flags & PREG_UNMATCHED_AS_NULL ;
10181018 zval val ;
10191019 int i ;
10201020 HashTable * subpats_ht = Z_ARRVAL_P (subpats );
@@ -1079,7 +1079,7 @@ static void populate_subpat_array(
10791079 }
10801080}
10811081
1082- static void php_do_pcre_match (INTERNAL_FUNCTION_PARAMETERS , int global ) /* {{{ */
1082+ static void php_do_pcre_match (INTERNAL_FUNCTION_PARAMETERS , bool global ) /* {{{ */
10831083{
10841084 /* parameters */
10851085 zend_string * regex ; /* Regular expression */
@@ -1105,7 +1105,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
11051105
11061106 pce -> refcount ++ ;
11071107 php_pcre_match_impl (pce , subject , return_value , subpats ,
1108- global , ZEND_NUM_ARGS () >= 4 , flags , start_offset );
1108+ global , flags , start_offset );
11091109 pce -> refcount -- ;
11101110}
11111111/* }}} */
@@ -1128,7 +1128,7 @@ static zend_always_inline bool is_known_valid_utf8(
11281128
11291129/* {{{ php_pcre_match_impl() */
11301130PHPAPI void php_pcre_match_impl (pcre_cache_entry * pce , zend_string * subject_str , zval * return_value ,
1131- zval * subpats , int global , int use_flags , zend_long flags , zend_off_t start_offset )
1131+ zval * subpats , bool global , zend_long flags , zend_off_t start_offset )
11321132{
11331133 zval result_set ; /* Holds a set of subpatterns after
11341134 a global match */
@@ -1142,17 +1142,15 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
11421142 size_t i ;
11431143 uint32_t subpats_order ; /* Order of subpattern matches */
11441144 uint32_t offset_capture ; /* Capture match offsets: yes/no */
1145- uint32_t unmatched_as_null ; /* Null non-matches: yes/no */
1145+ zend_long unmatched_as_null ; /* Null non-matches: yes/no */
11461146 PCRE2_SPTR mark = NULL ; /* Target for MARK name */
1147- zval marks ; /* Array of marks for PREG_PATTERN_ORDER */
1147+ HashTable * marks = NULL ; /* Array of marks for PREG_PATTERN_ORDER */
11481148 pcre2_match_data * match_data ;
11491149 PCRE2_SIZE start_offset2 , orig_start_offset ;
11501150
11511151 char * subject = ZSTR_VAL (subject_str );
11521152 size_t subject_len = ZSTR_LEN (subject_str );
11531153
1154- ZVAL_UNDEF (& marks );
1155-
11561154 /* Overwrite the passed-in value for subpatterns with an empty array. */
11571155 if (subpats != NULL ) {
11581156 subpats = zend_try_array_init (subpats );
@@ -1163,7 +1161,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
11631161
11641162 subpats_order = global ? PREG_PATTERN_ORDER : 0 ;
11651163
1166- if (use_flags ) {
1164+ if (flags ) {
11671165 offset_capture = flags & PREG_OFFSET_CAPTURE ;
11681166 unmatched_as_null = flags & PREG_UNMATCHED_AS_NULL ;
11691167
@@ -1173,11 +1171,11 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
11731171 */
11741172 if (flags & 0xff ) {
11751173 subpats_order = flags & 0xff ;
1176- }
1177- if (( global && ( subpats_order < PREG_PATTERN_ORDER || subpats_order > PREG_SET_ORDER )) ||
1178- (! global && subpats_order != 0 )) {
1179- zend_argument_value_error ( 4 , "must be a PREG_* constant" );
1180- RETURN_THROWS ();
1174+ if (( global && ( subpats_order < PREG_PATTERN_ORDER || subpats_order > PREG_SET_ORDER )) ||
1175+ (! global && subpats_order != 0 )) {
1176+ zend_argument_value_error ( 4 , "must be a PREG_* constant" );
1177+ RETURN_THROWS ( );
1178+ }
11811179 }
11821180 } else {
11831181 offset_capture = 0 ;
@@ -1301,18 +1299,20 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13011299 mark = pcre2_get_mark (match_data );
13021300 /* Add MARK, if available */
13031301 if (mark ) {
1304- if (Z_TYPE ( marks ) == IS_UNDEF ) {
1305- array_init ( & marks );
1302+ if (! marks ) {
1303+ marks = zend_new_array ( 0 );
13061304 }
1307- add_index_string (& marks , matched - 1 , (char * ) mark );
1305+ zval tmp ;
1306+ ZVAL_STRING (& tmp , (char * ) mark );
1307+ zend_hash_index_add_new (marks , matched - 1 , & tmp );
13081308 }
13091309 /*
13101310 * If the number of captured subpatterns on this run is
13111311 * less than the total possible number, pad the result
13121312 * arrays with NULLs or empty strings.
13131313 */
13141314 if (count < num_subpats ) {
1315- for (; i < num_subpats ; i ++ ) {
1315+ for (int i = count ; i < num_subpats ; i ++ ) {
13161316 if (offset_capture ) {
13171317 add_offset_pair (
13181318 match_sets [i ], NULL , PCRE2_UNSET , PCRE2_UNSET ,
@@ -1394,7 +1394,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13941394 /* Execute the regular expression. */
13951395#ifdef HAVE_PCRE_JIT_SUPPORT
13961396 if ((pce -> preg_options & PREG_JIT )) {
1397- if (PCRE2_UNSET == start_offset2 || start_offset2 > subject_len ) {
1397+ if (start_offset2 > subject_len ) {
13981398 pcre_handle_exec_error (PCRE2_ERROR_BADOFFSET );
13991399 break ;
14001400 }
@@ -1430,8 +1430,10 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
14301430 }
14311431 efree (match_sets );
14321432
1433- if (Z_TYPE (marks ) != IS_UNDEF ) {
1434- add_assoc_zval (subpats , "MARK" , & marks );
1433+ if (marks ) {
1434+ zval tmp ;
1435+ ZVAL_ARR (& tmp , marks );
1436+ zend_hash_str_update (Z_ARRVAL_P (subpats ), "MARK" , sizeof ("MARK" ) - 1 , & tmp );
14351437 }
14361438 }
14371439
@@ -1456,14 +1458,14 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
14561458/* {{{ Perform a Perl-style regular expression match */
14571459PHP_FUNCTION (preg_match )
14581460{
1459- php_do_pcre_match (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
1461+ php_do_pcre_match (INTERNAL_FUNCTION_PARAM_PASSTHRU , false );
14601462}
14611463/* }}} */
14621464
14631465/* {{{ Perform a Perl-style global regular expression match */
14641466PHP_FUNCTION (preg_match_all )
14651467{
1466- php_do_pcre_match (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
1468+ php_do_pcre_match (INTERNAL_FUNCTION_PARAM_PASSTHRU , true );
14671469}
14681470/* }}} */
14691471
0 commit comments