#include "php.h"
#include "php_ini.h"
#include "php_globals.h"
#include "php_pcre.h"
#include "ext/standard/info.h"
#include "ext/standard/php_smart_str.h"
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
#include "ext/standard/php_string.h"
#define PREG_PATTERN_ORDER 1
#define PREG_SET_ORDER 2
#define PREG_OFFSET_CAPTURE (1<<8)
#define PREG_SPLIT_NO_EMPTY (1<<0)
#define PREG_SPLIT_DELIM_CAPTURE (1<<1)
#define PREG_SPLIT_OFFSET_CAPTURE (1<<2)
#define PREG_REPLACE_EVAL (1<<0)
#define PREG_GREP_INVERT (1<<0)
#define PCRE_CACHE_SIZE 4096
enum {
PHP_PCRE_NO_ERROR = 0,
PHP_PCRE_INTERNAL_ERROR,
PHP_PCRE_BACKTRACK_LIMIT_ERROR,
PHP_PCRE_RECURSION_LIMIT_ERROR,
PHP_PCRE_BAD_UTF8_ERROR
};
ZEND_DECLARE_MODULE_GLOBALS(pcre)
static void pcre_handle_exec_error(int pcre_code TSRMLS_DC)
{
int preg_code = 0;
switch (pcre_code) {
case PCRE_ERROR_MATCHLIMIT:
preg_code = PHP_PCRE_BACKTRACK_LIMIT_ERROR;
break;
case PCRE_ERROR_RECURSIONLIMIT:
preg_code = PHP_PCRE_RECURSION_LIMIT_ERROR;
break;
case PCRE_ERROR_BADUTF8:
preg_code = PHP_PCRE_BAD_UTF8_ERROR;
break;
default:
preg_code = PHP_PCRE_INTERNAL_ERROR;
break;
}
PCRE_G(error_code) = preg_code;
}
static void php_free_pcre_cache(void *data)
{
pcre_cache_entry *pce = (pcre_cache_entry *) data;
if (!pce) return;
pefree(pce->re, 1);
if (pce->extra) pefree(pce->extra, 1);
#if HAVE_SETLOCALE
if ((void*)pce->tables) pefree((void*)pce->tables, 1);
pefree(pce->locale, 1);
#endif
}
static PHP_GINIT_FUNCTION(pcre)
{
zend_hash_init(&pcre_globals->pcre_cache, 0, NULL, php_free_pcre_cache, 1);
pcre_globals->backtrack_limit = 0;
pcre_globals->recursion_limit = 0;
pcre_globals->error_code = PHP_PCRE_NO_ERROR;
}
static PHP_GSHUTDOWN_FUNCTION(pcre)
{
zend_hash_destroy(&pcre_globals->pcre_cache);
}
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("pcre.backtrack_limit", "100000", PHP_INI_ALL, OnUpdateLong, backtrack_limit, zend_pcre_globals, pcre_globals)
STD_PHP_INI_ENTRY("pcre.recursion_limit", "100000", PHP_INI_ALL, OnUpdateLong, recursion_limit, zend_pcre_globals, pcre_globals)
PHP_INI_END()
static PHP_MINFO_FUNCTION(pcre)
{
php_info_print_table_start();
php_info_print_table_row(2, "PCRE (Perl Compatible Regular Expressions) Support", "enabled" );
php_info_print_table_row(2, "PCRE Library Version", pcre_version() );
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
static PHP_MINIT_FUNCTION(pcre)
{
REGISTER_INI_ENTRIES();
REGISTER_LONG_CONSTANT("PREG_PATTERN_ORDER", PREG_PATTERN_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SET_ORDER", PREG_SET_ORDER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_OFFSET_CAPTURE", PREG_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_NO_EMPTY", PREG_SPLIT_NO_EMPTY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_DELIM_CAPTURE", PREG_SPLIT_DELIM_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_SPLIT_OFFSET_CAPTURE", PREG_SPLIT_OFFSET_CAPTURE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_GREP_INVERT", PREG_GREP_INVERT, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_NO_ERROR", PHP_PCRE_NO_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_INTERNAL_ERROR", PHP_PCRE_INTERNAL_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BACKTRACK_LIMIT_ERROR", PHP_PCRE_BACKTRACK_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_RECURSION_LIMIT_ERROR", PHP_PCRE_RECURSION_LIMIT_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PREG_BAD_UTF8_ERROR", PHP_PCRE_BAD_UTF8_ERROR, CONST_CS | CONST_PERSISTENT);
REGISTER_STRING_CONSTANT("PCRE_VERSION", (char *)pcre_version(), CONST_CS | CONST_PERSISTENT);
return SUCCESS;
}
static PHP_MSHUTDOWN_FUNCTION(pcre)
{
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
static int pcre_clean_cache(void *data, void *arg TSRMLS_DC)
{
int *num_clean = (int *)arg;
if (*num_clean > 0) {
(*num_clean)--;
return 1;
} else {
return 0;
}
}
static char **make_subpats_table(int num_subpats, pcre_cache_entry *pce TSRMLS_DC)
{
pcre_extra *extra = pce->extra;
int name_cnt = 0, name_size, ni = 0;
int rc;
char *name_table;
unsigned short name_idx;
char **subpat_names = (char **)ecalloc(num_subpats, sizeof(char *));
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMECOUNT, &name_cnt);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
if (name_cnt > 0) {
int rc1, rc2;
rc1 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMETABLE, &name_table);
rc2 = pcre_fullinfo(pce->re, extra, PCRE_INFO_NAMEENTRYSIZE, &name_size);
rc = rc2 ? rc2 : rc1;
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
efree(subpat_names);
return NULL;
}
while (ni++ < name_cnt) {
name_idx = 0xff * name_table[0] + name_table[1];
subpat_names[name_idx] = name_table + 2;
if (is_numeric_string(subpat_names[name_idx], strlen(subpat_names[name_idx]), NULL, NULL, 0) > 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Numeric named subpatterns are not allowed");
efree(subpat_names);
return NULL;
}
name_table += name_size;
}
}
return subpat_names;
}
PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_len TSRMLS_DC)
{
pcre *re = NULL;
pcre_extra *extra;
int coptions = 0;
int soptions = 0;
const char *error;
int erroffset;
char delimiter;
char start_delimiter;
char end_delimiter;
char *p, *pp;
char *pattern;
int do_study = 0;
int poptions = 0;
unsigned const char *tables = NULL;
#if HAVE_SETLOCALE
char *locale = setlocale(LC_CTYPE, NULL);
#endif
pcre_cache_entry *pce;
pcre_cache_entry new_entry;
regex_len = strlen(regex);
if (zend_hash_find(&PCRE_G(pcre_cache), regex, regex_len+1, (void **)&pce) == SUCCESS) {
if (pcre_info(pce->re, NULL, NULL) == PCRE_ERROR_BADMAGIC) {
zend_hash_clean(&PCRE_G(pcre_cache));
} else {
#if HAVE_SETLOCALE
if (!strcmp(pce->locale, locale)) {
#endif
return pce;
#if HAVE_SETLOCALE
}
#endif
}
}
p = regex;
while (isspace((int)*(unsigned char *)p)) p++;
if (*p == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty regular expression");
return NULL;
}
delimiter = *p++;
if (isalnum((int)*(unsigned char *)&delimiter) || delimiter == '\\') {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "Delimiter must not be alphanumeric or backslash");
return NULL;
}
start_delimiter = delimiter;
if ((pp = strchr("([{< )]}> )]}>", delimiter)))
delimiter = pp[5];
end_delimiter = delimiter;
if (start_delimiter == end_delimiter) {
pp = p;
while (*pp != 0) {
if (*pp == '\\' && pp[1] != 0) pp++;
else if (*pp == delimiter)
break;
pp++;
}
if (*pp == 0) {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending delimiter '%c' found", delimiter);
return NULL;
}
} else {
int brackets = 1;
pp = p;
while (*pp != 0) {
if (*pp == '\\' && pp[1] != 0) pp++;
else if (*pp == end_delimiter && --brackets <= 0)
break;
else if (*pp == start_delimiter)
brackets++;
pp++;
}
if (*pp == 0) {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "No ending matching delimiter '%c' found", end_delimiter);
return NULL;
}
}
pattern = estrndup(p, pp-p);
pp++;
while (*pp != 0) {
switch (*pp++) {
case 'i': coptions |= PCRE_CASELESS; break;
case 'm': coptions |= PCRE_MULTILINE; break;
case 's': coptions |= PCRE_DOTALL; break;
case 'x': coptions |= PCRE_EXTENDED; break;
case 'A': coptions |= PCRE_ANCHORED; break;
case 'D': coptions |= PCRE_DOLLAR_ENDONLY;break;
case 'S': do_study = 1; break;
case 'U': coptions |= PCRE_UNGREEDY; break;
case 'X': coptions |= PCRE_EXTRA; break;
case 'u': coptions |= PCRE_UTF8; break;
case 'e': poptions |= PREG_REPLACE_EVAL; break;
case ' ':
case '\n':
break;
default:
php_error_docref(NULL TSRMLS_CC,E_WARNING, "Unknown modifier '%c'", pp[-1]);
efree(pattern);
return NULL;
}
}
#if HAVE_SETLOCALE
if (strcmp(locale, "C"))
tables = pcre_maketables();
#endif
re = pcre_compile(pattern,
coptions,
&error,
&erroffset,
tables);
if (re == NULL) {
php_error_docref(NULL TSRMLS_CC,E_WARNING, "Compilation failed: %s at offset %d", error, erroffset);
efree(pattern);
if (tables) {
pefree((void*)tables, 1);
}
return NULL;
}
if (do_study) {
extra = pcre_study(re, soptions, &error);
if (extra) {
extra->flags |= PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
}
if (error != NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while studying pattern");
}
} else {
extra = NULL;
}
efree(pattern);
if (zend_hash_num_elements(&PCRE_G(pcre_cache)) == PCRE_CACHE_SIZE) {
int num_clean = PCRE_CACHE_SIZE / 8;
zend_hash_apply_with_argument(&PCRE_G(pcre_cache), pcre_clean_cache, &num_clean TSRMLS_CC);
}
new_entry.re = re;
new_entry.extra = extra;
new_entry.preg_options = poptions;
new_entry.compile_options = coptions;
#if HAVE_SETLOCALE
new_entry.locale = pestrdup(locale, 1);
new_entry.tables = tables;
#endif
zend_hash_update(&PCRE_G(pcre_cache), regex, regex_len+1, (void *)&new_entry,
sizeof(pcre_cache_entry), (void**)&pce);
return pce;
}
PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int *preg_options TSRMLS_DC)
{
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC);
if (extra) {
*extra = pce ? pce->extra : NULL;
}
if (preg_options) {
*preg_options = pce ? pce->preg_options : 0;
}
return pce ? pce->re : NULL;
}
PHPAPI pcre* pcre_get_compiled_regex_ex(char *regex, pcre_extra **extra, int *preg_options, int *compile_options TSRMLS_DC)
{
pcre_cache_entry * pce = pcre_get_compiled_regex_cache(regex, strlen(regex) TSRMLS_CC);
if (extra) {
*extra = pce ? pce->extra : NULL;
}
if (preg_options) {
*preg_options = pce ? pce->preg_options : 0;
}
if (compile_options) {
*compile_options = pce ? pce->compile_options : 0;
}
return pce ? pce->re : NULL;
}
static inline void add_offset_pair(zval *result, char *str, int len, int offset, char *name)
{
zval *match_pair;
ALLOC_ZVAL(match_pair);
array_init(match_pair);
INIT_PZVAL(match_pair);
add_next_index_stringl(match_pair, str, len, 1);
add_next_index_long(match_pair, offset);
if (name) {
zval_add_ref(&match_pair);
zend_hash_update(Z_ARRVAL_P(result), name, strlen(name)+1, &match_pair, sizeof(zval *), NULL);
}
zend_hash_next_index_insert(Z_ARRVAL_P(result), &match_pair, sizeof(zval *), NULL);
}
static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global)
{
char *regex;
char *subject;
int regex_len;
int subject_len;
pcre_cache_entry *pce;
zval *subpats = NULL;
long flags = 0;
long start_offset = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ((global) ? "ssz|ll" : "ss|zll"), ®ex, ®ex_len,
&subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) {
RETURN_FALSE;
}
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_match_impl(pce, subject, subject_len, return_value, subpats,
global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC);
}
PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC)
{
zval *result_set,
**match_sets = NULL;
pcre_extra *extra = pce->extra;
pcre_extra extra_data;
int exoptions = 0;
int count = 0;
int *offsets;
int num_subpats;
int size_offsets;
int matched;
int g_notempty = 0;
const char **stringlist;
char *match;
char **subpat_names;
int i, rc;
int subpats_order;
int offset_capture;
if (subpats != NULL) {
zval_dtor(subpats);
array_init(subpats);
}
subpats_order = global ? PREG_PATTERN_ORDER : 0;
if (use_flags) {
offset_capture = flags & PREG_OFFSET_CAPTURE;
if (flags & 0xff) {
subpats_order = flags & 0xff;
}
if ((global && (subpats_order < PREG_PATTERN_ORDER || subpats_order > PREG_SET_ORDER)) ||
(!global && subpats_order != 0)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid flags specified");
return;
}
} else {
offset_capture = 0;
}
if (start_offset < 0) {
start_offset = subject_len + start_offset;
if (start_offset < 0) {
start_offset = 0;
}
}
if (extra == NULL) {
extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
extra = &extra_data;
}
extra->match_limit = PCRE_G(backtrack_limit);
extra->match_limit_recursion = PCRE_G(recursion_limit);
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
RETURN_FALSE;
}
num_subpats++;
size_offsets = num_subpats * 3;
subpat_names = make_subpats_table(num_subpats, pce TSRMLS_CC);
if (!subpat_names) {
RETURN_FALSE;
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
if (global && subpats_order == PREG_PATTERN_ORDER) {
match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0);
for (i=0; i<num_subpats; i++) {
ALLOC_ZVAL(match_sets[i]);
array_init(match_sets[i]);
INIT_PZVAL(match_sets[i]);
}
}
match = NULL;
matched = 0;
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
do {
count = pcre_exec(pce->re, extra, subject, subject_len, start_offset,
exoptions|g_notempty, offsets, size_offsets);
if (count == 0) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Matched, but too many substrings");
count = size_offsets/3;
}
if (count > 0) {
matched++;
match = subject + offsets[0];
if (subpats != NULL) {
if (pcre_get_substring_list(subject, offsets, count, &stringlist) < 0) {
efree(subpat_names);
efree(offsets);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Get subpatterns list failed");
RETURN_FALSE;
}
if (global) {
if (subpats_order == PREG_PATTERN_ORDER) {
for (i = 0; i < count; i++) {
if (offset_capture) {
add_offset_pair(match_sets[i], (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], offsets[i<<1], NULL);
} else {
add_next_index_stringl(match_sets[i], (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], 1);
}
}
if (count < num_subpats) {
for (; i < num_subpats; i++) {
add_next_index_string(match_sets[i], "", 1);
}
}
} else {
ALLOC_ZVAL(result_set);
array_init(result_set);
INIT_PZVAL(result_set);
for (i = 0; i < count; i++) {
if (offset_capture) {
add_offset_pair(result_set, (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], offsets[i<<1], subpat_names[i]);
} else {
if (subpat_names[i]) {
add_assoc_stringl(result_set, subpat_names[i], (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], 1);
}
add_next_index_stringl(result_set, (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], 1);
}
}
zend_hash_next_index_insert(Z_ARRVAL_P(subpats), &result_set, sizeof(zval *), NULL);
}
} else {
for (i = 0; i < count; i++) {
if (offset_capture) {
add_offset_pair(subpats, (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1],
offsets[i<<1], subpat_names[i]);
} else {
if (subpat_names[i]) {
add_assoc_stringl(subpats, subpat_names[i], (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], 1);
}
add_next_index_stringl(subpats, (char *)stringlist[i],
offsets[(i<<1)+1] - offsets[i<<1], 1);
}
}
}
pcre_free((void *) stringlist);
}
} else if (count == PCRE_ERROR_NOMATCH) {
if (g_notempty != 0 && start_offset < subject_len) {
offsets[0] = start_offset;
offsets[1] = start_offset + 1;
} else
break;
} else {
pcre_handle_exec_error(count TSRMLS_CC);
break;
}
g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0;
start_offset = offsets[1];
} while (global);
if (global && subpats_order == PREG_PATTERN_ORDER) {
for (i = 0; i < num_subpats; i++) {
if (subpat_names[i]) {
zend_hash_update(Z_ARRVAL_P(subpats), subpat_names[i],
strlen(subpat_names[i])+1, &match_sets[i], sizeof(zval *), NULL);
ZVAL_ADDREF(match_sets[i]);
}
zend_hash_next_index_insert(Z_ARRVAL_P(subpats), &match_sets[i], sizeof(zval *), NULL);
}
efree(match_sets);
}
efree(offsets);
efree(subpat_names);
RETVAL_LONG(matched);
}
PHP_FUNCTION(preg_match)
{
php_do_pcre_match(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
PHP_FUNCTION(preg_match_all)
{
php_do_pcre_match(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
static int preg_get_backref(char **str, int *backref)
{
register char in_brace = 0;
register char *walk = *str;
if (walk[1] == 0)
return 0;
if (*walk == '$' && walk[1] == '{') {
in_brace = 1;
walk++;
}
walk++;
if (*walk >= '0' && *walk <= '9') {
*backref = *walk - '0';
walk++;
} else
return 0;
if (*walk && *walk >= '0' && *walk <= '9') {
*backref = *backref * 10 + *walk - '0';
walk++;
}
if (in_brace) {
if (*walk == 0 || *walk != '}')
return 0;
else
walk++;
}
*str = walk;
return 1;
}
static int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC)
{
zval *retval_ptr;
zval **args[1];
zval *subpats;
int result_len;
int i;
MAKE_STD_ZVAL(subpats);
array_init(subpats);
for (i = 0; i < count; i++) {
if (subpat_names[i]) {
add_assoc_stringl(subpats, subpat_names[i], &subject[offsets[i<<1]] , offsets[(i<<1)+1] - offsets[i<<1], 1);
}
add_next_index_stringl(subpats, &subject[offsets[i<<1]], offsets[(i<<1)+1] - offsets[i<<1], 1);
}
args[0] = &subpats;
if (call_user_function_ex(EG(function_table), NULL, function, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
convert_to_string_ex(&retval_ptr);
*result = estrndup(Z_STRVAL_P(retval_ptr), Z_STRLEN_P(retval_ptr));
result_len = Z_STRLEN_P(retval_ptr);
zval_ptr_dtor(&retval_ptr);
} else {
if (!EG(exception)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call custom replacement function");
}
result_len = offsets[1] - offsets[0];
*result = estrndup(&subject[offsets[0]], result_len);
}
zval_dtor(subpats);
FREE_ZVAL(subpats);
return result_len;
}
static int preg_do_eval(char *eval_str, int eval_str_len, char *subject,
int *offsets, int count, char **result TSRMLS_DC)
{
zval retval;
char *eval_str_end,
*match,
*esc_match,
*walk,
*segment,
walk_last;
int match_len;
int esc_match_len;
int result_len;
int backref;
char *compiled_string_description;
smart_str code = {0};
eval_str_end = eval_str + eval_str_len;
walk = segment = eval_str;
walk_last = 0;
while (walk < eval_str_end) {
if ('\\' == *walk || '$' == *walk) {
smart_str_appendl(&code, segment, walk - segment);
if (walk_last == '\\') {
code.c[code.len-1] = *walk++;
segment = walk;
walk_last = 0;
continue;
}
segment = walk;
if (preg_get_backref(&walk, &backref)) {
if (backref < count) {
match = subject + offsets[backref<<1];
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
if (match_len) {
esc_match = php_addslashes_ex(match, match_len, &esc_match_len, 0, 1 TSRMLS_CC);
} else {
esc_match = match;
esc_match_len = 0;
}
} else {
esc_match = "";
esc_match_len = 0;
match_len = 0;
}
smart_str_appendl(&code, esc_match, esc_match_len);
segment = walk;
if (esc_match_len)
efree(esc_match);
continue;
}
}
walk++;
walk_last = walk[-1];
}
smart_str_appendl(&code, segment, walk - segment);
smart_str_0(&code);
compiled_string_description = zend_make_compiled_string_description("regexp code" TSRMLS_CC);
if (zend_eval_string(code.c, &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
efree(compiled_string_description);
php_error_docref(NULL TSRMLS_CC,E_ERROR, "Failed evaluating code: %s%s", PHP_EOL, code.c);
}
efree(compiled_string_description);
convert_to_string(&retval);
*result = estrndup(Z_STRVAL(retval), Z_STRLEN(retval));
result_len = Z_STRLEN(retval);
zval_dtor(&retval);
smart_str_free(&code);
return result_len;
}
PHPAPI char *php_pcre_replace(char *regex, int regex_len,
char *subject, int subject_len,
zval *replace_val, int is_callable_replace,
int *result_len, int limit, int *replace_count TSRMLS_DC)
{
pcre_cache_entry *pce;
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
return NULL;
}
return php_pcre_replace_impl(pce, subject, subject_len, replace_val,
is_callable_replace, result_len, limit, replace_count TSRMLS_CC);
}
PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val,
int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC)
{
pcre_extra *extra = pce->extra;
pcre_extra extra_data;
int exoptions = 0;
int count = 0;
int *offsets;
char **subpat_names;
int num_subpats;
int size_offsets;
int new_len;
int alloc_len;
int eval_result_len=0;
int match_len;
int backref;
int eval;
int start_offset;
int g_notempty=0;
int replace_len=0;
char *result,
*replace=NULL,
*new_buf,
*walkbuf,
*walk,
*match,
*piece,
*replace_end=NULL,
*eval_result,
walk_last;
int rc;
if (extra == NULL) {
extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
extra = &extra_data;
}
extra->match_limit = PCRE_G(backtrack_limit);
extra->match_limit_recursion = PCRE_G(recursion_limit);
eval = pce->preg_options & PREG_REPLACE_EVAL;
if (is_callable_replace) {
if (eval) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Modifier /e cannot be used with replacement callback");
return NULL;
}
} else {
replace = Z_STRVAL_P(replace_val);
replace_len = Z_STRLEN_P(replace_val);
replace_end = replace + replace_len;
}
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
return NULL;
}
num_subpats++;
size_offsets = num_subpats * 3;
subpat_names = make_subpats_table(num_subpats, pce TSRMLS_CC);
if (!subpat_names) {
return NULL;
}
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
alloc_len = 2 * subject_len + 1;
result = safe_emalloc(alloc_len, sizeof(char), 0);
match = NULL;
*result_len = 0;
start_offset = 0;
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
while (1) {
count = pcre_exec(pce->re, extra, subject, subject_len, start_offset,
exoptions|g_notempty, offsets, size_offsets);
if (count == 0) {
php_error_docref(NULL TSRMLS_CC,E_NOTICE, "Matched, but too many substrings");
count = size_offsets/3;
}
piece = subject + start_offset;
if (count > 0 && (limit == -1 || limit > 0)) {
if (replace_count) {
++*replace_count;
}
match = subject + offsets[0];
new_len = *result_len + offsets[0] - start_offset;
if (eval) {
eval_result_len = preg_do_eval(replace, replace_len, subject,
offsets, count, &eval_result TSRMLS_CC);
new_len += eval_result_len;
} else if (is_callable_replace) {
eval_result_len = preg_do_repl_func(replace_val, subject, offsets, subpat_names, count, &eval_result TSRMLS_CC);
new_len += eval_result_len;
} else {
walk = replace;
walk_last = 0;
while (walk < replace_end) {
if ('\\' == *walk || '$' == *walk) {
if (walk_last == '\\') {
walk++;
walk_last = 0;
continue;
}
if (preg_get_backref(&walk, &backref)) {
if (backref < count)
new_len += offsets[(backref<<1)+1] - offsets[backref<<1];
continue;
}
}
new_len++;
walk++;
walk_last = walk[-1];
}
}
if (new_len + 1 > alloc_len) {
alloc_len = 1 + alloc_len + 2 * new_len;
new_buf = emalloc(alloc_len);
memcpy(new_buf, result, *result_len);
efree(result);
result = new_buf;
}
memcpy(&result[*result_len], piece, match-piece);
*result_len += match-piece;
walkbuf = result + *result_len;
if (eval || is_callable_replace) {
memcpy(walkbuf, eval_result, eval_result_len);
*result_len += eval_result_len;
STR_FREE(eval_result);
} else {
walk = replace;
walk_last = 0;
while (walk < replace_end) {
if ('\\' == *walk || '$' == *walk) {
if (walk_last == '\\') {
*(walkbuf-1) = *walk++;
walk_last = 0;
continue;
}
if (preg_get_backref(&walk, &backref)) {
if (backref < count) {
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
memcpy(walkbuf, subject + offsets[backref<<1], match_len);
walkbuf += match_len;
}
continue;
}
}
*walkbuf++ = *walk++;
walk_last = walk[-1];
}
*walkbuf = '\0';
*result_len += walkbuf - (result + *result_len);
}
if (limit != -1)
limit--;
} else if (count == PCRE_ERROR_NOMATCH || limit == 0) {
if (g_notempty != 0 && start_offset < subject_len) {
offsets[0] = start_offset;
offsets[1] = start_offset + 1;
memcpy(&result[*result_len], piece, 1);
(*result_len)++;
} else {
new_len = *result_len + subject_len - start_offset;
if (new_len + 1 > alloc_len) {
alloc_len = new_len + 1;
new_buf = safe_emalloc(alloc_len, sizeof(char), 0);
memcpy(new_buf, result, *result_len);
efree(result);
result = new_buf;
}
memcpy(&result[*result_len], piece, subject_len - start_offset);
*result_len += subject_len - start_offset;
result[*result_len] = '\0';
break;
}
} else {
pcre_handle_exec_error(count TSRMLS_CC);
efree(result);
result = NULL;
break;
}
g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0;
start_offset = offsets[1];
}
efree(offsets);
efree(subpat_names);
return result;
}
static char *php_replace_in_subject(zval *regex, zval *replace, zval **subject, int *result_len, int limit, zend_bool is_callable_replace, int *replace_count TSRMLS_DC)
{
zval **regex_entry,
**replace_entry = NULL,
*replace_value,
empty_replace;
char *subject_value,
*result;
int subject_len;
convert_to_string_ex(subject);
ZVAL_STRINGL(&empty_replace, "", 0, 0);
if (Z_TYPE_P(regex) == IS_ARRAY) {
subject_value = estrndup(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject));
subject_len = Z_STRLEN_PP(subject);
*result_len = subject_len;
zend_hash_internal_pointer_reset(Z_ARRVAL_P(regex));
replace_value = replace;
if (Z_TYPE_P(replace) == IS_ARRAY && !is_callable_replace)
zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
while (zend_hash_get_current_data(Z_ARRVAL_P(regex), (void **)®ex_entry) == SUCCESS) {
convert_to_string_ex(regex_entry);
if (Z_TYPE_P(replace) == IS_ARRAY && !is_callable_replace) {
if (zend_hash_get_current_data(Z_ARRVAL_P(replace), (void **)&replace_entry) == SUCCESS) {
if (!is_callable_replace) {
convert_to_string_ex(replace_entry);
}
replace_value = *replace_entry;
zend_hash_move_forward(Z_ARRVAL_P(replace));
} else {
replace_value = &empty_replace;
}
}
if ((result = php_pcre_replace(Z_STRVAL_PP(regex_entry),
Z_STRLEN_PP(regex_entry),
subject_value,
subject_len,
replace_value,
is_callable_replace,
result_len,
limit,
replace_count TSRMLS_CC)) != NULL) {
efree(subject_value);
subject_value = result;
subject_len = *result_len;
} else {
efree(subject_value);
return NULL;
}
zend_hash_move_forward(Z_ARRVAL_P(regex));
}
return subject_value;
} else {
result = php_pcre_replace(Z_STRVAL_P(regex),
Z_STRLEN_P(regex),
Z_STRVAL_PP(subject),
Z_STRLEN_PP(subject),
replace,
is_callable_replace,
result_len,
limit,
replace_count TSRMLS_CC);
return result;
}
}
static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_callable_replace)
{
zval **regex,
**replace,
**subject,
**limit,
**subject_entry,
**zcount;
char *result;
int result_len;
int limit_val = -1;
char *string_key;
ulong num_key;
char *callback_name;
int replace_count=0;
int *replace_count_ptr=NULL;
if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 5 ||
zend_get_parameters_ex(ZEND_NUM_ARGS(), ®ex, &replace, &subject, &limit, &zcount) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!is_callable_replace && Z_TYPE_PP(replace) == IS_ARRAY && Z_TYPE_PP(regex) != IS_ARRAY) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter mismatch, pattern is a string while replacement is an array");
RETURN_FALSE;
}
SEPARATE_ZVAL(replace);
if (Z_TYPE_PP(replace) != IS_ARRAY)
convert_to_string_ex(replace);
if (is_callable_replace) {
if (!zend_is_callable(*replace, 0, &callback_name)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Requires argument 2, '%s', to be a valid callback", callback_name);
efree(callback_name);
*return_value = **subject;
zval_copy_ctor(return_value);
INIT_PZVAL(return_value);
return;
}
efree(callback_name);
}
SEPARATE_ZVAL(regex);
SEPARATE_ZVAL(subject);
if (ZEND_NUM_ARGS() > 3) {
convert_to_long_ex(limit);
limit_val = Z_LVAL_PP(limit);
}
if (ZEND_NUM_ARGS() > 4) {
replace_count_ptr =& replace_count;
}
if (Z_TYPE_PP(regex) != IS_ARRAY)
convert_to_string_ex(regex);
if (Z_TYPE_PP(subject) == IS_ARRAY) {
array_init(return_value);
zend_hash_internal_pointer_reset(Z_ARRVAL_PP(subject));
while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)&subject_entry) == SUCCESS) {
SEPARATE_ZVAL(subject_entry);
if ((result = php_replace_in_subject(*regex, *replace, subject_entry, &result_len, limit_val, is_callable_replace, replace_count_ptr TSRMLS_CC)) != NULL) {
switch(zend_hash_get_current_key(Z_ARRVAL_PP(subject), &string_key, &num_key, 0))
{
case HASH_KEY_IS_STRING:
add_assoc_stringl(return_value, string_key, result, result_len, 0);
break;
case HASH_KEY_IS_LONG:
add_index_stringl(return_value, num_key, result, result_len, 0);
break;
}
}
zend_hash_move_forward(Z_ARRVAL_PP(subject));
}
} else {
if ((result = php_replace_in_subject(*regex, *replace, subject, &result_len, limit_val, is_callable_replace, replace_count_ptr TSRMLS_CC)) != NULL) {
RETVAL_STRINGL(result, result_len, 0);
}
}
if (replace_count_ptr) {
zval_dtor(*zcount);
ZVAL_LONG(*zcount, replace_count);
}
}
PHP_FUNCTION(preg_replace)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
PHP_FUNCTION(preg_replace_callback)
{
preg_replace_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
PHP_FUNCTION(preg_split)
{
char *regex;
char *subject;
int regex_len;
int subject_len;
long limit_val = -1;
long flags = 0;
pcre_cache_entry *pce;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", ®ex, ®ex_len,
&subject, &subject_len, &limit_val, &flags) == FAILURE) {
RETURN_FALSE;
}
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC);
}
PHPAPI void php_pcre_split_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
long limit_val, long flags TSRMLS_DC)
{
pcre_extra *extra = NULL;
pcre *re_bump = NULL;
pcre_extra *extra_bump = NULL;
pcre_extra extra_data;
int *offsets;
int size_offsets;
int exoptions = 0;
int count = 0;
int start_offset;
int next_offset;
int g_notempty = 0;
char *match,
*last_match;
int rc;
int no_empty;
int delim_capture;
int offset_capture;
no_empty = flags & PREG_SPLIT_NO_EMPTY;
delim_capture = flags & PREG_SPLIT_DELIM_CAPTURE;
offset_capture = flags & PREG_SPLIT_OFFSET_CAPTURE;
if (limit_val == 0) {
limit_val = -1;
}
if (extra == NULL) {
extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
extra = &extra_data;
}
extra->match_limit = PCRE_G(backtrack_limit);
extra->match_limit_recursion = PCRE_G(recursion_limit);
array_init(return_value);
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &size_offsets);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
RETURN_FALSE;
}
size_offsets = (size_offsets + 1) * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
start_offset = 0;
next_offset = 0;
last_match = subject;
match = NULL;
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
while ((limit_val == -1 || limit_val > 1)) {
count = pcre_exec(pce->re, extra, subject,
subject_len, start_offset,
exoptions|g_notempty, offsets, size_offsets);
if (count == 0) {
php_error_docref(NULL TSRMLS_CC,E_NOTICE, "Matched, but too many substrings");
count = size_offsets/3;
}
if (count > 0) {
match = subject + offsets[0];
if (!no_empty || &subject[offsets[0]] != last_match) {
if (offset_capture) {
add_offset_pair(return_value, last_match, &subject[offsets[0]]-last_match, next_offset, NULL);
} else {
add_next_index_stringl(return_value, last_match,
&subject[offsets[0]]-last_match, 1);
}
if (limit_val != -1)
limit_val--;
}
last_match = &subject[offsets[1]];
next_offset = offsets[1];
if (delim_capture) {
int i, match_len;
for (i = 1; i < count; i++) {
match_len = offsets[(i<<1)+1] - offsets[i<<1];
if (!no_empty || match_len > 0) {
if (offset_capture) {
add_offset_pair(return_value, &subject[offsets[i<<1]], match_len, offsets[i<<1], NULL);
} else {
add_next_index_stringl(return_value,
&subject[offsets[i<<1]],
match_len, 1);
}
}
}
}
} else if (count == PCRE_ERROR_NOMATCH) {
if (g_notempty != 0 && start_offset < subject_len) {
if (pce->compile_options & PCRE_UTF8) {
if (re_bump == NULL) {
int dummy;
if ((re_bump = pcre_get_compiled_regex("/./us", &extra_bump, &dummy TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
}
count = pcre_exec(re_bump, extra_bump, subject,
subject_len, start_offset,
exoptions, offsets, size_offsets);
if (count < 1) {
php_error_docref(NULL TSRMLS_CC,E_NOTICE, "Unknown error");
offsets[0] = start_offset;
offsets[1] = start_offset + 1;
}
} else {
offsets[0] = start_offset;
offsets[1] = start_offset + 1;
}
} else
break;
} else {
pcre_handle_exec_error(count TSRMLS_CC);
break;
}
g_notempty = (offsets[1] == offsets[0])? PCRE_NOTEMPTY | PCRE_ANCHORED : 0;
start_offset = offsets[1];
}
start_offset = last_match - subject;
if (!no_empty || start_offset < subject_len)
{
if (offset_capture) {
add_offset_pair(return_value, &subject[start_offset], subject_len - start_offset, start_offset, NULL);
} else {
add_next_index_stringl(return_value, last_match, subject + subject_len - last_match, 1);
}
}
efree(offsets);
}
PHP_FUNCTION(preg_quote)
{
int in_str_len;
char *in_str;
char *in_str_end;
int delim_len;
char *delim = NULL;
char *out_str,
*p,
*q,
delim_char=0,
c;
zend_bool quote_delim = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &in_str, &in_str_len,
&delim, &delim_len) == FAILURE) {
return;
}
in_str_end = in_str + in_str_len;
if (in_str == in_str_end) {
RETURN_EMPTY_STRING();
}
if (delim && *delim) {
delim_char = delim[0];
quote_delim = 1;
}
out_str = safe_emalloc(4, in_str_len, 1);
for(p = in_str, q = out_str; p != in_str_end; p++) {
c = *p;
switch(c) {
case '.':
case '\\':
case '+':
case '*':
case '?':
case '[':
case '^':
case ']':
case '$':
case '(':
case ')':
case '{':
case '}':
case '=':
case '!':
case '>':
case '<':
case '|':
case ':':
*q++ = '\\';
*q++ = c;
break;
case '\0':
*q++ = '\\';
*q++ = '0';
*q++ = '0';
*q++ = '0';
break;
default:
if (quote_delim && c == delim_char)
*q++ = '\\';
*q++ = c;
break;
}
}
*q = '\0';
RETVAL_STRINGL(erealloc(out_str, q - out_str + 1), q - out_str, 0);
}
PHP_FUNCTION(preg_grep)
{
char *regex;
int regex_len;
zval *input;
long flags = 0;
pcre_cache_entry *pce;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|l", ®ex, ®ex_len,
&input, &flags) == FAILURE) {
return;
}
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
php_pcre_grep_impl(pce, input, return_value, flags TSRMLS_CC);
}
PHPAPI void php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return_value, long flags TSRMLS_DC)
{
zval **entry;
pcre_extra *extra = pce->extra;
pcre_extra extra_data;
int *offsets;
int size_offsets;
int count = 0;
char *string_key;
ulong num_key;
zend_bool invert;
int rc;
invert = flags & PREG_GREP_INVERT ? 1 : 0;
if (extra == NULL) {
extra_data.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
extra = &extra_data;
}
extra->match_limit = PCRE_G(backtrack_limit);
extra->match_limit_recursion = PCRE_G(recursion_limit);
rc = pcre_fullinfo(pce->re, extra, PCRE_INFO_CAPTURECOUNT, &size_offsets);
if (rc < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal pcre_fullinfo() error %d", rc);
RETURN_FALSE;
}
size_offsets = (size_offsets + 1) * 3;
offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
array_init(return_value);
PCRE_G(error_code) = PHP_PCRE_NO_ERROR;
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
while (zend_hash_get_current_data(Z_ARRVAL_P(input), (void **)&entry) == SUCCESS) {
zval subject = **entry;
if (Z_TYPE_PP(entry) != IS_STRING) {
zval_copy_ctor(&subject);
convert_to_string(&subject);
}
count = pcre_exec(pce->re, extra, Z_STRVAL(subject),
Z_STRLEN(subject), 0,
0, offsets, size_offsets);
if (count == 0) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Matched, but too many substrings");
count = size_offsets/3;
} else if (count < 0 && count != PCRE_ERROR_NOMATCH) {
pcre_handle_exec_error(count TSRMLS_CC);
break;
}
if ((count > 0 && !invert) || (count == PCRE_ERROR_NOMATCH && invert)) {
ZVAL_ADDREF(*entry);
switch (zend_hash_get_current_key(Z_ARRVAL_P(input), &string_key, &num_key, 0))
{
case HASH_KEY_IS_STRING:
zend_hash_update(Z_ARRVAL_P(return_value), string_key,
strlen(string_key)+1, entry, sizeof(zval *), NULL);
break;
case HASH_KEY_IS_LONG:
zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry,
sizeof(zval *), NULL);
break;
}
}
if (Z_TYPE_PP(entry) != IS_STRING) {
zval_dtor(&subject);
}
zend_hash_move_forward(Z_ARRVAL_P(input));
}
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
efree(offsets);
}
PHP_FUNCTION(preg_last_error)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
return;
}
RETURN_LONG(PCRE_G(error_code));
}
zend_function_entry pcre_functions[] = {
PHP_FE(preg_match, third_arg_force_ref)
PHP_FE(preg_match_all, third_arg_force_ref)
PHP_FE(preg_replace, fifth_arg_force_ref)
PHP_FE(preg_replace_callback, fifth_arg_force_ref)
PHP_FE(preg_split, NULL)
PHP_FE(preg_quote, NULL)
PHP_FE(preg_grep, NULL)
PHP_FE(preg_last_error, NULL)
{NULL, NULL, NULL}
};
zend_module_entry pcre_module_entry = {
STANDARD_MODULE_HEADER,
"pcre",
pcre_functions,
PHP_MINIT(pcre),
PHP_MSHUTDOWN(pcre),
NULL,
NULL,
PHP_MINFO(pcre),
NO_VERSION_YET,
PHP_MODULE_GLOBALS(pcre),
PHP_GINIT(pcre),
PHP_GSHUTDOWN(pcre),
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
#ifdef COMPILE_DL_PCRE
ZEND_GET_MODULE(pcre)
# ifdef PHP_WIN32
# include "zend_arg_defs.c"
# endif
#endif
#endif