com php-src: Merge branch 'PHP-5.6': ext/pcre/php_pcre.c

From: Date: Thu, 13 Aug 2015 12:28:16 +0000
Subject: com php-src: Merge branch 'PHP-5.6': ext/pcre/php_pcre.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-88514@lists.php.net to get a copy of this message
Commit: 1ec40e84d4ca1c36459012c1dee70da9753179c6 Author: Christoph M. Becker <cmb@php.net> Thu, 13 Aug 2015 14:28:16 +0200 Parents: 715d5d2855a0c6946ac99f1631a4dd9168b0cbfe cd18ba117cd3d32b760aa7e16a78947aa91e254a Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1ec40e84d4ca1c36459012c1dee70da9753179c6 Log: Merge branch 'PHP-5.6' * PHP-5.6: Fix #70232: Incorrect bump-along behavior with \K and empty string match Resolved conflicts: ext/pcre/php_pcre.c Bugs: https://bugs.php.net/70232 Changed paths: MM ext/pcre/php_pcre.c Diff: diff --cc ext/pcre/php_pcre.c index e57bbd9,c55828b..4da75ec --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@@ -888,16 -811,16 +893,16 @@@ PHPAPI void php_pcre_match_impl(pcre_ca } else break; } else { - pcre_handle_exec_error(count TSRMLS_CC); + pcre_handle_exec_error(count); break; } - + /* If we have matched an empty string, mimic what Perl's /g options does. - This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try + This turns out to be rather cunning. First we set PCRE_NOTEMPTY_ATSTART and try the match again at the same point. If this fails (picked up above) we advance to the next character. */ - g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; + g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED : 0; - + /* Advance to the position right after the last full match */ start_offset = offsets[1]; } while (global); @@@ -1240,38 -1254,14 +1245,38 @@@ PHPAPI zend_string *php_pcre_replace_im } *walkbuf = '\0'; /* increment the result length by how much we've added to the string */ - *result_len += walkbuf - (result + *result_len); + result_len += (int)(walkbuf - (ZSTR_VAL(result) + result_len)); + } else { + /* Use custom function to get replacement string and its length. */ + eval_result = preg_do_repl_func(replace_val, subject, offsets, subpat_names, count, mark); + ZEND_ASSERT(eval_result); + new_len += (int)ZSTR_LEN(eval_result); + if (new_len >= alloc_len) { + alloc_len = alloc_len + 2 * new_len; + if (result == NULL) { + result = zend_string_alloc(alloc_len, 0); + } else { + result = zend_string_extend(result, alloc_len, 0); + } + } + /* copy the part of the string before the match */ + memcpy(ZSTR_VAL(result) + result_len, piece, match-piece); + result_len += (int)(match-piece); + + /* copy replacement and backrefs */ + walkbuf = ZSTR_VAL(result) + result_len; + + /* If using custom function, copy result to the buffer and clean up. */ + memcpy(walkbuf, ZSTR_VAL(eval_result), ZSTR_LEN(eval_result)); + result_len += (int)ZSTR_LEN(eval_result); + zend_string_release(eval_result); } - if (limit != -1) + if (EXPECTED(limit)) { limit--; - - } else if (count == PCRE_ERROR_NOMATCH || limit == 0) { + } + } else if (count == PCRE_ERROR_NOMATCH || UNEXPECTED(limit == 0)) { - /* If we previously set PCRE_NOTEMPTY after a null match, + /* If we previously set PCRE_NOTEMPTY_ATSTART after a null match, this is not necessarily the end. We need to advance the start offset, and continue. Fudge the offset values to achieve this, unless we're already at the end of the string. */ @@@ -1304,20 -1288,18 +1309,20 @@@ break; } } else { - pcre_handle_exec_error(count TSRMLS_CC); - efree(result); - result = NULL; + pcre_handle_exec_error(count); + if (result) { + zend_string_free(result); + result = NULL; + } break; } - + /* If we have matched an empty string, mimic what Perl's /g options does. - This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try + This turns out to be rather cunning. First we set PCRE_NOTEMPTY_ATSTART and try the match again at the same point. If this fails (picked up above) we advance to the next character. */ - g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; + g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED : 0; - + /* Advance to the next piece. */ start_offset = offsets[1]; } @@@ -1849,11 -1696,11 +1854,11 @@@ PHPAPI void php_pcre_split_impl(pcre_ca } /* If we have matched an empty string, mimic what Perl's /g options does. - This turns out to be rather cunning. First we set PCRE_NOTEMPTY and try + This turns out to be rather cunning. First we set PCRE_NOTEMPTY_ATSTART and try the match again at the same point. If this fails (picked up above) we advance to the next character. */ - g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0; + g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED : 0; - + /* Advance to the position right after the last full match */ start_offset = offsets[1]; }

« previous php.cvs (#88514) next »