/* }}} */
/* {{{ static pcre_clean_cache */
-static int pcre_clean_cache(void *data, void *arg TSRMLS_DC)
+static int pcre_clean_cache(zval *data, void *arg)
{
- pcre_cache_entry *pce = (pcre_cache_entry *) data;
++ pcre_cache_entry *pce = (pcre_cache_entry *) Z_PTR_P(data);
int *num_clean = (int *)arg;
- if (*num_clean > 0) {
+ if (*num_clean > 0 && !pce->refcount) {
(*num_clean)--;
- return 1;
+ return ZEND_HASH_APPLY_REMOVE;
} else {
- return 0;
+ return ZEND_HASH_APPLY_KEEP;
}
}
/* }}} */
new_entry.preg_options = poptions;
new_entry.compile_options = coptions;
#if HAVE_SETLOCALE
- new_entry.locale = pestrdup(locale, 1);
+ new_entry.locale = BG(locale_string) ?
+ ((GC_FLAGS(BG(locale_string)) & IS_STR_PERSISTENT) ?
+ zend_string_copy(BG(locale_string)) :
+ zend_string_init(BG(locale_string)->val, BG(locale_string)->len, 1)) :
+ NULL;
new_entry.tables = tables;
#endif
+ new_entry.refcount = 0;
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &new_entry.capture_count);
+ if (rc < 0) {
+ php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
+ return NULL;
+ }
+
+ rc = pcre_fullinfo(re, extra, PCRE_INFO_NAMECOUNT, &new_entry.name_count);
+ if (rc < 0) {
+ php_error_docref(NULL, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
+ return NULL;
+ }
+
/*
* Interned strings are not duplicated when stored in HashTable,
* but all the interned strings created during HTTP request are removed
RETURN_FALSE;
}
- php_pcre_match_impl(pce, subject, subject_len, return_value, subpats,
- global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC);
+ pce->refcount++;
+ php_pcre_match_impl(pce, subject->val, (int)subject->len, return_value, subpats,
+ global, ZEND_NUM_ARGS() >= 4, flags, start_offset);
+ pce->refcount--;
}
/* }}} */
/* {{{ php_pcre_replace
*/
-PHPAPI char *php_pcre_replace(char *regex, int regex_len,
+PHPAPI zend_string *php_pcre_replace(zend_string *regex,
+ zend_string *subject_str,
char *subject, int subject_len,
zval *replace_val, int is_callable_replace,
- int *result_len, int limit, int *replace_count TSRMLS_DC)
+ int limit, int *replace_count)
{
pcre_cache_entry *pce; /* Compiled regular expression */
- char *result; /* Function result */
++ zend_string *result; /* Function result */
/* Compile regex or get it from cache. */
- if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
+ if ((pce = pcre_get_compiled_regex_cache(regex)) == NULL) {
return NULL;
}
-
- return php_pcre_replace_impl(pce, subject_str, subject, subject_len, replace_val,
+ pce->refcount++;
- result = php_pcre_replace_impl(pce, subject, subject_len, replace_val,
- is_callable_replace, result_len, limit, replace_count TSRMLS_CC);
++ result = php_pcre_replace_impl(pce, subject_str, subject, subject_len, replace_val,
+ is_callable_replace, limit, replace_count);
+ pce->refcount--;
+
+ return result;
}
/* }}} */
RETURN_FALSE;
}
- php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC);
+ pce->refcount++;
+ php_pcre_split_impl(pce, subject->val, (int)subject->len, return_value, (int)limit_val, flags);
+ pce->refcount--;
}
/* }}} */
RETURN_FALSE;
}
- php_pcre_grep_impl(pce, input, return_value, flags TSRMLS_CC);
+ pce->refcount++;
+ php_pcre_grep_impl(pce, input, return_value, flags);
+ pce->refcount--;
}
/* }}} */