summaryrefslogtreecommitdiff
path: root/ext/pcre/php_pcre.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pcre/php_pcre.c')
-rw-r--r--ext/pcre/php_pcre.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index a7c1a93646..e1c46842b9 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2018 The PHP Group |
+ | Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -862,13 +862,10 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
/* {{{ pcre_get_compiled_regex
*/
-PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count, uint32_t *preg_options)
+PHPAPI pcre2_code *pcre_get_compiled_regex(zend_string *regex, uint32_t *capture_count)
{
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
- if (preg_options) {
- *preg_options = 0;
- }
if (capture_count) {
*capture_count = pce ? pce->capture_count : 0;
}
@@ -884,7 +881,7 @@ PHPAPI pcre2_code* pcre_get_compiled_regex_ex(zend_string *regex, uint32_t *capt
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex);
if (preg_options) {
- *preg_options = 0;
+ *preg_options = pce ? pce->preg_options : 0;
}
if (compile_options) {
*compile_options = pce ? pce->compile_options : 0;
@@ -973,7 +970,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
Z_PARAM_STR(regex)
Z_PARAM_STR(subject)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL_DEREF(subpats)
+ Z_PARAM_ZVAL(subpats)
Z_PARAM_LONG(flags)
Z_PARAM_LONG(start_offset)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
@@ -984,14 +981,14 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
}
pce->refcount++;
- php_pcre_match_impl(pce, ZSTR_VAL(subject), ZSTR_LEN(subject), return_value, subpats,
+ php_pcre_match_impl(pce, subject, return_value, subpats,
global, ZEND_NUM_ARGS() >= 4, flags, start_offset);
pce->refcount--;
}
/* }}} */
/* {{{ php_pcre_match_impl() */
-PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t subject_len, zval *return_value,
+PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str, zval *return_value,
zval *subpats, int global, int use_flags, zend_long flags, zend_off_t start_offset)
{
zval result_set, /* Holds a set of subpatterns after
@@ -1013,12 +1010,17 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
pcre2_match_data *match_data;
PCRE2_SIZE start_offset2;
+ char *subject = ZSTR_VAL(subject_str);
+ size_t subject_len = ZSTR_LEN(subject_str);
+
ZVAL_UNDEF(&marks);
/* Overwrite the passed-in value for subpatterns with an empty array. */
if (subpats != NULL) {
- zval_ptr_dtor(subpats);
- array_init(subpats);
+ subpats = zend_try_array_init(subpats);
+ if (!subpats) {
+ return;
+ }
}
subpats_order = global ? PREG_PATTERN_ORDER : 0;
@@ -1102,7 +1104,8 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, size_t sub
}
}
- options = (pce->compile_options & PCRE2_UTF) ? 0 : PCRE2_NO_UTF_CHECK;
+ options = (pce->compile_options & PCRE2_UTF) && !(GC_FLAGS(subject_str) & IS_STR_VALID_UTF8)
+ ? 0 : PCRE2_NO_UTF_CHECK;
/* Execute the regular expression. */
#ifdef HAVE_PCRE_JIT_SUPPORT
@@ -1401,8 +1404,12 @@ error:
efree(subpat_names);
}
- /* Did we encounter an error? */
if (PCRE_G(error_code) == PHP_PCRE_NO_ERROR) {
+ /* If there was no error and we're in /u mode, remember that the string is valid UTF-8. */
+ if ((pce->compile_options & PCRE2_UTF) && !ZSTR_IS_INTERNED(subject_str)) {
+ GC_ADD_FLAGS(subject_str, IS_STR_VALID_UTF8);
+ }
+
RETVAL_LONG(matched);
} else {
RETVAL_FALSE;
@@ -2242,7 +2249,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, int is_filter)
Z_PARAM_ZVAL(subject)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(limit)
- Z_PARAM_ZVAL_DEREF(zcount)
+ Z_PARAM_ZVAL(zcount)
ZEND_PARSE_PARAMETERS_END();
if (Z_TYPE_P(replace) != IS_ARRAY) {
@@ -2308,8 +2315,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, int is_filter)
}
if (zcount) {
- zval_ptr_dtor(zcount);
- ZVAL_LONG(zcount, replace_count);
+ ZEND_TRY_ASSIGN_LONG(zcount, replace_count);
}
}
/* }}} */
@@ -2339,7 +2345,7 @@ static PHP_FUNCTION(preg_replace_callback)
Z_PARAM_ZVAL(subject)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(limit)
- Z_PARAM_ZVAL_DEREF(zcount)
+ Z_PARAM_ZVAL(zcount)
ZEND_PARSE_PARAMETERS_END();
if (!zend_is_callable_ex(replace, NULL, 0, NULL, &fcc, NULL)) {
@@ -2356,8 +2362,7 @@ static PHP_FUNCTION(preg_replace_callback)
replace_count = preg_replace_func_impl(return_value, regex, &fci, &fcc, subject, limit);
if (zcount) {
- zval_ptr_dtor(zcount);
- ZVAL_LONG(zcount, replace_count);
+ ZEND_TRY_ASSIGN_LONG(zcount, replace_count);
}
}
/* }}} */
@@ -2379,7 +2384,7 @@ static PHP_FUNCTION(preg_replace_callback_array)
Z_PARAM_ZVAL(subject)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(limit)
- Z_PARAM_ZVAL_DEREF(zcount)
+ Z_PARAM_ZVAL(zcount)
ZEND_PARSE_PARAMETERS_END();
fci.size = sizeof(fci);
@@ -2424,8 +2429,7 @@ static PHP_FUNCTION(preg_replace_callback_array)
} ZEND_HASH_FOREACH_END();
if (zcount) {
- zval_ptr_dtor(zcount);
- ZVAL_LONG(zcount, replace_count);
+ ZEND_TRY_ASSIGN_LONG(zcount, replace_count);
}
}
/* }}} */
@@ -2915,8 +2919,7 @@ PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
Returns the error code of the last regexp execution. */
static PHP_FUNCTION(preg_last_error)
{
- ZEND_PARSE_PARAMETERS_START(0, 0)
- ZEND_PARSE_PARAMETERS_END();
+ ZEND_PARSE_PARAMETERS_NONE();
RETURN_LONG(PCRE_G(error_code));
}
@@ -3062,12 +3065,3 @@ PHPAPI pcre2_code *php_pcre_pce_re(pcre_cache_entry *pce)
}/*}}}*/
#endif /* HAVE_PCRE || HAVE_BUNDLED_PCRE */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 fdm=marker
- * vim<600: sw=4 ts=4
- */