diff options
author | Nikita Popov <nikic@php.net> | 2014-08-25 21:21:16 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2014-08-25 21:52:18 +0200 |
commit | 6db293d5e043d35c281a6b11cb68460f5d7188a9 (patch) | |
tree | d1880c1810fe147de6ff7f8ff317b4ec300a518f /ext/standard | |
parent | 7813d85d3d5901b24f77b63538eb6754e161f471 (diff) | |
parent | 455741fce3c4f4392deb97775cba7a39f6490271 (diff) | |
download | php-git-6db293d5e043d35c281a6b11cb68460f5d7188a9.tar.gz |
Merge remote-tracking branch 'php-src/master' into ast
Conflicts:
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_globals.h
Zend/zend_language_parser.y
Zend/zend_language_scanner.c
Zend/zend_language_scanner.l
Zend/zend_types.h
Diffstat (limited to 'ext/standard')
72 files changed, 1354 insertions, 1320 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index a177ee7e0f..2663b404ac 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -141,7 +141,7 @@ PHP_MSHUTDOWN_FUNCTION(array) /* {{{ */ } /* }}} */ -static void php_set_compare_func(int sort_type TSRMLS_DC) /* {{{ */ +static void php_set_compare_func(zend_long sort_type TSRMLS_DC) /* {{{ */ { switch (sort_type & ~PHP_SORT_FLAG_CASE) { case PHP_SORT_NUMERIC: @@ -218,7 +218,7 @@ static int php_array_reverse_key_compare(const void *a, const void *b TSRMLS_DC) PHP_FUNCTION(krsort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -238,7 +238,7 @@ PHP_FUNCTION(krsort) PHP_FUNCTION(ksort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -253,9 +253,9 @@ PHP_FUNCTION(ksort) } /* }}} */ -PHPAPI int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ +PHPAPI zend_long php_count_recursive(zval *array, zend_long mode TSRMLS_DC) /* {{{ */ { - long cnt = 0; + zend_long cnt = 0; zval *element; if (Z_TYPE_P(array) == IS_ARRAY) { @@ -288,8 +288,8 @@ PHPAPI int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */ PHP_FUNCTION(count) { zval *array; - long mode = COUNT_NORMAL; - long cnt; + zend_long mode = COUNT_NORMAL; + zend_long cnt; zval *element; #ifndef FAST_ZPP @@ -403,8 +403,8 @@ static int php_array_natural_general_compare(const void *a, const void *b, int f int result = strnatcmp_ex(str1->val, str1->len, str2->val, str2->len, fold_case); - STR_RELEASE(str1); - STR_RELEASE(str2); + zend_string_release(str1); + zend_string_release(str2); return result; } /* }}} */ @@ -464,7 +464,7 @@ PHP_FUNCTION(natcasesort) PHP_FUNCTION(asort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -484,7 +484,7 @@ PHP_FUNCTION(asort) PHP_FUNCTION(arsort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -504,7 +504,7 @@ PHP_FUNCTION(arsort) PHP_FUNCTION(sort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -524,7 +524,7 @@ PHP_FUNCTION(sort) PHP_FUNCTION(rsort) { zval *array; - long sort_type = PHP_SORT_REGULAR; + zend_long sort_type = PHP_SORT_REGULAR; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/|l", &array, &sort_type) == FAILURE) { RETURN_FALSE; @@ -557,7 +557,7 @@ static int php_array_user_compare(const void *a, const void *b TSRMLS_DC) /* {{{ BG(user_compare_fci).retval = &retval; BG(user_compare_fci).no_separation = 0; if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { - long ret = zval_get_long(&retval); + zend_long ret = zval_get_long(&retval); zval_ptr_dtor(&retval); zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[0]); @@ -695,7 +695,7 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /* Bucket *s; zval args[2]; zval retval; - long result; + zend_long result; ZVAL_NULL(&args[0]); ZVAL_NULL(&args[1]); @@ -706,12 +706,12 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /* if (f->key == NULL) { ZVAL_LONG(&args[0], f->h); } else { - ZVAL_STR(&args[0], STR_COPY(f->key)); + ZVAL_STR(&args[0], zend_string_copy(f->key)); } if (s->key == NULL) { ZVAL_LONG(&args[1], s->h); } else { - ZVAL_STR(&args[1], STR_COPY(s->key)); + ZVAL_STR(&args[1], zend_string_copy(s->key)); } BG(user_compare_fci).param_count = 2; @@ -1230,7 +1230,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ *array, /* array to check in */ *entry, /* pointer to array entry */ res; /* comparison result */ - ulong num_idx; + zend_ulong num_idx; zend_string *str_idx; zend_bool strict = 0; /* strict comparison or not */ @@ -1256,7 +1256,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ RETURN_TRUE; } else { if (str_idx) { - RETVAL_STR(STR_COPY(str_idx)); + RETVAL_STR(zend_string_copy(str_idx)); } else { RETVAL_LONG(num_idx); } @@ -1271,7 +1271,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ RETURN_TRUE; } else { if (str_idx) { - RETVAL_STR(STR_COPY(str_idx)); + RETVAL_STR(zend_string_copy(str_idx)); } else { RETVAL_LONG(num_idx); } @@ -1339,7 +1339,7 @@ static int php_valid_var_name(char *var_name, int var_name_len) /* {{{ */ PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, int var_name_len, zend_bool add_underscore TSRMLS_DC) /* {{{ */ { - ZVAL_NEW_STR(result, STR_ALLOC(Z_STRLEN_P(prefix) + (add_underscore ? 1 : 0) + var_name_len, 0)); + ZVAL_NEW_STR(result, zend_string_alloc(Z_STRLEN_P(prefix) + (add_underscore ? 1 : 0) + var_name_len, 0)); memcpy(Z_STRVAL_P(result), Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)); if (add_underscore) { @@ -1357,10 +1357,10 @@ PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, int va PHP_FUNCTION(extract) { zval *var_array, *prefix = NULL; - long extract_type = EXTR_OVERWRITE; + zend_long extract_type = EXTR_OVERWRITE; zval *entry; zend_string *var_name; - ulong num_key; + zend_ulong num_key; int var_exists, count = 0; int extract_refs = 0; zend_array *symbol_table; @@ -1424,7 +1424,7 @@ PHP_FUNCTION(extract) if (var_exists && var_name->len == sizeof("this")-1 && !strcmp(var_name->val, "this") && EG(scope) && EG(scope)->name->len != 0) { break; } - ZVAL_STR(&final_name, STR_COPY(var_name)); + ZVAL_STR(&final_name, zend_string_copy(var_name)); break; case EXTR_PREFIX_IF_EXISTS: @@ -1435,7 +1435,7 @@ PHP_FUNCTION(extract) case EXTR_PREFIX_SAME: if (!var_exists && var_name->len != 0) { - ZVAL_STR(&final_name, STR_COPY(var_name)); + ZVAL_STR(&final_name, zend_string_copy(var_name)); } /* break omitted intentionally */ @@ -1450,14 +1450,14 @@ PHP_FUNCTION(extract) if (!php_valid_var_name(var_name->val, var_name->len)) { php_prefix_varname(&final_name, prefix, var_name->val, var_name->len, 1 TSRMLS_CC); } else { - ZVAL_STR(&final_name, STR_COPY(var_name)); + ZVAL_STR(&final_name, zend_string_copy(var_name)); } } break; default: if (!var_exists) { - ZVAL_STR(&final_name, STR_COPY(var_name)); + ZVAL_STR(&final_name, zend_string_copy(var_name)); } break; } @@ -1554,7 +1554,7 @@ PHP_FUNCTION(compact) PHP_FUNCTION(array_fill) { zval *val; - long start_key, num; + zend_long start_key, num; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz", &start_key, &num, &val) == FAILURE) { return; @@ -1612,7 +1612,7 @@ PHP_FUNCTION(array_fill_keys) zval_add_ref(val); zend_symtable_update(Z_ARRVAL_P(return_value), key, val); - STR_RELEASE(key); + zend_string_release(key); } } ZEND_HASH_FOREACH_END(); } @@ -1652,7 +1652,7 @@ PHP_FUNCTION(range) if (Z_TYPE_P(zlow) == IS_STRING && Z_TYPE_P(zhigh) == IS_STRING && Z_STRLEN_P(zlow) >= 1 && Z_STRLEN_P(zhigh) >= 1) { int type1, type2; unsigned char low, high; - long lstep = (long) step; + zend_long lstep = (zend_long) step; type1 = is_numeric_string(Z_STRVAL_P(zlow), Z_STRLEN_P(zlow), NULL, NULL, 0); type2 = is_numeric_string(Z_STRVAL_P(zhigh), Z_STRLEN_P(zhigh), NULL, NULL, 0); @@ -1673,7 +1673,7 @@ PHP_FUNCTION(range) } for (; low >= high; low -= (unsigned int)lstep) { if (CG(one_char_string)[low]) { - ZVAL_INT_STR(&tmp, CG(one_char_string)[low]); + ZVAL_INTERNED_STR(&tmp, CG(one_char_string)[low]); } else { ZVAL_STRINGL(&tmp, (char*)&low, 1); } @@ -1689,7 +1689,7 @@ PHP_FUNCTION(range) } for (; low <= high; low += (unsigned int)lstep) { if (CG(one_char_string)[low]) { - ZVAL_INT_STR(&tmp, CG(one_char_string)[low]); + ZVAL_INTERNED_STR(&tmp, CG(one_char_string)[low]); } else { ZVAL_STRINGL(&tmp, (char*)&low, 1); } @@ -1700,7 +1700,7 @@ PHP_FUNCTION(range) } } else { if (CG(one_char_string)[low]) { - ZVAL_INT_STR(&tmp, CG(one_char_string)[low]); + ZVAL_INTERNED_STR(&tmp, CG(one_char_string)[low]); } else { ZVAL_STRINGL(&tmp, (char*)&low, 1); } @@ -1709,7 +1709,7 @@ PHP_FUNCTION(range) } else if (Z_TYPE_P(zlow) == IS_DOUBLE || Z_TYPE_P(zhigh) == IS_DOUBLE || is_step_double) { double low, high, value; - long i; + zend_long i; double_str: low = zval_get_double(zlow); high = zval_get_double(zhigh); @@ -1742,11 +1742,11 @@ double_str: } } else { double low, high; - long lstep; + zend_long lstep; long_str: low = zval_get_double(zlow); high = zval_get_double(zhigh); - lstep = (long) step; + lstep = (zend_long) step; Z_TYPE_INFO(tmp) = IS_LONG; if (low > high) { /* Negative steps */ @@ -1755,7 +1755,7 @@ long_str: goto err; } for (; low >= high; low -= lstep) { - Z_LVAL(tmp) = (long)low; + Z_LVAL(tmp) = (zend_long)low; zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } } else if (high > low) { /* Positive steps */ @@ -1764,11 +1764,11 @@ long_str: goto err; } for (; low <= high; low += lstep) { - Z_LVAL(tmp) = (long)low; + Z_LVAL(tmp) = (zend_long)low; zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } } else { - Z_LVAL(tmp) = (long)low; + Z_LVAL(tmp) = (zend_long)low; zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp); } } @@ -1824,7 +1824,7 @@ static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */ for (j = 0; j < n_elems; j++) { p = hash->arData + j; if (p->key && !IS_INTERNED(p->key)) { - STR_RELEASE(p->key); + zend_string_release(p->key); } p->h = j; p->key = NULL; @@ -1995,7 +1995,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end) zval *stack, /* Input stack */ *val; /* Value to be popped */ zend_string *key = NULL; - ulong index; + zend_ulong index; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &stack) == FAILURE) { @@ -2145,7 +2145,7 @@ PHP_FUNCTION(array_splice) HashTable old_hash; uint idx; Bucket *p; /* Bucket used for traversing hash */ - long i, + zend_long i, offset, length = 0, repl_num = 0; /* Number of replacement elements */ @@ -2190,7 +2190,7 @@ PHP_FUNCTION(array_splice) /* ..and the length */ if (length < 0) { size = num_in - offset + length; - } else if (((unsigned long) offset + (unsigned long) length) > (unsigned) num_in) { + } else if (((zend_ulong) offset + (zend_ulong) length) > (unsigned) num_in) { size = num_in - offset; } @@ -2222,13 +2222,13 @@ PHP_FUNCTION(array_slice) zval *input, /* Input array */ *z_length = NULL, /* How many elements to get */ *entry; /* An array entry */ - long offset, /* Offset to get elements from */ + zend_long offset, /* Offset to get elements from */ length = 0; zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */ int num_in, /* Number of elements in the input array */ pos; /* Current position in the array */ zend_string *string_key; - ulong num_key; + zend_ulong num_key; #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) { @@ -2265,7 +2265,7 @@ PHP_FUNCTION(array_slice) /* ..and the length */ if (length < 0) { length = num_in - offset + length; - } else if (((unsigned long) offset + (unsigned long) length) > (unsigned) num_in) { + } else if (((zend_ulong) offset + (zend_ulong) length) > (unsigned) num_in) { length = num_in - offset; } @@ -2404,7 +2404,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC { zval *src_entry, *dest_entry, *src_zval, *dest_zval; zend_string *string_key; - ulong num_key; + zend_ulong num_key; int ret; ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) { @@ -2564,7 +2564,7 @@ PHP_FUNCTION(array_keys) new_val; /* New value */ int add_key; /* Flag to indicate whether a key should be added */ zend_bool strict = 0; /* do strict comparison */ - ulong num_idx; + zend_ulong num_idx; zend_string *str_idx; int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; @@ -2602,7 +2602,7 @@ PHP_FUNCTION(array_keys) if (add_key) { if (str_idx) { - ZVAL_STR(&new_val, STR_COPY(str_idx)); + ZVAL_STR(&new_val, zend_string_copy(str_idx)); } else { ZVAL_LONG(&new_val, num_idx); } @@ -2684,7 +2684,7 @@ zend_bool array_column_param_helper(zval *param, const char *name TSRMLS_DC) { switch (Z_TYPE_P(param)) { case IS_DOUBLE: - convert_to_long_ex(param); + convert_to_int_ex(param); /* fallthrough */ case IS_LONG: return 1; @@ -2775,7 +2775,7 @@ PHP_FUNCTION(array_reverse) zval *input, /* Input array */ *entry; /* An entry in the input array */ zend_string *string_key; - ulong num_key; + zend_ulong num_key; zend_bool preserve_keys = 0; /* whether to preserve keys */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &input, &preserve_keys) == FAILURE) { @@ -2810,10 +2810,10 @@ PHP_FUNCTION(array_pad) zval *pads; /* Array to pass to splice */ HashTable *new_hash;/* Return value from splice */ HashTable old_hash; - long pad_size; /* Size to pad to */ - long pad_size_abs; /* Absolute value of pad_size */ - int input_size; /* Size of the input array */ - int num_pads; /* How many pads do we need */ + zend_long pad_size; /* Size to pad to */ + zend_long pad_size_abs; /* Absolute value of pad_size */ + zend_long input_size; /* Size of the input array */ + zend_long num_pads; /* How many pads do we need */ int do_pad; /* Whether we should do padding at all */ int i; @@ -2823,7 +2823,7 @@ PHP_FUNCTION(array_pad) /* Do some initial calculations */ input_size = zend_hash_num_elements(Z_ARRVAL_P(input)); - pad_size_abs = abs(pad_size); + pad_size_abs = ZEND_ABS(pad_size); if (pad_size_abs < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time"); zval_dtor(return_value); @@ -2841,7 +2841,7 @@ PHP_FUNCTION(array_pad) /* Populate the pads array */ num_pads = pad_size_abs - input_size; - if (num_pads > 1048576) { + if (num_pads > Z_I(1048576)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time"); zval_dtor(return_value); RETURN_FALSE; @@ -2874,7 +2874,7 @@ PHP_FUNCTION(array_pad) PHP_FUNCTION(array_flip) { zval *array, *entry, data; - ulong num_idx; + zend_ulong num_idx; zend_string *str_idx; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) { @@ -2886,14 +2886,14 @@ PHP_FUNCTION(array_flip) ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) { if (Z_TYPE_P(entry) == IS_LONG) { if (str_idx) { - ZVAL_STR(&data, STR_COPY(str_idx)); + ZVAL_STR(&data, zend_string_copy(str_idx)); } else { ZVAL_LONG(&data, num_idx); } zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_P(entry), &data); } else if (Z_TYPE_P(entry) == IS_STRING) { if (str_idx) { - ZVAL_STR(&data, STR_COPY(str_idx)); + ZVAL_STR(&data, zend_string_copy(str_idx)); } else { ZVAL_LONG(&data, num_idx); } @@ -2912,8 +2912,8 @@ PHP_FUNCTION(array_change_key_case) zval *array, *entry; zend_string *string_key; zend_string *new_key; - ulong num_key; - long change_to_upper=0; + zend_ulong num_key; + zend_long change_to_upper=0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &change_to_upper) == FAILURE) { return; @@ -2927,14 +2927,14 @@ PHP_FUNCTION(array_change_key_case) if (!string_key) { zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry); } else { - new_key = STR_INIT(string_key->val, string_key->len, 0); + new_key = zend_string_init(string_key->val, string_key->len, 0); if (change_to_upper) { php_strtoupper(new_key->val, new_key->len); } else { php_strtolower(new_key->val, new_key->len); } zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry); - STR_RELEASE(new_key); + zend_string_release(new_key); } } ZEND_HASH_FOREACH_END(); } @@ -2953,7 +2953,7 @@ PHP_FUNCTION(array_unique) }; struct bucketindex *arTmp, *cmpdata, *lastkept; unsigned int i; - long sort_type = PHP_SORT_STRING; + zend_long sort_type = PHP_SORT_STRING; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { return; @@ -3035,7 +3035,7 @@ static int zval_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */ return ZEND_NORMALIZE_BOOL(Z_DVAL(result)); } - convert_to_long(&result); + convert_to_int(&result); return ZEND_NORMALIZE_BOOL(Z_LVAL(result)); } /* }}} */ @@ -3061,7 +3061,7 @@ static int zval_user_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */ BG(user_compare_fci).no_separation = 0; if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { - long ret = zval_get_long(&retval); + zend_long ret = zval_get_long(&retval); zval_ptr_dtor(&retval); return ret < 0 ? -1 : ret > 0 ? 1 : 0;; } else { @@ -4141,10 +4141,10 @@ PHP_FUNCTION(array_multisort) PHP_FUNCTION(array_rand) { zval *input; - long randval, num_req = 1; + zend_long randval, num_req = 1; int num_avail; zend_string *string_key; - ulong num_key; + zend_ulong num_key; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &input, &num_req) == FAILURE) { return; @@ -4176,14 +4176,14 @@ PHP_FUNCTION(array_rand) /* If we are returning a single result, just do it. */ if (Z_TYPE_P(return_value) != IS_ARRAY) { if (string_key) { - RETURN_STR(STR_COPY(string_key)); + RETURN_STR(zend_string_copy(string_key)); } else { RETURN_LONG(num_key); } } else { /* Append the result to the return value. */ if (string_key) { - add_next_index_str(return_value, STR_COPY(string_key)); + add_next_index_str(return_value, zend_string_copy(string_key)); } else { add_next_index_long(return_value, num_key); } @@ -4247,7 +4247,7 @@ PHP_FUNCTION(array_product) if (Z_TYPE(entry_n) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) { dval = (double)Z_LVAL_P(return_value) * (double)Z_LVAL(entry_n); - if ( (double)LONG_MIN <= dval && dval <= (double)LONG_MAX ) { + if ( (double)ZEND_LONG_MIN <= dval && dval <= (double)ZEND_LONG_MAX ) { Z_LVAL_P(return_value) *= Z_LVAL(entry_n); continue; } @@ -4298,14 +4298,18 @@ PHP_FUNCTION(array_reduce) fci.no_separation = 0; ZEND_HASH_FOREACH_VAL(htbl, operand) { - ZVAL_COPY_VALUE(&args[0], &result); - ZVAL_COPY_VALUE(&args[1], operand); + ZVAL_COPY(&args[0], &result); + ZVAL_COPY(&args[1], operand); fci.params = args; if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); zval_ptr_dtor(&result); ZVAL_COPY_VALUE(&result, &retval); } else { + zval_ptr_dtor(&args[1]); + zval_ptr_dtor(&args[0]); php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback"); return; } @@ -4324,11 +4328,11 @@ PHP_FUNCTION(array_filter) zval args[2]; zval retval; zend_bool have_callback = 0; - long use_type = 0; + zend_long use_type = 0; zend_string *string_key; zend_fcall_info fci = empty_fcall_info; zend_fcall_info_cache fci_cache = empty_fcall_info_cache; - ulong num_key; + zend_ulong num_key; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) { return; @@ -4359,9 +4363,9 @@ PHP_FUNCTION(array_filter) } } else { if (use_type == ARRAY_FILTER_USE_BOTH) { - ZVAL_STR(&args[1], STR_COPY(string_key)); + ZVAL_STR(&args[1], zend_string_copy(string_key)); } else if (use_type == ARRAY_FILTER_USE_KEY) { - ZVAL_STR(&args[0], STR_COPY(string_key)); + ZVAL_STR(&args[0], zend_string_copy(string_key)); } } } @@ -4432,9 +4436,9 @@ PHP_FUNCTION(array_map) RETVAL_NULL(); if (n_arrays == 1) { - ulong num_key; + zend_ulong num_key; zend_string *str_key; - zval *zv; + zval *zv, arg; if (Z_TYPE(arrays[0]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", 2); @@ -4453,20 +4457,18 @@ PHP_FUNCTION(array_map) ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL(arrays[0]), num_key, str_key, zv) { fci.retval = &result; fci.param_count = 1; - fci.params = zv; + fci.params = &arg; fci.no_separation = 0; - if (Z_REFCOUNTED_P(zv)) { - Z_ADDREF_P(zv); - } + ZVAL_COPY(&arg, zv); if (zend_call_function(&fci, &fci_cache TSRMLS_CC) != SUCCESS || Z_TYPE(result) == IS_UNDEF) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the map callback"); zval_dtor(return_value); - zval_ptr_dtor(zv); + zval_ptr_dtor(&arg); RETURN_NULL(); } else { - zval_ptr_dtor(zv); + zval_ptr_dtor(&arg); } if (str_key) { zend_hash_add_new(Z_ARRVAL_P(return_value), str_key, &result); @@ -4475,7 +4477,7 @@ PHP_FUNCTION(array_map) } } ZEND_HASH_FOREACH_END(); } else { - zend_uint *array_pos = (HashPosition *)ecalloc(n_arrays, sizeof(HashPosition)); + uint32_t *array_pos = (HashPosition *)ecalloc(n_arrays, sizeof(HashPosition)); for (i = 0; i < n_arrays; i++) { if (Z_TYPE(arrays[i]) != IS_ARRAY) { @@ -4503,7 +4505,7 @@ PHP_FUNCTION(array_map) for (i = 0; i < n_arrays; i++) { /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ - zend_uint pos = array_pos[i]; + uint32_t pos = array_pos[i]; while (1) { if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { ZVAL_NULL(&zv); @@ -4529,7 +4531,7 @@ PHP_FUNCTION(array_map) for (i = 0; i < n_arrays; i++) { /* If this array still has elements, add the current one to the * parameter list, otherwise use null value. */ - zend_uint pos = array_pos[i]; + uint32_t pos = array_pos[i]; while (1) { if (pos >= Z_ARRVAL(arrays[i])->nNumUsed) { ZVAL_NULL(¶ms[i]); @@ -4620,9 +4622,9 @@ PHP_FUNCTION(array_key_exists) PHP_FUNCTION(array_chunk) { int argc = ZEND_NUM_ARGS(), num_in; - long size, current = 0; + zend_long size, current = 0; zend_string *str_key; - ulong num_key; + zend_ulong num_key; zend_bool preserve_keys = 0; zval *input = NULL; zval chunk; @@ -4686,7 +4688,7 @@ PHP_FUNCTION(array_chunk) PHP_FUNCTION(array_combine) { zval *values, *keys; - zend_uint pos_values = 0; + uint32_t pos_values = 0; zval *entry_keys, *entry_values; int num_keys, num_values; @@ -4722,7 +4724,7 @@ PHP_FUNCTION(array_combine) zval_add_ref(entry_values); zend_symtable_update(Z_ARRVAL_P(return_value), key, entry_values); - STR_RELEASE(key); + zend_string_release(key); } pos_values++; break; diff --git a/ext/standard/assert.c b/ext/standard/assert.c index e64e2e1ecb..abd7c4079e 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -25,10 +25,10 @@ /* }}} */ ZEND_BEGIN_MODULE_GLOBALS(assert) - long active; - long bail; - long warning; - long quiet_eval; + zend_long active; + zend_long bail; + zend_long warning; + zend_long quiet_eval; zval callback; char *cb; ZEND_END_MODULE_GLOBALS(assert) @@ -256,7 +256,7 @@ PHP_FUNCTION(assert) PHP_FUNCTION(assert_options) { zval *value = NULL; - long what; + zend_long what; int oldint; int ac = ZEND_NUM_ARGS(); zend_string *key; @@ -270,10 +270,10 @@ PHP_FUNCTION(assert_options) oldint = ASSERTG(active); if (ac == 2) { zend_string *value_str = zval_get_string(value); - key = STR_INIT("assert.active", sizeof("assert.active")-1, 0); + key = zend_string_init("assert.active", sizeof("assert.active")-1, 0); zend_alter_ini_entry_ex(key, value_str->val, value_str->len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); - STR_RELEASE(key); - STR_RELEASE(value_str); + zend_string_release(key); + zend_string_release(value_str); } RETURN_LONG(oldint); break; @@ -282,10 +282,10 @@ PHP_FUNCTION(assert_options) oldint = ASSERTG(bail); if (ac == 2) { zend_string *value_str = zval_get_string(value); - key = STR_INIT("assert.bail", sizeof("assert.bail")-1, 0); + key = zend_string_init("assert.bail", sizeof("assert.bail")-1, 0); zend_alter_ini_entry_ex(key, value_str->val, value_str->len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); - STR_RELEASE(key); - STR_RELEASE(value_str); + zend_string_release(key); + zend_string_release(value_str); } RETURN_LONG(oldint); break; @@ -294,10 +294,10 @@ PHP_FUNCTION(assert_options) oldint = ASSERTG(quiet_eval); if (ac == 2) { zend_string *value_str = zval_get_string(value); - key = STR_INIT("assert.quiet_eval", sizeof("assert.quiet_eval")-1, 0); + key = zend_string_init("assert.quiet_eval", sizeof("assert.quiet_eval")-1, 0); zend_alter_ini_entry_ex(key, value_str->val, value_str->len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); - STR_RELEASE(key); - STR_RELEASE(value_str); + zend_string_release(key); + zend_string_release(value_str); } RETURN_LONG(oldint); break; @@ -306,10 +306,10 @@ PHP_FUNCTION(assert_options) oldint = ASSERTG(warning); if (ac == 2) { zend_string *value_str = zval_get_string(value); - key = STR_INIT("assert.warning", sizeof("assert.warning")-1, 0); + key = zend_string_init("assert.warning", sizeof("assert.warning")-1, 0); zend_alter_ini_entry_ex(key, value_str->val, value_str->len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); - STR_RELEASE(key); - STR_RELEASE(value_str); + zend_string_release(key); + zend_string_release(value_str); } RETURN_LONG(oldint); break; @@ -331,7 +331,7 @@ PHP_FUNCTION(assert_options) break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %ld", what); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %pd", what); break; } diff --git a/ext/standard/base64.c b/ext/standard/base64.c index 3bc96267b2..544514161b 100644 --- a/ext/standard/base64.c +++ b/ext/standard/base64.c @@ -53,7 +53,7 @@ static const short base64_reverse_table[256] = { }; /* }}} */ -PHPAPI zend_string *php_base64_encode(const unsigned char *str, int length) /* {{{ */ +PHPAPI zend_string *php_base64_encode(const unsigned char *str, size_t length) /* {{{ */ { const unsigned char *current = str; unsigned char *p; @@ -63,7 +63,7 @@ PHPAPI zend_string *php_base64_encode(const unsigned char *str, int length) /* { return NULL; } - result = STR_ALLOC(((length + 2) / 3) * 4 * sizeof(char), 0); + result = zend_string_alloc(((length + 2) / 3) * 4 * sizeof(char), 0); p = (unsigned char *)result->val; while (length > 2) { /* keep going until we have less than 24 bits */ @@ -131,20 +131,20 @@ void php_base64_init(void) */ /* }}} */ -PHPAPI zend_string *php_base64_decode(const unsigned char *str, int length) /* {{{ */ +PHPAPI zend_string *php_base64_decode(const unsigned char *str, size_t length) /* {{{ */ { return php_base64_decode_ex(str, length, 0); } /* }}} */ -PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, int length, zend_bool strict) /* {{{ */ +PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t length, zend_bool strict) /* {{{ */ { const unsigned char *current = str; int ch, i = 0, j = 0, k; /* this sucks for threaded environments */ zend_string *result; - result = STR_ALLOC(length, 0); + result = zend_string_alloc(length, 0); /* run through the whole string, converting as we go */ while ((ch = *current++) != '\0' && length-- > 0) { @@ -158,7 +158,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, int length, z continue; } } - STR_FREE(result); + zend_string_free(result); return NULL; } continue; @@ -168,7 +168,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, int length, z if ((!strict && ch < 0) || ch == -1) { /* a space or some other separator character, we simply skip over */ continue; } else if (ch == -2) { - STR_FREE(result); + zend_string_free(result); return NULL; } @@ -196,7 +196,7 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, int length, z if (ch == base64_pad) { switch(i % 4) { case 1: - STR_FREE(result); + zend_string_free(result); return NULL; case 2: k++; diff --git a/ext/standard/base64.h b/ext/standard/base64.h index e58565702a..43324e4911 100644 --- a/ext/standard/base64.h +++ b/ext/standard/base64.h @@ -24,9 +24,9 @@ PHP_FUNCTION(base64_decode); PHP_FUNCTION(base64_encode); -PHPAPI extern zend_string *php_base64_encode(const unsigned char *, int); -PHPAPI extern zend_string *php_base64_decode_ex(const unsigned char *, int, zend_bool); -PHPAPI extern zend_string *php_base64_decode(const unsigned char *, int); +PHPAPI extern zend_string *php_base64_encode(const unsigned char *, size_t); +PHPAPI extern zend_string *php_base64_decode_ex(const unsigned char *, size_t, zend_bool); +PHPAPI extern zend_string *php_base64_decode(const unsigned char *, size_t); #endif /* BASE64_H */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 17bdae5719..dbccaae265 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -99,7 +99,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif #ifndef INADDR_NONE -#define INADDR_NONE ((unsigned long int) -1) +#define INADDR_NONE ((zend_ulong) -1) #endif #include "zend_globals.h" @@ -395,7 +395,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge, 0, 0, 2) ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */ ZEND_ARG_VARIADIC_INFO(0, arrays) ZEND_END_ARG_INFO() - + ZEND_BEGIN_ARG_INFO_EX(arginfo_array_merge_recursive, 0, 0, 2) ZEND_ARG_INFO(0, arr1) /* ARRAY_INFO(0, arg, 0) */ ZEND_ARG_VARIADIC_INFO(0, arrays) @@ -3914,7 +3914,7 @@ PHP_FUNCTION(ip2long) #ifdef HAVE_INET_PTON struct in_addr ip; #else - unsigned long int ip; + zend_ulong ip; #endif if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) == FAILURE) { @@ -3950,7 +3950,7 @@ PHP_FUNCTION(long2ip) /* "It's a long but it's not, PHP ints are signed */ char *ip; int ip_len; - unsigned long n; + zend_ulong n; struct in_addr myaddr; #ifdef HAVE_INET_PTON char str[40]; @@ -4252,7 +4252,7 @@ PHP_FUNCTION(getopt) argv[pos++] = estrdup(arg_str->val); - STR_RELEASE(arg_str); + zend_string_release(arg_str); } ZEND_HASH_FOREACH_END(); /* The C Standard requires argv[argc] to be NULL - this might @@ -4297,7 +4297,7 @@ PHP_FUNCTION(getopt) opts->opt_char = 0; opts++; - STR_RELEASE(arg_str); + zend_string_release(arg_str); } ZEND_HASH_FOREACH_END(); } else { opts = (opt_struct*) erealloc(opts, sizeof(opt_struct) * (len + 1)); @@ -4386,7 +4386,7 @@ PHP_FUNCTION(flush) Delay for a given number of seconds */ PHP_FUNCTION(sleep) { - long num; + zend_long num; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) { RETURN_FALSE; @@ -4409,7 +4409,7 @@ PHP_FUNCTION(sleep) PHP_FUNCTION(usleep) { #if HAVE_USLEEP - long num; + zend_long num; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) { return; @@ -4428,7 +4428,7 @@ PHP_FUNCTION(usleep) Delay for a number of seconds and nano seconds */ PHP_FUNCTION(time_nanosleep) { - long tv_sec, tv_nsec; + zend_long tv_sec, tv_nsec; struct timespec php_req, php_rem; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &tv_sec, &tv_nsec) == FAILURE) { @@ -4525,9 +4525,9 @@ static int add_config_entry_cb(zval *entry TSRMLS_DC, int num_args, va_list args if (Z_TYPE_P(entry) == IS_STRING) { if (hash_key->key) { - add_assoc_str_ex(retval, hash_key->key->val, hash_key->key->len, STR_COPY(Z_STR_P(entry))); + add_assoc_str_ex(retval, hash_key->key->val, hash_key->key->len, zend_string_copy(Z_STR_P(entry))); } else { - add_index_str(retval, hash_key->h, STR_COPY(Z_STR_P(entry))); + add_index_str(retval, hash_key->h, zend_string_copy(Z_STR_P(entry))); } } else if (Z_TYPE_P(entry) == IS_ARRAY) { array_init(&tmp); @@ -4626,7 +4626,7 @@ PHP_FUNCTION(error_log) char *message, *opt = NULL, *headers = NULL; int message_len, opt_len = 0, headers_len = 0; int opt_err = 0, argc = ZEND_NUM_ARGS(); - long erropt = 0; + zend_long erropt = 0; if (zend_parse_parameters(argc TSRMLS_CC, "s|lps", &message, &message_len, &erropt, &opt, &opt_len, &headers, &headers_len) == FAILURE) { return; @@ -4858,12 +4858,12 @@ static int user_shutdown_function_call(zval *zv TSRMLS_DC) /* {{{ */ if (!zend_is_callable(&shutdown_function_entry->arguments[0], 0, &function_name TSRMLS_CC)) { php_error(E_WARNING, "(Registered shutdown functions) Unable to call %s() - function does not exist", function_name->val); if (function_name) { - STR_RELEASE(function_name); + zend_string_release(function_name); } return 0; } if (function_name) { - STR_RELEASE(function_name); + zend_string_release(function_name); } if (call_user_function(EG(function_table), NULL, @@ -5019,7 +5019,7 @@ PHP_FUNCTION(register_shutdown_function) zend_hash_next_index_insert_mem(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry)); } if (callback_name) { - STR_RELEASE(callback_name); + zend_string_release(callback_name); } } /* }}} */ @@ -5375,13 +5375,13 @@ PHP_FUNCTION(set_include_path) RETVAL_FALSE; } - key = STR_INIT("include_path", sizeof("include_path") - 1, 0); + key = zend_string_init("include_path", sizeof("include_path") - 1, 0); if (zend_alter_ini_entry_ex(key, new_value, new_value_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == FAILURE) { - STR_RELEASE(key); + zend_string_release(key); zval_dtor(return_value); RETURN_FALSE; } - STR_RELEASE(key); + zend_string_release(key); } /* }}} */ @@ -5414,9 +5414,9 @@ PHP_FUNCTION(restore_include_path) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } - key = STR_INIT("include_path", sizeof("include_path")-1, 0); + key = zend_string_init("include_path", sizeof("include_path")-1, 0); zend_restore_ini_entry(key, PHP_INI_STAGE_RUNTIME); - STR_FREE(key); + zend_string_free(key); } /* }}} */ @@ -5477,9 +5477,9 @@ PHP_FUNCTION(ignore_user_abort) old_setting = PG(ignore_user_abort); if (arg) { - zend_string *key = STR_INIT("ignore_user_abort", sizeof("ignore_user_abort"), 0); + zend_string *key = zend_string_init("ignore_user_abort", sizeof("ignore_user_abort"), 0); zend_alter_ini_entry_ex(key, arg, arg_len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC); - STR_RELEASE(key); + zend_string_release(key); } RETURN_LONG(old_setting); @@ -5526,7 +5526,7 @@ PHP_FUNCTION(getservbyport) { char *proto; int proto_len; - long port; + zend_long port; struct servent *serv; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &port, &proto, &proto_len) == FAILURE) { @@ -5573,7 +5573,7 @@ PHP_FUNCTION(getprotobyname) Returns protocol name associated with protocol number proto */ PHP_FUNCTION(getprotobynumber) { - long proto; + zend_long proto; struct protoent *ent; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &proto) == FAILURE) { @@ -5616,10 +5616,10 @@ PHP_FUNCTION(register_tick_function) if (!zend_is_callable(&tick_fe.arguments[0], 0, &function_name TSRMLS_CC)) { efree(tick_fe.arguments); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid tick callback '%s' passed", function_name->val); - STR_RELEASE(function_name); + zend_string_release(function_name); RETURN_FALSE; } else if (function_name) { - STR_RELEASE(function_name); + zend_string_release(function_name); } if (Z_TYPE(tick_fe.arguments[0]) != IS_ARRAY && Z_TYPE(tick_fe.arguments[0]) != IS_OBJECT) { @@ -5778,7 +5778,7 @@ static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int cal } if (!(Z_STRLEN_P(arg1) > 1 && Z_STRVAL_P(arg1)[0] == '0') && is_numeric_string(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1), NULL, NULL, 0) == IS_LONG) { - ulong key = (ulong) zend_atol(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); + zend_ulong key = (zend_ulong) zend_atol(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); if ((find_hash = zend_hash_index_find(Z_ARRVAL_P(arr), key)) == NULL) { array_init(&hash); find_hash = zend_hash_index_update(Z_ARRVAL_P(arr), key, &hash); @@ -5839,7 +5839,7 @@ PHP_FUNCTION(parse_ini_file) char *filename = NULL; int filename_len = 0; zend_bool process_sections = 0; - long scanner_mode = ZEND_INI_SCANNER_NORMAL; + zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_file_handle fh; zend_ini_parser_cb_t ini_parser_cb; @@ -5880,7 +5880,7 @@ PHP_FUNCTION(parse_ini_string) char *string = NULL, *str = NULL; int str_len = 0; zend_bool process_sections = 0; - long scanner_mode = ZEND_INI_SCANNER_NORMAL; + zend_long scanner_mode = ZEND_INI_SCANNER_NORMAL; zend_ini_parser_cb_t ini_parser_cb; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", &str, &str_len, &process_sections, &scanner_mode) == FAILURE) { diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 3cabf87d1a..64a6c5363c 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -167,7 +167,7 @@ typedef struct _php_basic_globals { char *locale_string; char *strtok_last; char strtok_table[256]; - ulong strtok_len; + zend_ulong strtok_len; char str_ebuf[40]; zend_fcall_info array_walk_fci; zend_fcall_info_cache array_walk_fci_cache; @@ -178,9 +178,9 @@ typedef struct _php_basic_globals { zval active_ini_file_section; /* pageinfo.c */ - long page_uid; - long page_gid; - long page_inode; + zend_long page_uid; + zend_long page_gid; + zend_long page_inode; time_t page_mtime; /* filestat.c && main/streams/streams.c */ diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index f494cc86b1..320d1f90a7 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -61,7 +61,7 @@ static void browscap_entry_dtor_request(zval *zvalue) /* {{{ */ zend_hash_destroy(Z_ARRVAL_P(zvalue)); efree(Z_ARR_P(zvalue)); } else if (Z_TYPE_P(zvalue) == IS_STRING) { - STR_RELEASE(Z_STR_P(zvalue)); + zend_string_release(Z_STR_P(zvalue)); } } /* }}} */ @@ -71,7 +71,7 @@ static void browscap_entry_dtor_persistent(zval *zvalue) /* {{{ */ { zend_hash_destroy(Z_ARRVAL_P(zvalue)); free(Z_ARR_P(zvalue)); } else if (Z_TYPE_P(zvalue) == IS_STRING) { - STR_RELEASE(Z_STR_P(zvalue)); + zend_string_release(Z_STR_P(zvalue)); } } /* }}} */ @@ -83,7 +83,7 @@ static void convert_browscap_pattern(zval *pattern, int persistent) /* {{{ */ zend_string *res; char *lc_pattern; - res = STR_SAFE_ALLOC(Z_STRLEN_P(pattern), 2, 4, persistent); + res = zend_string_safe_alloc(Z_STRLEN_P(pattern), 2, 4, persistent); t = res->val; lc_pattern = zend_str_tolower_dup(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern)); @@ -167,7 +167,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callb (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "yes", sizeof("yes") - 1)) || (Z_STRLEN_P(arg2) == 4 && !strncasecmp(Z_STRVAL_P(arg2), "true", sizeof("true") - 1)) ) { - ZVAL_NEW_STR(&new_property, STR_INIT("1", sizeof("1")-1, persistent)); + ZVAL_NEW_STR(&new_property, zend_string_init("1", sizeof("1")-1, persistent)); } else if ( (Z_STRLEN_P(arg2) == 2 && !strncasecmp(Z_STRVAL_P(arg2), "no", sizeof("no") - 1)) || (Z_STRLEN_P(arg2) == 3 && !strncasecmp(Z_STRVAL_P(arg2), "off", sizeof("off") - 1)) || @@ -175,14 +175,14 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callb (Z_STRLEN_P(arg2) == 5 && !strncasecmp(Z_STRVAL_P(arg2), "false", sizeof("false") - 1)) ) { // TODO: USE STR_EMPTY_ALLOC()? - ZVAL_NEW_STR(&new_property, STR_INIT("", sizeof("")-1, persistent)); + ZVAL_NEW_STR(&new_property, zend_string_init("", sizeof("")-1, persistent)); } else { /* Other than true/false setting */ - ZVAL_STR(&new_property, STR_DUP(Z_STR_P(arg2), persistent)); + ZVAL_STR(&new_property, zend_string_dup(Z_STR_P(arg2), persistent)); } - new_key = STR_DUP(Z_STR_P(arg1), persistent); + new_key = zend_string_dup(Z_STR_P(arg1), persistent); zend_str_tolower(new_key->val, new_key->len); zend_hash_update(Z_ARRVAL(bdata->current_section), new_key, &new_property); - STR_RELEASE(new_key); + zend_string_release(new_key); } break; case ZEND_INI_PARSER_SECTION: { @@ -208,7 +208,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callb zend_hash_update(bdata->htab, Z_STR_P(arg1), &bdata->current_section); ZVAL_STR(&processed, Z_STR_P(arg1)); - ZVAL_STR(&unprocessed, STR_DUP(Z_STR_P(arg1), persistent)); + ZVAL_STR(&unprocessed, zend_string_dup(Z_STR_P(arg1), persistent)); convert_browscap_pattern(&processed, persistent); zend_hash_str_update(Z_ARRVAL(bdata->current_section), "browser_name_regex", sizeof("browser_name_regex")-1, &processed); @@ -465,9 +465,9 @@ PHP_FUNCTION(get_browser) } if (agent_name == NULL) { - zend_string *key = STR_INIT("_SERVER", sizeof("_SERVER") - 1, 0); + zend_string *key = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0); zend_is_auto_global(key TSRMLS_CC); - STR_RELEASE(key); + zend_string_release(key); if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) != IS_UNDEF || (http_user_agent = zend_hash_str_find(HASH_OF(&PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) == NULL ) { diff --git a/ext/standard/credits.c b/ext/standard/credits.c index 3cb6eef724..6df81ca029 100644 --- a/ext/standard/credits.c +++ b/ext/standard/credits.c @@ -69,6 +69,7 @@ PHPAPI void php_print_credits(int flag TSRMLS_DC) /* {{{ */ CREDIT_LINE("Streams Abstraction Layer", "Wez Furlong, Sara Golemon"); CREDIT_LINE("PHP Data Objects Layer", "Wez Furlong, Marcus Boerger, Sterling Hughes, George Schlossnagle, Ilia Alshanetsky"); CREDIT_LINE("Output Handler", "Zeev Suraski, Thies C. Arntzen, Marcus Boerger, Michael Wallner"); + CREDIT_LINE("Consistent 64 bit support", "Anthony Ferrara, Anatol Belski"); php_info_print_table_end(); } diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c index 2a2304be20..5c9fcbafe8 100644 --- a/ext/standard/crypt.c +++ b/ext/standard/crypt.c @@ -136,7 +136,7 @@ PHP_MSHUTDOWN_FUNCTION(crypt) /* {{{ */ static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; -static void php_to64(char *s, long v, int n) /* {{{ */ +static void php_to64(char *s, zend_long v, int n) /* {{{ */ { while (--n >= 0) { *s++ = itoa64[v&0x3f]; @@ -160,7 +160,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch out = php_md5_crypt_r(password, salt, output); if (out) { - return STR_INIT(out, strlen(out), 0); + return zend_string_init(out, strlen(out), 0); } return NULL; } else if (salt[0]=='$' && salt[1]=='6' && salt[2]=='$') { @@ -173,7 +173,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch efree(output); return NULL; } else { - result = STR_INIT(output, strlen(output), 0); + result = zend_string_init(output, strlen(output), 0); memset(output, 0, PHP_MAX_SALT_LEN); efree(output); return result; @@ -188,7 +188,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch efree(output); return NULL; } else { - result = STR_INIT(output, strlen(output), 0); + result = zend_string_init(output, strlen(output), 0); memset(output, 0, PHP_MAX_SALT_LEN); efree(output); return result; @@ -210,7 +210,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch memset(output, 0, PHP_MAX_SALT_LEN + 1); return NULL; } else { - result = STR_INIT(output, strlen(output), 0); + result = zend_string_init(output, strlen(output), 0); memset(output, 0, PHP_MAX_SALT_LEN + 1); return result; } @@ -222,7 +222,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch if (!crypt_res) { return NULL; } else { - result = STR_INIT(crypt_res, strlen(crypt_res), 0); + result = zend_string_init(crypt_res, strlen(crypt_res), 0); return result; } } @@ -243,7 +243,7 @@ PHPAPI zend_string *php_crypt(const char *password, const int pass_len, const ch if (!crypt_res) { return FAILURE; } else { - result = STR_INIT(crypt_res, strlen(crypt_res), 0); + result = zend_string_init(crypt_res, strlen(crypt_res), 0); return result; } } diff --git a/ext/standard/crypt_sha256.c b/ext/standard/crypt_sha256.c index ccfa66bd60..e53f488805 100644 --- a/ext/standard/crypt_sha256.c +++ b/ext/standard/crypt_sha256.c @@ -372,7 +372,7 @@ char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int b if (strncmp(salt, sha256_rounds_prefix, sizeof(sha256_rounds_prefix) - 1) == 0) { const char *num = salt + sizeof(sha256_rounds_prefix) - 1; char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); + zend_ulong srounds = ZEND_STRTOUL(num, &endp, 10); if (*endp == '$') { salt = endp + 1; rounds = MAX(ROUNDS_MIN, MIN(srounds, ROUNDS_MAX)); diff --git a/ext/standard/crypt_sha512.c b/ext/standard/crypt_sha512.c index ebabed9d24..a673bfac1c 100644 --- a/ext/standard/crypt_sha512.c +++ b/ext/standard/crypt_sha512.c @@ -405,7 +405,7 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) if (strncmp(salt, sha512_rounds_prefix, sizeof(sha512_rounds_prefix) - 1) == 0) { const char *num = salt + sizeof(sha512_rounds_prefix) - 1; char *endp; - unsigned long int srounds = strtoul(num, &endp, 10); + zend_ulong srounds = ZEND_STRTOUL(num, &endp, 10); if (*endp == '$') { salt = endp + 1; diff --git a/ext/standard/cyr_convert.c b/ext/standard/cyr_convert.c index 326e9e21b8..503f3659ed 100644 --- a/ext/standard/cyr_convert.c +++ b/ext/standard/cyr_convert.c @@ -279,7 +279,7 @@ PHP_FUNCTION(convert_cyr_string) return; } - str = STR_INIT(input, input_len, 0); + str = zend_string_init(input, input_len, 0); php_convert_cyr_string(str->val, str->len, fr_cs[0], to_cs[0] TSRMLS_CC); RETVAL_NEW_STR(str); diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 16cc8db054..4d96384e9c 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -273,7 +273,7 @@ PHP_FUNCTION(closedir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a valid Directory resource", dirp->res->handle); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle); RETURN_FALSE; } @@ -387,7 +387,7 @@ PHP_FUNCTION(rewinddir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a valid Directory resource", dirp->res->handle); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle); RETURN_FALSE; } @@ -406,7 +406,7 @@ PHP_NAMED_FUNCTION(php_if_readdir) FETCH_DIRP(); if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a valid Directory resource", dirp->res->handle); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid Directory resource", dirp->res->handle); RETURN_FALSE; } @@ -430,7 +430,7 @@ PHP_FUNCTION(glob) #endif char *pattern = NULL; int pattern_len; - long flags = 0; + zend_long flags = 0; glob_t globbuf; int n; int ret; @@ -524,7 +524,7 @@ no_results: * able to filter directories out. */ if (flags & GLOB_ONLYDIR) { - struct stat s; + zend_stat_t s; if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) { continue; @@ -553,7 +553,7 @@ PHP_FUNCTION(scandir) { char *dirn; int dirn_len; - long flags = 0; + zend_long flags = 0; zend_string **namelist; int n, i; zval *zcontext = NULL; diff --git a/ext/standard/dns.c b/ext/standard/dns.c index cabe3d72f1..852ebaab22 100644 --- a/ext/standard/dns.c +++ b/ext/standard/dns.c @@ -203,10 +203,10 @@ static zend_string *php_gethostbyaddr(char *ip) #endif if (!hp || hp->h_name == NULL || hp->h_name[0] == '\0') { - return STR_INIT(ip, strlen(ip), 0); + return zend_string_init(ip, strlen(ip), 0); } - return STR_INIT(hp->h_name, strlen(hp->h_name), 0); + return zend_string_init(hp->h_name, strlen(hp->h_name), 0); } /* }}} */ @@ -263,13 +263,13 @@ static zend_string *php_gethostbyname(char *name) hp = gethostbyname(name); if (!hp || !*(hp->h_addr_list)) { - return STR_INIT(name, strlen(name), 0); + return zend_string_init(name, strlen(name), 0); } memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr)); address = inet_ntoa(in); - return STR_INIT(address, strlen(address), 0); + return zend_string_init(address, strlen(address), 0); } /* }}} */ @@ -411,8 +411,14 @@ PHP_FUNCTION(dns_check_record) #if HAVE_FULL_DNS_FUNCS +#define CHECKCP(n) do { \ + if (cp + n > end) { \ + return NULL; \ + } \ +} while (0) + /* {{{ php_parserr */ -static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int store, int raw, zval *subarray) +static u_char *php_parserr(u_char *cp, u_char *end, querybuf *answer, int type_to_fetch, int store, int raw, zval *subarray) { u_short type, class, dlen; u_long ttl; @@ -424,16 +430,18 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int ZVAL_UNDEF(subarray); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, sizeof(name) - 2); + n = dn_expand(answer->qb2, end, cp, name, sizeof(name) - 2); if (n < 0) { return NULL; } cp += n; + CHECKCP(10); GETSHORT(type, cp); GETSHORT(class, cp); GETLONG(ttl, cp); GETSHORT(dlen, cp); + CHECKCP(dlen); if (type_to_fetch != T_ANY && type != type_to_fetch) { cp += dlen; return cp; @@ -459,12 +467,14 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int switch (type) { case DNS_T_A: + CHECKCP(4); add_assoc_string(subarray, "type", "A"); snprintf(name, sizeof(name), "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]); add_assoc_string(subarray, "ip", name); cp += dlen; break; case DNS_T_MX: + CHECKCP(2); add_assoc_string(subarray, "type", "MX"); GETSHORT(n, cp); add_assoc_long(subarray, "pri", n); @@ -483,7 +493,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int if (type == DNS_T_PTR) { add_assoc_string(subarray, "type", "PTR"); } - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2); + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2); if (n < 0) { return NULL; } @@ -493,38 +503,45 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int case DNS_T_HINFO: /* See RFC 1010 for values */ add_assoc_string(subarray, "type", "HINFO"); + CHECKCP(1); n = *cp & 0xFF; cp++; + CHECKCP(n); add_assoc_stringl(subarray, "cpu", (char*)cp, n); cp += n; + CHECKCP(1); n = *cp & 0xFF; cp++; + CHECKCP(n); add_assoc_stringl(subarray, "os", (char*)cp, n); cp += n; break; case DNS_T_TXT: { - int ll = 0; + int l1 = 0, l2 = 0; zval entries; zend_string *tp; add_assoc_string(subarray, "type", "TXT"); - tp = STR_ALLOC(dlen, 0); + tp = zend_string_alloc(dlen, 0); array_init(&entries); - while (ll < dlen) { - n = cp[ll]; - if ((ll + n) >= dlen) { + while (l1 < dlen) { + n = cp[l1]; + if ((l1 + n) >= dlen) { // Invalid chunk length, truncate - n = dlen - (ll + 1); + n = dlen - (l1 + 1); + } + if (n) { + memcpy(tp->val + l2 , cp + l1 + 1, n); + add_next_index_stringl(&entries, cp + l1 + 1, n); } - memcpy(tp->val + ll , cp + ll + 1, n); - add_next_index_stringl(&entries, (char*)cp + ll + 1, n); - ll = ll + n + 1; + l1 = l1 + n + 1; + l2 = l2 + n; } - tp->val[dlen] = '\0'; - tp->len = dlen; + tp->val[l2] = '\0'; + tp->len = l2; cp += dlen; add_assoc_str(subarray, "txt", tp); @@ -533,18 +550,19 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int break; case DNS_T_SOA: add_assoc_string(subarray, "type", "SOA"); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) -2); + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) -2); if (n < 0) { return NULL; } cp += n; add_assoc_string(subarray, "mname", name); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) -2); + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) -2); if (n < 0) { return NULL; } cp += n; add_assoc_string(subarray, "rname", name); + CHECKCP(5*4); GETLONG(n, cp); add_assoc_long(subarray, "serial", n); GETLONG(n, cp); @@ -558,6 +576,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int break; case DNS_T_AAAA: tp = (u_char*)name; + CHECKCP(8*2); for(i=0; i < 8; i++) { GETSHORT(s, cp); if (s != 0) { @@ -592,6 +611,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int case DNS_T_A6: p = cp; add_assoc_string(subarray, "type", "A6"); + CHECKCP(1); n = ((int)cp[0]) & 0xFF; cp++; add_assoc_long(subarray, "masklen", n); @@ -627,6 +647,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int cp++; } for (i = (n + 8) / 16; i < 8; i++) { + CHECKCP(2); GETSHORT(s, cp); if (s != 0) { if (tp > (u_char *)name) { @@ -656,7 +677,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int tp[0] = '\0'; add_assoc_string(subarray, "ipv6", name); if (cp < p + dlen) { - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2); + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2); if (n < 0) { return NULL; } @@ -665,6 +686,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int } break; case DNS_T_SRV: + CHECKCP(3*2); add_assoc_string(subarray, "type", "SRV"); GETSHORT(n, cp); add_assoc_long(subarray, "pri", n); @@ -672,7 +694,7 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int add_assoc_long(subarray, "weight", n); GETSHORT(n, cp); add_assoc_long(subarray, "port", n); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2); + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2); if (n < 0) { return NULL; } @@ -680,21 +702,35 @@ static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int add_assoc_string(subarray, "target", name); break; case DNS_T_NAPTR: + CHECKCP(2*2); add_assoc_string(subarray, "type", "NAPTR"); GETSHORT(n, cp); add_assoc_long(subarray, "order", n); GETSHORT(n, cp); add_assoc_long(subarray, "pref", n); + + CHECKCP(1); n = (cp[0] & 0xFF); - add_assoc_stringl(subarray, "flags", (char*)++cp, n); + cp++; + CHECKCP(n); + add_assoc_stringl(subarray, "flags", (char*)cp, n); cp += n; + + CHECKCP(1); n = (cp[0] & 0xFF); - add_assoc_stringl(subarray, "services", (char*)++cp, n); + cp++; + CHECKCP(n); + add_assoc_stringl(subarray, "services", (char*)cp, n); cp += n; + + CHECKCP(1); n = (cp[0] & 0xFF); - add_assoc_stringl(subarray, "regex", (char*)++cp, n); + cp++; + CHECKCP(n); + add_assoc_stringl(subarray, "regex", (char*)cp, n); cp += n; - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2); + + n = dn_expand(answer->qb2, end, cp, name, (sizeof name) - 2); if (n < 0) { return NULL; } @@ -887,7 +923,7 @@ PHP_FUNCTION(dns_get_record) while (an-- && cp && cp < end) { zval retval; - cp = php_parserr(cp, &answer, type_to_fetch, store_results, raw, &retval); + cp = php_parserr(cp, end, &answer, type_to_fetch, store_results, raw, &retval); if (Z_TYPE(retval) != IS_UNDEF && store_results) { add_next_index_zval(return_value, &retval); } @@ -900,7 +936,7 @@ PHP_FUNCTION(dns_get_record) while (ns-- > 0 && cp && cp < end) { zval retval; - cp = php_parserr(cp, &answer, DNS_T_ANY, authns != NULL, raw, &retval); + cp = php_parserr(cp, end, &answer, DNS_T_ANY, authns != NULL, raw, &retval); if (Z_TYPE(retval) != IS_UNDEF) { add_next_index_zval(authns, &retval); } @@ -912,7 +948,7 @@ PHP_FUNCTION(dns_get_record) while (ar-- > 0 && cp && cp < end) { zval retval; - cp = php_parserr(cp, &answer, DNS_T_ANY, 1, raw, &retval); + cp = php_parserr(cp, end, &answer, DNS_T_ANY, 1, raw, &retval); if (Z_TYPE(retval) != IS_UNDEF) { add_next_index_zval(addtl, &retval); } diff --git a/ext/standard/dns_win32.c b/ext/standard/dns_win32.c index f255ebba63..7decf91c5c 100644 --- a/ext/standard/dns_win32.c +++ b/ext/standard/dns_win32.c @@ -219,7 +219,7 @@ static void php_parserr(PDNS_RECORD pRec, int type_to_fetch, int store, int raw, txt_len += strlen(data_txt->pStringArray[i]) + 1; } - txt = STR_SAFE_ALLOC(txt_len, 2, 0, 0); + txt = zend_string_safe_alloc(txt_len, 2, 0, 0); txt_dst = txt->val; for (i = 0; i < count; i++) { int len = strlen(data_txt->pStringArray[i]); diff --git a/ext/standard/exec.c b/ext/standard/exec.c index 6720231089..fe0443d59c 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -247,7 +247,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str) TSRMLS_FETCH(); - cmd = STR_ALLOC(2 * l, 0); + cmd = zend_string_alloc(2 * l, 0); for (x = 0, y = 0; x < l; x++) { int mb_len = php_mblen(str + x, (l - x)); @@ -320,7 +320,7 @@ PHPAPI zend_string *php_escape_shell_cmd(char *str) if ((estimate - y) > 4096) { /* realloc if the estimate was way overill * Arbitrary cutoff point of 4096 */ - cmd = STR_REALLOC(cmd, y, 0); + cmd = zend_string_realloc(cmd, y, 0); } cmd->len = y; @@ -339,7 +339,7 @@ PHPAPI zend_string *php_escape_shell_arg(char *str) TSRMLS_FETCH(); - cmd = STR_ALLOC(4 * l + 2, 0); /* worst case */ + cmd = zend_string_alloc(4 * l + 2, 0); /* worst case */ #ifdef PHP_WIN32 cmd->val[y++] = '"'; @@ -387,7 +387,7 @@ PHPAPI zend_string *php_escape_shell_arg(char *str) if ((estimate - y) > 4096) { /* realloc if the estimate was way overill * Arbitrary cutoff point of 4096 */ - cmd = STR_REALLOC(cmd, y, 0); + cmd = zend_string_realloc(cmd, y, 0); } cmd->len = y; return cmd; @@ -470,7 +470,7 @@ PHP_FUNCTION(shell_exec) Change the priority of the current process */ PHP_FUNCTION(proc_nice) { - long pri; + zend_long pri; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pri) == FAILURE) { RETURN_FALSE; diff --git a/ext/standard/file.c b/ext/standard/file.c index 4551bef8cf..28fc790ea9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -342,7 +342,7 @@ PHP_FUNCTION(flock) zval *arg1, *arg3 = NULL; int act; php_stream *stream; - long operation = 0; + zend_long operation = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z/", &arg1, &operation, &arg3) == FAILURE) { return; @@ -526,8 +526,8 @@ PHP_FUNCTION(file_get_contents) int filename_len; zend_bool use_include_path = 0; php_stream *stream; - long offset = -1; - long maxlen = PHP_STREAM_COPY_ALL; + zend_long offset = -1; + zend_long maxlen = PHP_STREAM_COPY_ALL; zval *zcontext = NULL; php_stream_context *context = NULL; zend_string *contents; @@ -552,13 +552,13 @@ PHP_FUNCTION(file_get_contents) } if (offset > 0 && php_stream_seek(stream, offset, SEEK_SET) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", offset); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position " ZEND_LONG_FMT " in the stream", offset); php_stream_close(stream); RETURN_FALSE; } if (maxlen > INT_MAX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "maxlen truncated from %ld to %d bytes", maxlen, INT_MAX); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "maxlen truncated from %pd to %d bytes", maxlen, INT_MAX); maxlen = INT_MAX; } if ((contents = php_stream_copy_to_mem(stream, maxlen, 0)) != NULL) { @@ -579,12 +579,13 @@ PHP_FUNCTION(file_put_contents) char *filename; int filename_len; zval *data; - long numbytes = 0; - long flags = 0; + zend_long numbytes = 0; + zend_long flags = 0; zval *zcontext = NULL; php_stream_context *context = NULL; php_stream *srcstream = NULL; char mode[3] = "wb"; + char ret_ok = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) { return; @@ -629,11 +630,11 @@ PHP_FUNCTION(file_put_contents) case IS_RESOURCE: { size_t len; if (php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL, &len) != SUCCESS) { - numbytes = -1; + ret_ok = 0; } else { - if (len > LONG_MAX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "content truncated from %lu to %ld bytes", (unsigned long) len, LONG_MAX); - len = LONG_MAX; + if (len > ZEND_LONG_MAX) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "content truncated from %zu to " ZEND_LONG_FMT " bytes", len, ZEND_LONG_MAX); + len = ZEND_LONG_MAX; } numbytes = len; } @@ -650,7 +651,7 @@ PHP_FUNCTION(file_put_contents) if (Z_STRLEN_P(data)) { numbytes = php_stream_write(stream, Z_STRVAL_P(data), Z_STRLEN_P(data)); if (numbytes != Z_STRLEN_P(data)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %ld of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN_P(data)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %pl of %zd bytes written, possibly out of free disk space", numbytes, Z_STRLEN_P(data)); numbytes = -1; } } @@ -658,7 +659,7 @@ PHP_FUNCTION(file_put_contents) case IS_ARRAY: if (zend_hash_num_elements(Z_ARRVAL_P(data))) { - int bytes_written; + size_t bytes_written; zval *tmp; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(data), tmp) { @@ -666,18 +667,14 @@ PHP_FUNCTION(file_put_contents) if (str->len) { numbytes += str->len; bytes_written = php_stream_write(stream, str->val, str->len); - if (bytes_written < 0 || bytes_written != str->len) { - if (bytes_written < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write %d bytes to %s", str->len, filename); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d bytes written, possibly out of free disk space", bytes_written, str->len); - } - numbytes = -1; - STR_RELEASE(str); + if (bytes_written != str->len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write %zd bytes to %s", str->len, filename); + ret_ok = 0; + zend_string_release(str); break; } } - STR_RELEASE(str); + zend_string_release(str); } ZEND_HASH_FOREACH_END(); } break; @@ -689,7 +686,7 @@ PHP_FUNCTION(file_put_contents) if (zend_std_cast_object_tostring(data, &out, IS_STRING TSRMLS_CC) == SUCCESS) { numbytes = php_stream_write(stream, Z_STRVAL(out), Z_STRLEN(out)); if (numbytes != Z_STRLEN(out)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %ld of %d bytes written, possibly out of free disk space", numbytes, Z_STRLEN(out)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %pd of %zd bytes written, possibly out of free disk space", numbytes, Z_STRLEN(out)); numbytes = -1; } zval_dtor(&out); @@ -697,12 +694,12 @@ PHP_FUNCTION(file_put_contents) } } default: - numbytes = -1; + ret_ok = 0; break; } php_stream_close(stream); - if (numbytes < 0) { + if (!ret_ok) { RETURN_FALSE; } @@ -721,7 +718,7 @@ PHP_FUNCTION(file) char *p, *s, *e; register int i = 0; char eol_marker = '\n'; - long flags = 0; + zend_long flags = 0; zend_bool use_include_path; zend_bool include_new_line; zend_bool skip_blank_lines; @@ -735,7 +732,7 @@ PHP_FUNCTION(file) return; } if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%ld' flag is not supported", flags); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'" ZEND_LONG_FMT "' flag is not supported", flags); RETURN_FALSE; } @@ -798,7 +795,7 @@ parse_eol: } if (target_buf) { - STR_FREE(target_buf); + zend_string_free(target_buf); } php_stream_close(stream); } @@ -835,7 +832,7 @@ PHP_FUNCTION(tempnam) RETVAL_STRING(opened_path); efree(opened_path); } - STR_RELEASE(p); + zend_string_release(p); } /* }}} */ @@ -906,7 +903,7 @@ PHPAPI PHP_FUNCTION(fclose) PHP_STREAM_TO_ZVAL(stream, arg1); if ((stream->flags & PHP_STREAM_FLAG_NO_FCLOSE) != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a valid stream resource", stream->res->handle); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%pd is not a valid stream resource", stream->res->handle); RETURN_FALSE; } @@ -1010,7 +1007,7 @@ PHPAPI PHP_FUNCTION(feof) PHPAPI PHP_FUNCTION(fgets) { zval *arg1; - long len = 1024; + zend_long len = 1024; char *buf = NULL; int argc = ZEND_NUM_ARGS(); size_t line_len = 0; @@ -1094,7 +1091,7 @@ PHPAPI PHP_FUNCTION(fgetc) PHPAPI PHP_FUNCTION(fgetss) { zval *fd; - long bytes = 0; + zend_long bytes = 0; size_t len = 0; size_t actual_len, retval_len; char *buf = NULL, *retval; @@ -1200,7 +1197,7 @@ PHPAPI PHP_FUNCTION(fwrite) int arg2len; int ret; int num_bytes; - long arg3 = 0; + zend_long arg3 = 0; char *buffer = NULL; php_stream *stream; @@ -1276,7 +1273,7 @@ PHPAPI PHP_FUNCTION(rewind) PHPAPI PHP_FUNCTION(ftell) { zval *arg1; - long ret; + zend_long ret; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { @@ -1298,7 +1295,7 @@ PHPAPI PHP_FUNCTION(ftell) PHPAPI PHP_FUNCTION(fseek) { zval *arg1; - long arg2, whence = SEEK_SET; + zend_long arg2, whence = SEEK_SET; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &arg2, &whence) == FAILURE) { @@ -1315,7 +1312,7 @@ PHPAPI PHP_FUNCTION(fseek) */ /* DEPRECATED APIs: Use php_stream_mkdir() instead */ -PHPAPI int php_mkdir_ex(const char *dir, long mode, int options TSRMLS_DC) +PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options TSRMLS_DC) { int ret; @@ -1330,7 +1327,7 @@ PHPAPI int php_mkdir_ex(const char *dir, long mode, int options TSRMLS_DC) return ret; } -PHPAPI int php_mkdir(const char *dir, long mode TSRMLS_DC) +PHPAPI int php_mkdir(const char *dir, zend_long mode TSRMLS_DC) { return php_mkdir_ex(dir, mode, REPORT_ERRORS TSRMLS_CC); } @@ -1343,7 +1340,7 @@ PHP_FUNCTION(mkdir) char *dir; int dir_len; zval *zcontext = NULL; - long mode = 0777; + zend_long mode = 0777; zend_bool recursive = 0; php_stream_context *context; @@ -1409,7 +1406,7 @@ PHP_FUNCTION(readfile) Return or change the umask */ PHP_FUNCTION(umask) { - long arg1 = 0; + zend_long arg1 = 0; int oldumask; oldumask = umask(077); @@ -1524,7 +1521,7 @@ PHP_FUNCTION(unlink) PHP_NAMED_FUNCTION(php_if_ftruncate) { zval *fp; - long size; + zend_long size; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &fp, &size) == FAILURE) { @@ -1767,7 +1764,7 @@ safe_to_copy: PHPAPI PHP_FUNCTION(fread) { zval *arg1; - long len; + zend_long len; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &len) == FAILURE) { @@ -1781,7 +1778,7 @@ PHPAPI PHP_FUNCTION(fread) RETURN_FALSE; } - ZVAL_NEW_STR(return_value, STR_ALLOC(len, 0)); + ZVAL_NEW_STR(return_value, zend_string_alloc(len, 0)); Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len); /* needed because recv/read/gzread doesnt put a null at the end*/ @@ -1891,8 +1888,8 @@ PHP_FUNCTION(fputcsv) } /* }}} */ -/* {{{ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) */ -PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) +/* {{{ PHPAPI size_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) */ +PHPAPI size_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC) { int count, i = 0, ret; zval *field_tmp; @@ -1935,7 +1932,7 @@ PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char en if (++i != count) { smart_str_appendl(&csvline, &delimiter, 1); } - STR_RELEASE(field_str); + zend_string_release(field_str); } ZEND_HASH_FOREACH_END(); smart_str_appendc(&csvline, '\n'); @@ -1959,7 +1956,7 @@ PHP_FUNCTION(fgetcsv) /* first section exactly as php_fgetss */ - long len = 0; + zend_long len = 0; size_t buf_len; char *buf; php_stream *stream; @@ -2457,7 +2454,7 @@ PHP_FUNCTION(fnmatch) { char *pattern, *filename; int pattern_len, filename_len; - long flags = 0; + zend_long flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pp|l", &pattern, &pattern_len, &filename, &filename_len, &flags) == FAILURE) { return; diff --git a/ext/standard/file.h b/ext/standard/file.h index 9c044aff1e..4551d5ec44 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -77,10 +77,10 @@ PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC); PHPAPI int php_copy_file(const char *src, const char *dest TSRMLS_DC); PHPAPI int php_copy_file_ex(const char *src, const char *dest, int src_chk TSRMLS_DC); PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_chk, php_stream_context *ctx TSRMLS_DC); -PHPAPI int php_mkdir_ex(const char *dir, long mode, int options TSRMLS_DC); -PHPAPI int php_mkdir(const char *dir, long mode TSRMLS_DC); +PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options TSRMLS_DC); +PHPAPI int php_mkdir(const char *dir, zend_long mode TSRMLS_DC); PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char escape_char, size_t buf_len, char *buf, zval *return_value TSRMLS_DC); -PHPAPI int php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC); +PHPAPI size_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char TSRMLS_DC); #define META_DEF_BUFSIZE 8192 @@ -117,8 +117,8 @@ php_meta_tags_token php_next_meta_token(php_meta_tags_data * TSRMLS_DC); typedef struct { int pclose_ret; size_t def_chunk_size; - long auto_detect_line_endings; - long default_socket_timeout; + zend_long auto_detect_line_endings; + zend_long default_socket_timeout; char *user_agent; /* for the http wrapper */ char *from_address; /* for the ftp and http wrappers */ const char *user_stream_current_filename; /* for simple recursion protection */ diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 9fb35ef344..a081fdf4f0 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -158,7 +158,7 @@ static int php_disk_total_space(char *path, double *space TSRMLS_DC) /* {{{ */ /* i know - this is ugly, but i works <thies@thieso.net> */ bytestotal = TotalNumberOfBytes.HighPart * - (double) (((unsigned long)1) << 31) * 2.0 + + (double) (((zend_ulong)1) << 31) * 2.0 + TotalNumberOfBytes.LowPart; } else { /* If it's not available, we just use GetDiskFreeSpace */ if (GetDiskFreeSpace(path, @@ -290,7 +290,7 @@ static int php_disk_free_space(char *path, double *space TSRMLS_DC) /* {{{ */ /* i know - this is ugly, but i works <thies@thieso.net> */ bytesfree = FreeBytesAvailableToCaller.HighPart * - (double) (((unsigned long)1) << 31) * 2.0 + + (double) (((zend_ulong)1) << 31) * 2.0 + FreeBytesAvailableToCaller.LowPart; } else { /* If it's not available, we just use GetDiskFreeSpace */ if (GetDiskFreeSpace(path, @@ -668,7 +668,7 @@ PHP_FUNCTION(chmod) { char *filename; int filename_len; - long mode; + zend_long mode; int ret; mode_t imode; php_stream_wrapper *wrapper; @@ -714,7 +714,7 @@ PHP_FUNCTION(touch) { char *filename; int filename_len; - long filetime = 0, fileatime = 0; + zend_long filetime = 0, fileatime = 0; int ret, argc = ZEND_NUM_ARGS(); FILE *file; struct utimbuf newtimebuf; @@ -850,7 +850,7 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ { zval stat_dev, stat_ino, stat_mode, stat_nlink, stat_uid, stat_gid, stat_rdev, stat_size, stat_atime, stat_mtime, stat_ctime, stat_blksize, stat_blocks; - struct stat *stat_sb; + zend_stat_t *stat_sb; php_stream_statbuf ssb; int flags = 0, rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */ char *stat_sb_names[13] = { @@ -962,21 +962,21 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ switch (type) { case FS_PERMS: - RETURN_LONG((long)ssb.sb.st_mode); + RETURN_LONG((zend_long)ssb.sb.st_mode); case FS_INODE: - RETURN_LONG((long)ssb.sb.st_ino); + RETURN_LONG((zend_long)ssb.sb.st_ino); case FS_SIZE: - RETURN_LONG((long)ssb.sb.st_size); + RETURN_LONG((zend_long)ssb.sb.st_size); case FS_OWNER: - RETURN_LONG((long)ssb.sb.st_uid); + RETURN_LONG((zend_long)ssb.sb.st_uid); case FS_GROUP: - RETURN_LONG((long)ssb.sb.st_gid); + RETURN_LONG((zend_long)ssb.sb.st_gid); case FS_ATIME: - RETURN_LONG((long)ssb.sb.st_atime); + RETURN_LONG((zend_long)ssb.sb.st_atime); case FS_MTIME: - RETURN_LONG((long)ssb.sb.st_mtime); + RETURN_LONG((zend_long)ssb.sb.st_mtime); case FS_CTIME: - RETURN_LONG((long)ssb.sb.st_ctime); + RETURN_LONG((zend_long)ssb.sb.st_ctime); case FS_TYPE: if (S_ISLNK(ssb.sb.st_mode)) { RETURN_STRING("link"); @@ -1223,7 +1223,7 @@ PHP_FUNCTION(realpath_cache_get) array_init(&entry); /* bucket->key is unsigned long */ - if (LONG_MAX >= bucket->key) { + if (ZEND_LONG_MAX >= bucket->key) { add_assoc_long(&entry, "key", bucket->key); } else { add_assoc_double(&entry, "key", (double)bucket->key); diff --git a/ext/standard/filters.c b/ext/standard/filters.c index d40321f959..f7ddbf5a39 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -1224,7 +1224,7 @@ static php_conv_err_t php_conv_get_string_prop_ex(const HashTable *ht, char **pr *pretval_len = str->len; memcpy(*pretval, str->val, str->len + 1); - STR_RELEASE(str); + zend_string_release(str); } else { return PHP_CONV_ERR_NOT_FOUND; } @@ -1232,7 +1232,7 @@ static php_conv_err_t php_conv_get_string_prop_ex(const HashTable *ht, char **pr } #if IT_WAS_USED -static php_conv_err_t php_conv_get_long_prop_ex(const HashTable *ht, long *pretval, char *field_name, size_t field_name_len) +static php_conv_err_t php_conv_get_long_prop_ex(const HashTable *ht, zend_long *pretval, char *field_name, size_t field_name_len) { zval **tmpval; @@ -1244,7 +1244,7 @@ static php_conv_err_t php_conv_get_long_prop_ex(const HashTable *ht, long *pretv if (Z_TYPE_PP(tmpval) != IS_LONG) { tmp = *ztval; zval_copy_ctor(&tmp); - convert_to_long(&tmp); + convert_to_int(&tmp); ztval = &tmp; } *pretval = Z_LVAL_P(ztval); @@ -1255,7 +1255,7 @@ static php_conv_err_t php_conv_get_long_prop_ex(const HashTable *ht, long *pretv } #endif -static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, unsigned long *pretval, char *field_name, size_t field_name_len) +static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, zend_ulong *pretval, char *field_name, size_t field_name_len) { zval *tmpval; @@ -1266,7 +1266,7 @@ static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, unsigned l if (Z_TYPE_P(tmpval) != IS_LONG) { ZVAL_DUP(&tmp, tmpval);; - convert_to_long(&tmp); + convert_to_int(&tmp); tmpval = &tmp; } if (Z_LVAL_P(tmpval) < 0) { @@ -1306,7 +1306,7 @@ static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, int *pretva #if IT_WAS_USED static int php_conv_get_int_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len) { - long l; + zend_long l; php_conv_err_t err; *pretval = 0; @@ -1320,7 +1320,7 @@ static int php_conv_get_int_prop_ex(const HashTable *ht, int *pretval, char *fie static int php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len) { - unsigned long l; + zend_ulong l; php_conv_err_t err; *pretval = 0; diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c index edd704b068..587474346a 100644 --- a/ext/standard/formatted_print.c +++ b/ext/standard/formatted_print.c @@ -52,11 +52,11 @@ static char HEXCHARS[] = "0123456789ABCDEF"; /* php_spintf_appendchar() {{{ */ inline static void -php_sprintf_appendchar(zend_string **buffer, int *pos, char add TSRMLS_DC) +php_sprintf_appendchar(zend_string **buffer, size_t *pos, char add TSRMLS_DC) { if (!*buffer || (*pos + 1) >= (*buffer)->len) { PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(TSRMLS_C), (*buffer)->len)); - *buffer = STR_REALLOC(*buffer, (*buffer)->len << 1, 0); + *buffer = zend_string_realloc(*buffer, (*buffer)->len << 1, 0); } PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos)); (*buffer)->val[(*pos)++] = add; @@ -65,22 +65,18 @@ php_sprintf_appendchar(zend_string **buffer, int *pos, char add TSRMLS_DC) /* php_spintf_appendstring() {{{ */ inline static void -php_sprintf_appendstring(zend_string **buffer, int *pos, char *add, - int min_width, int max_width, char padding, - int alignment, int len, int neg, int expprec, int always_sign) +php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add, + size_t min_width, size_t max_width, char padding, + size_t alignment, size_t len, int neg, int expprec, int always_sign) { - register int npad; - int req_size; - int copy_len; - int m_width; + register size_t npad; + size_t req_size; + size_t copy_len; + size_t m_width; copy_len = (expprec ? MIN(max_width, len) : len); - npad = min_width - copy_len; + npad = (min_width < copy_len) ? 0 : min_width - copy_len; - if (npad < 0) { - npad = 0; - } - PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n", *buffer, *pos, (*buffer)->len, add, min_width, padding, alignment)); m_width = MAX(min_width, copy_len); @@ -92,15 +88,15 @@ php_sprintf_appendstring(zend_string **buffer, int *pos, char *add, req_size = *pos + m_width + 1; if (!*buffer || req_size > (*buffer)->len) { - int size = (*buffer)->len; + size_t size = (*buffer)->len; while (req_size > size) { - if (size > INT_MAX/2) { - zend_error_noreturn(E_ERROR, "Field width %d is too long", req_size); + if (size > ZEND_SIZE_MAX/2) { + zend_error_noreturn(E_ERROR, "Field width %zd is too long", req_size); } size <<= 1; } PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", size)); - *buffer = STR_REALLOC(*buffer, size, 0); + *buffer = zend_string_realloc(*buffer, size, 0); } if (alignment == ALIGN_RIGHT) { if ((neg || always_sign) && padding=='0') { @@ -126,21 +122,21 @@ php_sprintf_appendstring(zend_string **buffer, int *pos, char *add, /* php_spintf_appendint() {{{ */ inline static void -php_sprintf_appendint(zend_string **buffer, int *pos, long number, - int width, char padding, int alignment, +php_sprintf_appendint(zend_string **buffer, size_t *pos, zend_long number, + size_t width, char padding, size_t alignment, int always_sign) { char numbuf[NUM_BUF_SIZE]; - register unsigned long magn, nmagn; + register zend_ulong magn, nmagn; register unsigned int i = NUM_BUF_SIZE - 1, neg = 0; PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n", *buffer, pos, &(*buffer)->len, number, width, padding, alignment)); if (number < 0) { neg = 1; - magn = ((unsigned long) -(number + 1)) + 1; + magn = ((zend_ulong) -(number + 1)) + 1; } else { - magn = (unsigned long) number; + magn = (zend_ulong) number; } /* Can't right-pad 0's on integers */ @@ -170,17 +166,17 @@ php_sprintf_appendint(zend_string **buffer, int *pos, long number, /* php_spintf_appenduint() {{{ */ inline static void -php_sprintf_appenduint(zend_string **buffer, int *pos, - unsigned long number, - int width, char padding, int alignment) +php_sprintf_appenduint(zend_string **buffer, size_t *pos, + zend_ulong number, + size_t width, char padding, size_t alignment) { char numbuf[NUM_BUF_SIZE]; - register unsigned long magn, nmagn; + register zend_ulong magn, nmagn; register unsigned int i = NUM_BUF_SIZE - 1; PRINTF_DEBUG(("sprintf: appenduint(%x, %x, %x, %d, %d, '%c', %d)\n", *buffer, pos, &(*buffer)->len, number, width, padding, alignment)); - magn = (unsigned long) number; + magn = (zend_ulong) number; /* Can't right-pad 0's on integers */ if (alignment == 0 && padding == '0') padding = ' '; @@ -202,17 +198,18 @@ php_sprintf_appenduint(zend_string **buffer, int *pos, /* php_spintf_appenddouble() {{{ */ inline static void -php_sprintf_appenddouble(zend_string **buffer, int *pos, +php_sprintf_appenddouble(zend_string **buffer, size_t *pos, double number, - int width, char padding, - int alignment, int precision, + size_t width, char padding, + size_t alignment, int precision, int adjust, char fmt, int always_sign TSRMLS_DC) { char num_buf[NUM_BUF_SIZE]; char *s = NULL; - int s_len = 0, is_negative = 0; + size_t s_len = 0; + int is_negative = 0; #ifdef HAVE_LOCALE_H struct lconv *lconv; #endif @@ -293,13 +290,13 @@ php_sprintf_appenddouble(zend_string **buffer, int *pos, /* php_spintf_appendd2n() {{{ */ inline static void -php_sprintf_append2n(zend_string **buffer, int *pos, long number, - int width, char padding, int alignment, int n, +php_sprintf_append2n(zend_string **buffer, size_t *pos, zend_long number, + size_t width, char padding, size_t alignment, int n, char *chartable, int expprec) { char numbuf[NUM_BUF_SIZE]; - register unsigned long num; - register unsigned int i = NUM_BUF_SIZE - 1; + register zend_ulong num; + register zend_ulong i = NUM_BUF_SIZE - 1; register int andbits = (1 << n) - 1; PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n", @@ -307,7 +304,7 @@ php_sprintf_append2n(zend_string **buffer, int *pos, long number, chartable)); PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits)); - num = (unsigned long) number; + num = (zend_ulong) number; numbuf[i] = '\0'; do { @@ -324,11 +321,11 @@ php_sprintf_append2n(zend_string **buffer, int *pos, long number, /* php_spintf_getnumber() {{{ */ inline static int -php_sprintf_getnumber(char *buffer, int *pos) +php_sprintf_getnumber(char *buffer, size_t *pos) { char *endptr; - register long num = strtol(&buffer[*pos], &endptr, 10); - register int i = 0; + register zend_long num = ZEND_STRTOL(&buffer[*pos], &endptr, 10); + register size_t i = 0; if (endptr != NULL) { i = (endptr - &buffer[*pos]); @@ -373,7 +370,8 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) { zval *newargs = NULL; zval *args, *z_format; - int argc, size = 240, inpos = 0, outpos = 0, temppos; + int argc; + size_t size = 240, inpos = 0, outpos = 0, temppos; int alignment, currarg, adjusting, argnum, width, precision; char *format, padding; zend_string *result; @@ -417,7 +415,7 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) format = Z_STRVAL(args[format_offset]); format_len = Z_STRLEN(args[format_offset]); - result = STR_ALLOC(size, 0); + result = zend_string_alloc(size, 0); currarg = 1; @@ -563,7 +561,7 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC) alignment, str->len, 0, expprec, 0); - STR_RELEASE(str); + zend_string_release(str); break; } @@ -680,13 +678,13 @@ PHP_FUNCTION(vsprintf) PHP_FUNCTION(user_printf) { zend_string *result; - int rlen; + size_t rlen; if ((result=php_formatted_print(ZEND_NUM_ARGS(), 0, 0 TSRMLS_CC))==NULL) { RETURN_FALSE; } rlen = PHPWRITE(result->val, result->len); - STR_FREE(result); + zend_string_free(result); RETURN_LONG(rlen); } /* }}} */ @@ -696,13 +694,13 @@ PHP_FUNCTION(user_printf) PHP_FUNCTION(vprintf) { zend_string *result; - int rlen; + size_t rlen; if ((result=php_formatted_print(ZEND_NUM_ARGS(), 1, 0 TSRMLS_CC))==NULL) { RETURN_FALSE; } rlen = PHPWRITE(result->val, result->len); - STR_FREE(result); + zend_string_free(result); RETURN_LONG(rlen); } /* }}} */ @@ -732,7 +730,7 @@ PHP_FUNCTION(fprintf) php_stream_write(stream, result->val, result->len); RETVAL_LONG(result->len); - STR_FREE(result); + zend_string_free(result); } /* }}} */ @@ -761,7 +759,7 @@ PHP_FUNCTION(vfprintf) php_stream_write(stream, result->val, result->len); RETVAL_LONG(result->len); - STR_FREE(result); + zend_string_free(result); } /* }}} */ diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index 300df8c1c0..319a0437d6 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -33,16 +33,16 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) { char *host; int host_len; - long port = -1; + zend_long port = -1; zval *zerrno = NULL, *zerrstr = NULL; double timeout = FG(default_socket_timeout); - unsigned long conv; + zend_ulong conv; struct timeval tv; char *hashkey = NULL; php_stream *stream = NULL; int err; char *hostname = NULL; - long hostname_len; + zend_long hostname_len; zend_string *errstr = NULL; RETVAL_FALSE; @@ -52,11 +52,11 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) } if (persistent) { - spprintf(&hashkey, 0, "pfsockopen__%s:%ld", host, port); + spprintf(&hashkey, 0, "pfsockopen__%s:" ZEND_LONG_FMT, host, port); } if (port > 0) { - hostname_len = spprintf(&hostname, 0, "%s:%ld", host, port); + hostname_len = spprintf(&hostname, 0, "%s:" ZEND_LONG_FMT, host, port); } else { hostname_len = host_len; hostname = host; @@ -83,7 +83,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) efree(hostname); } if (stream == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%ld (%s)", host, port, errstr == NULL ? "Unknown error" : errstr->val); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:" ZEND_LONG_FMT " (%s)", host, port, errstr == NULL ? "Unknown error" : errstr->val); } if (hashkey) { @@ -100,14 +100,14 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) zval_dtor(zerrstr); ZVAL_STR(zerrstr, errstr); } else if (!zerrstr && errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } RETURN_FALSE; } if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } php_stream_to_zval(stream, return_value); diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 31b96fb68c..cb96c190db 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -531,10 +531,10 @@ php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, const char *pa (tmpzval = php_stream_context_get_option(context, "ftp", "resume_pos")) != NULL && Z_TYPE_P(tmpzval) == IS_LONG && Z_LVAL_P(tmpzval) > 0) { - php_stream_printf(stream TSRMLS_CC, "REST %ld\r\n", Z_LVAL_P(tmpzval)); + php_stream_printf(stream TSRMLS_CC, "REST %pd\r\n", Z_LVAL_P(tmpzval)); result = GET_FTP_RESULT(stream); if (result < 300 || result > 399) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to resume from offset %ld", Z_LVAL_P(tmpzval)); + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to resume from offset %pd", Z_LVAL_P(tmpzval)); goto errexit; } } @@ -632,7 +632,7 @@ static size_t php_ftp_dirstream_read(php_stream *stream, char *buf, size_t count tmp_len = MIN(sizeof(ent->d_name), basename->len - 1); memcpy(ent->d_name, basename->val, tmp_len); ent->d_name[tmp_len - 1] = '\0'; - STR_RELEASE(basename); + zend_string_release(basename); /* Trim off trailing whitespace characters */ tmp_len--; diff --git a/ext/standard/head.c b/ext/standard/head.c index ad82b9fbbf..b53740563d 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -97,7 +97,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t encoded_value = php_url_encode(value, value_len); len += encoded_value->len; } else if (value) { - encoded_value = STR_INIT(value, value_len, 0); + encoded_value = zend_string_init(value, value_len, 0); len += encoded_value->len; } @@ -118,7 +118,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t */ dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1, 1, 0 TSRMLS_CC); snprintf(cookie, len + 100, "Set-Cookie: %s=deleted; expires=%s; Max-Age=0", name, dt->val); - STR_FREE(dt); + zend_string_free(dt); } else { snprintf(cookie, len + 100, "Set-Cookie: %s=%s", name, value ? encoded_value->val : ""); if (expires > 0) { @@ -129,14 +129,14 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t /* check to make sure that the year does not exceed 4 digits in length */ p = zend_memrchr(dt->val, '-', dt->len); if (!p || *(p + 5) != ' ') { - STR_FREE(dt); + zend_string_free(dt); efree(cookie); - STR_FREE(encoded_value); + zend_string_free(encoded_value); zend_error(E_WARNING, "Expiry date cannot have a year greater than 9999"); return FAILURE; } strlcat(cookie, dt->val, len + 100); - STR_FREE(dt); + zend_string_free(dt); snprintf(tsdelta, sizeof(tsdelta), "%li", (long) difftime(expires, time(NULL))); strlcat(cookie, COOKIE_MAX_AGE, len + 100); @@ -145,7 +145,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t } if (encoded_value) { - STR_FREE(encoded_value); + zend_string_free(encoded_value); } if (path && path_len > 0) { @@ -178,7 +178,7 @@ PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, t PHP_FUNCTION(setcookie) { char *name, *value = NULL, *path = NULL, *domain = NULL; - long expires = 0; + zend_long expires = 0; zend_bool secure = 0, httponly = 0; int name_len, value_len = 0, path_len = 0, domain_len = 0; @@ -201,7 +201,7 @@ PHP_FUNCTION(setcookie) PHP_FUNCTION(setrawcookie) { char *name, *value = NULL, *path = NULL, *domain = NULL; - long expires = 0; + zend_long expires = 0; zend_bool secure = 0, httponly = 0; int name_len, value_len = 0, path_len = 0, domain_len = 0; @@ -289,7 +289,7 @@ PHP_FUNCTION(headers_list) Sets a response code, or returns the current HTTP response code */ PHP_FUNCTION(http_response_code) { - long response_code = 0; + zend_long response_code = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &response_code) == FAILURE) { return; @@ -297,7 +297,7 @@ PHP_FUNCTION(http_response_code) if (response_code) { - long old_response_code; + zend_long old_response_code; old_response_code = SG(sapi_headers).http_response_code; SG(sapi_headers).http_response_code = response_code; diff --git a/ext/standard/html.c b/ext/standard/html.c index 360639ea76..a9e5fbfe9d 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -790,7 +790,7 @@ static inline int numeric_entity_is_allowed(unsigned uni_cp, int document_type) */ static inline int process_numeric_entity(const char **buf, unsigned *code_point) { - long code_l; + zend_long code_l; int hexadecimal = (**buf == 'x' || **buf == 'X'); /* TODO: XML apparently disallows "X" */ char *endptr; @@ -804,7 +804,7 @@ static inline int process_numeric_entity(const char **buf, unsigned *code_point) return FAILURE; } - code_l = strtol(*buf, &endptr, hexadecimal ? 16 : 10); + code_l = ZEND_STRTOL(*buf, &endptr, hexadecimal ? 16 : 10); /* we're guaranteed there were valid digits, so *endptr > buf */ *buf = endptr; @@ -813,7 +813,7 @@ static inline int process_numeric_entity(const char **buf, unsigned *code_point) /* many more are invalid, but that depends on whether it's HTML * (and which version) or XML. */ - if (code_l > 0x10FFFFL) + if (code_l > Z_I(0x10FFFF)) return FAILURE; if (code_point != NULL) @@ -856,7 +856,7 @@ static inline int process_named_entity_html(const char **buf, const char **start static inline int resolve_named_entity_html(const char *start, size_t length, const entity_ht *ht, unsigned *uni_cp1, unsigned *uni_cp2) { const entity_cp_map *s; - ulong hash = zend_inline_hash_func(start, length); + zend_ulong hash = zend_inline_hash_func(start, length); s = ht->buckets[hash % ht->num_elems]; while (s->entity) { @@ -1112,11 +1112,11 @@ PHPAPI zend_string *php_unescape_html_entities(unsigned char *old, size_t oldlen if (oldlen > new_size) { /* overflow, refuse to do anything */ - ret = STR_INIT((char*)old, oldlen, 0); + ret = zend_string_init((char*)old, oldlen, 0); retlen = oldlen; goto empty_source; } - ret = STR_ALLOC(new_size, 0); + ret = zend_string_alloc(new_size, 0); ret->val[0] = '\0'; ret->len = oldlen; retlen = oldlen; @@ -1275,7 +1275,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle } } - replaced = STR_ALLOC(maxlen, 0); + replaced = zend_string_alloc(maxlen, 0); len = 0; cursor = 0; while (cursor < oldlen) { @@ -1288,7 +1288,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle /* guarantee we have at least 40 bytes to write. * In HTML5, entities may take up to 33 bytes */ if (len > maxlen - 40) { /* maxlen can never be smaller than 128 */ - replaced = STR_SAFE_REALLOC(replaced, maxlen, 1, 128, 0); + replaced = zend_string_safe_realloc(replaced, maxlen, 1, 128, 0); maxlen += 128; } @@ -1301,7 +1301,7 @@ PHPAPI zend_string *php_escape_html_entities_ex(unsigned char *old, size_t oldle len += replacement_len; continue; } else { - STR_FREE(replaced); + zend_string_free(replaced); return STR_EMPTY_ALLOC(); } } else { /* SUCCESS */ @@ -1420,7 +1420,7 @@ encode_amp: /* at this point maxlen - len >= 40 */ if (maxlen - len < ent_len + 2 /* & and ; */) { /* ent_len < oldlen, which is certainly <= SIZE_MAX/2 */ - replaced = STR_SAFE_REALLOC(replaced, maxlen, 1, ent_len + 128, 0); + replaced = zend_string_safe_realloc(replaced, maxlen, 1, ent_len + 128, 0); maxlen += ent_len + 128; } replaced->val[len++] = '&'; @@ -1442,30 +1442,30 @@ encode_amp: */ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) { - char *str, *hint_charset = NULL; - int str_len, hint_charset_len = 0; - long flags = ENT_COMPAT; + zend_string *str, *hint_charset = NULL; + char *default_charset; + zend_long flags = ENT_COMPAT; zend_string *replaced; zend_bool double_encode = 1; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!b", &str, &str_len, &flags, &hint_charset, &hint_charset_len, &double_encode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|lS!b", &str, &flags, &hint_charset, &double_encode) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 4) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG(flags) - Z_PARAM_STRING_EX(hint_charset, hint_charset_len, 1, 0) + Z_PARAM_STR_EX(hint_charset, 1, 0) Z_PARAM_BOOL(double_encode); ZEND_PARSE_PARAMETERS_END(); #endif if (!hint_charset) { - hint_charset = get_default_charset(TSRMLS_C); + default_charset = get_default_charset(TSRMLS_C); } - replaced = php_escape_html_entities_ex((unsigned char*)str, str_len, all, (int) flags, hint_charset, double_encode TSRMLS_CC); + replaced = php_escape_html_entities_ex((unsigned char*)str->val, str->len, all, (int) flags, (hint_charset ? hint_charset->val : default_charset), double_encode TSRMLS_CC); RETVAL_STR(replaced); } /* }}} */ @@ -1506,7 +1506,7 @@ PHP_FUNCTION(htmlspecialchars_decode) { char *str; int str_len; - long quote_style = ENT_COMPAT; + zend_long quote_style = ENT_COMPAT; zend_string *replaced; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, "e_style) == FAILURE) { @@ -1525,30 +1525,30 @@ PHP_FUNCTION(htmlspecialchars_decode) Convert all HTML entities to their applicable characters */ PHP_FUNCTION(html_entity_decode) { - char *str, *hint_charset = NULL; - int str_len, hint_charset_len = 0; + zend_string *str, *hint_charset = NULL; + char *default_charset; size_t new_len = 0; - long quote_style = ENT_COMPAT; + zend_long quote_style = ENT_COMPAT; zend_string *replaced; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, - "e_style, &hint_charset, &hint_charset_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|lS", &str, + "e_style, &hint_charset) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 3) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_LONG(quote_style) - Z_PARAM_STRING(hint_charset, hint_charset_len) + Z_PARAM_STR(hint_charset) ZEND_PARSE_PARAMETERS_END(); #endif if (!hint_charset) { - hint_charset = get_default_charset(TSRMLS_C); + default_charset = get_default_charset(TSRMLS_C); } - replaced = php_unescape_html_entities((unsigned char*)str, str_len, 1 /*all*/, quote_style, hint_charset TSRMLS_CC); + replaced = php_unescape_html_entities((unsigned char*)str->val, str->len, 1 /*all*/, quote_style, (hint_charset ? hint_charset->val : default_charset) TSRMLS_CC); if (replaced) { RETURN_STR(replaced); @@ -1626,7 +1626,7 @@ static inline void write_s3row_data( Returns the internal translation table used by htmlspecialchars and htmlentities */ PHP_FUNCTION(get_html_translation_table) { - long all = HTML_SPECIALCHARS, + zend_long all = HTML_SPECIALCHARS, flags = ENT_COMPAT; int doctype; entity_table_opt entity_table; diff --git a/ext/standard/http.c b/ext/standard/http.c index 34b8e79389..609a6ffa65 100644 --- a/ext/standard/http.c +++ b/ext/standard/http.c @@ -35,7 +35,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, char *newprefix, *p; const char *prop_name; int arg_sep_len, newprefix_len, prop_len; - ulong idx; + zend_ulong idx; zval *zdata = NULL, copyzval; if (!ht) { @@ -95,7 +95,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, memcpy(p, ekey->val, ekey->len); p += ekey->len; - STR_FREE(ekey); + zend_string_free(ekey); if (key_suffix) { memcpy(p, key_suffix, key_suffix_len); @@ -109,7 +109,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, char *ekey; int ekey_len; /* Is an integer key */ - ekey_len = spprintf(&ekey, 0, "%ld", idx); + ekey_len = spprintf(&ekey, 0, "%pd", idx); newprefix_len = key_prefix_len + num_prefix_len + ekey_len + key_suffix_len + 3 /* %5B */; newprefix = emalloc(newprefix_len + 1); p = newprefix; @@ -160,7 +160,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, ekey = php_url_encode(prop_name, prop_len); } smart_str_appendl(formstr, ekey->val, ekey->len); - STR_FREE(ekey); + zend_string_free(ekey); } else { char *ekey; int ekey_len; @@ -168,7 +168,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, if (num_prefix) { smart_str_appendl(formstr, num_prefix, num_prefix_len); } - ekey_len = spprintf(&ekey, 0, "%ld", idx); + ekey_len = spprintf(&ekey, 0, "%pd", idx); smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } @@ -183,14 +183,14 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, ekey = php_url_encode(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); } smart_str_appendl(formstr, ekey->val, ekey->len); - STR_FREE(ekey); + zend_string_free(ekey); } break; case IS_LONG: { char *ekey; int ekey_len; - ekey_len = spprintf(&ekey, 0, "%ld", Z_LVAL_P(zdata)); + ekey_len = spprintf(&ekey, 0, "%pd", Z_LVAL_P(zdata)); smart_str_appendl(formstr, ekey, ekey_len); efree(ekey); } @@ -223,7 +223,7 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr, } smart_str_appendl(formstr, ekey->val, ekey->len); zval_ptr_dtor(©zval); - STR_FREE(ekey); + zend_string_free(ekey); } } } @@ -241,7 +241,7 @@ PHP_FUNCTION(http_build_query) char *prefix = NULL, *arg_sep=NULL; int arg_sep_len = 0, prefix_len = 0; smart_str formstr = {0}; - long enc_type = PHP_QUERY_RFC1738; + zend_long enc_type = PHP_QUERY_RFC1738; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ssl", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len, &enc_type) != SUCCESS) { RETURN_FALSE; diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 73952dda31..4bf86a4947 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -218,7 +218,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, if (errstr) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr->val); - STR_RELEASE(errstr); + zend_string_release(errstr); errstr = NULL; } @@ -537,7 +537,7 @@ finish: php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, NULL, 0); } - STR_FREE(stmp); + zend_string_free(stmp); } /* if the user has configured who they are, send a From: line */ @@ -749,7 +749,7 @@ finish: /* create filter to decode response body */ if (!(options & STREAM_ONLY_GET_HEADERS)) { - long decode = 1; + zend_long decode = 1; if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) { decode = zend_is_true(tmpzval TSRMLS_CC); diff --git a/ext/standard/image.c b/ext/standard/image.c index 0ec4cd3885..79e26c6310 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -237,7 +237,7 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) } while ((status==Z_BUF_ERROR)&&(factor<maxfactor)); if (bufz) { - STR_RELEASE(bufz); + zend_string_release(bufz); } if (status == Z_OK) { @@ -1160,7 +1160,7 @@ PHPAPI char * php_image_type_to_mime_type(int image_type) Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */ PHP_FUNCTION(image_type_to_mime_type) { - long p_image_type; + zend_long p_image_type; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &p_image_type) == FAILURE) { return; @@ -1174,7 +1174,7 @@ PHP_FUNCTION(image_type_to_mime_type) Get file extension for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */ PHP_FUNCTION(image_type_to_extension) { - long image_type; + zend_long image_type; zend_bool inc_dot=1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) { diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c index fb63703792..4a6a39d4ed 100644 --- a/ext/standard/incomplete_class.c +++ b/ext/standard/incomplete_class.c @@ -42,7 +42,7 @@ static void incomplete_class_message(zval *object, int error_type TSRMLS_DC) if (class_name) { php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, class_name->val); - STR_RELEASE(class_name); + zend_string_release(class_name); } else { php_error_docref(NULL TSRMLS_CC, error_type, INCOMPLETE_CLASS_MSG, "unknown"); } @@ -141,7 +141,7 @@ PHPAPI zend_string *php_lookup_class_name(zval *object) object_properties = Z_OBJPROP_P(object); if ((val = zend_hash_str_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)-1)) != NULL) { - return STR_COPY(Z_STR_P(val)); + return zend_string_copy(Z_STR_P(val)); } return NULL; @@ -150,7 +150,7 @@ PHPAPI zend_string *php_lookup_class_name(zval *object) /* {{{ php_store_class_name */ -PHPAPI void php_store_class_name(zval *object, const char *name, zend_uint len) +PHPAPI void php_store_class_name(zval *object, const char *name, uint32_t len) { zval val; TSRMLS_FETCH(); diff --git a/ext/standard/info.c b/ext/standard/info.c index 47249466b0..d0d1d114e6 100644 --- a/ext/standard/info.c +++ b/ext/standard/info.c @@ -69,7 +69,7 @@ static int php_info_print_html_esc(const char *str, int len) /* {{{ */ new_str = php_escape_html_entities((unsigned char *) str, len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC); written = php_output_write(new_str->val, new_str->len TSRMLS_CC); - STR_FREE(new_str); + zend_string_free(new_str); return written; } /* }}} */ @@ -196,10 +196,10 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) { zval *data, *tmp, tmp2; zend_string *string_key; - ulong num_key; + zend_ulong num_key; zend_string *key; - key = STR_INIT(name, name_length, 0); + key = zend_string_init(name, name_length, 0); zend_is_auto_global(key TSRMLS_CC); if ((data = zend_hash_find(&EG(symbol_table).ht, key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) { @@ -219,7 +219,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) php_info_print(string_key->val); } } else { - php_info_printf("%ld", num_key); + php_info_printf("%pd", num_key); } php_info_print("\"]"); if (!sapi_module.phpinfo_as_text) { @@ -264,7 +264,7 @@ static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) } } ZEND_HASH_FOREACH_END(); } - STR_FREE(key); + zend_string_free(key); } /* }}} */ @@ -655,7 +655,7 @@ PHPAPI zend_string *php_get_uname(char mode) php_uname = PHP_UNAME; #endif #endif - return STR_INIT(php_uname, strlen(php_uname), 0); + return zend_string_init(php_uname, strlen(php_uname), 0); } /* }}} */ @@ -833,7 +833,7 @@ PHPAPI void php_print_info(int flag TSRMLS_DC) zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC); } php_info_print_box_end(); - STR_FREE(php_uname); + zend_string_free(php_uname); } zend_ini_sort_entries(TSRMLS_C); @@ -1166,7 +1166,7 @@ void register_phpinfo_constants(INIT_FUNC_ARGS) Output a page of useful information about PHP and the current request */ PHP_FUNCTION(phpinfo) { - long flag = PHP_INFO_ALL; + zend_long flag = PHP_INFO_ALL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) { return; @@ -1210,7 +1210,7 @@ PHP_FUNCTION(phpversion) Prints the list of people who've contributed to the PHP project */ PHP_FUNCTION(phpcredits) { - long flag = PHP_CREDITS_ALL; + zend_long flag = PHP_CREDITS_ALL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) { return; diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index cea43dd8d3..daf667df87 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -179,7 +179,7 @@ PHP_FUNCTION(iptcembed) { char *iptcdata, *jpeg_file; int iptcdata_len, jpeg_file_len; - long spool = 0; + zend_long spool = 0; FILE *fp; unsigned int marker, done = 0; int inx; @@ -334,8 +334,8 @@ PHP_FUNCTION(iptcparse) if((inx+6) >= str_len) { break; } - len = (((long) buffer[ inx + 2 ]) << 24) + (((long) buffer[ inx + 3 ]) << 16) + - (((long) buffer[ inx + 4 ]) << 8) + (((long) buffer[ inx + 5 ])); + len = (((zend_long) buffer[ inx + 2 ]) << 24) + (((zend_long) buffer[ inx + 3 ]) << 16) + + (((zend_long) buffer[ inx + 4 ]) << 8) + (((zend_long) buffer[ inx + 5 ])); inx += 6; } else { /* short tag */ len = (((unsigned short) buffer[ inx ])<<8) | (unsigned short)buffer[ inx+1 ]; diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c index 786ca052d7..03e7e0075d 100644 --- a/ext/standard/levenshtein.c +++ b/ext/standard/levenshtein.c @@ -95,7 +95,7 @@ PHP_FUNCTION(levenshtein) char *str1, *str2; char *callback_name; int str1_len, str2_len, callback_len; - long cost_ins, cost_rep, cost_del; + zend_long cost_ins, cost_rep, cost_del; int distance = -1; switch (argc) { diff --git a/ext/standard/link_win32.c b/ext/standard/link_win32.c index 41ce9d20df..07466d2966 100644 --- a/ext/standard/link_win32.c +++ b/ext/standard/link_win32.c @@ -88,7 +88,7 @@ PHP_FUNCTION(linkinfo) { char *link; int link_len; - struct stat sb; + zend_stat_t sb; int ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &link, &link_len) == FAILURE) { diff --git a/ext/standard/mail.c b/ext/standard/mail.c index 815f83118f..e45f9f7c90 100644 --- a/ext/standard/mail.c +++ b/ext/standard/mail.c @@ -72,7 +72,7 @@ *p = ' '; \ } \ -extern long php_getuid(TSRMLS_D); +extern zend_long php_getuid(TSRMLS_D); /* {{{ proto int ezmlm_hash(string addr) Calculate EZMLM list hash value. */ @@ -182,7 +182,7 @@ PHP_FUNCTION(mail) } if (extra_cmd) { - STR_RELEASE(extra_cmd); + zend_string_release(extra_cmd); } if (to_r != to) { efree(to_r); @@ -259,7 +259,7 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s\n", date_str->val, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : ""); - STR_FREE(date_str); + zend_string_free(date_str); if (hdr) { php_mail_log_crlf_to_spaces(tmp); @@ -285,11 +285,11 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char f = php_basename(tmp, strlen(tmp), NULL, 0 TSRMLS_CC); if (headers != NULL) { - spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s\n%s", php_getuid(TSRMLS_C), f->val, headers); + spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s\n%s", php_getuid(TSRMLS_C), f->val, headers); } else { - spprintf(&hdr, 0, "X-PHP-Originating-Script: %ld:%s", php_getuid(TSRMLS_C), f->val); + spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s", php_getuid(TSRMLS_C), f->val); } - STR_RELEASE(f); + zend_string_release(f); } if (!sendmail_path) { diff --git a/ext/standard/math.c b/ext/standard/math.c index a392eb607c..8a99faa665 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -286,8 +286,8 @@ PHP_FUNCTION(abs) if (Z_TYPE_P(value) == IS_DOUBLE) { RETURN_DOUBLE(fabs(Z_DVAL_P(value))); } else if (Z_TYPE_P(value) == IS_LONG) { - if (Z_LVAL_P(value) == LONG_MIN) { - RETURN_DOUBLE(-(double)LONG_MIN); + if (Z_LVAL_P(value) == ZEND_LONG_MIN) { + RETURN_DOUBLE(-(double)ZEND_LONG_MIN); } else { RETURN_LONG(Z_LVAL_P(value) < 0 ? -Z_LVAL_P(value) : Z_LVAL_P(value)); } @@ -342,8 +342,8 @@ PHP_FUNCTION(round) { zval *value; int places = 0; - long precision = 0; - long mode = PHP_ROUND_HALF_UP; + zend_long precision = 0; + zend_long mode = PHP_ROUND_HALF_UP; double return_val; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &value, &precision, &mode) == FAILURE) { @@ -926,9 +926,9 @@ PHP_FUNCTION(rad2deg) /* * Convert a string representation of a base(2-36) number to a long. */ -PHPAPI long _php_math_basetolong(zval *arg, int base) +PHPAPI zend_long _php_math_basetolong(zval *arg, int base) { - long num = 0, digit, onum; + zend_long num = 0, digit, onum; int i; char c, *s; @@ -959,7 +959,7 @@ PHPAPI long _php_math_basetolong(zval *arg, int base) TSRMLS_FETCH(); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number '%s' is too big to fit in long", s); - return LONG_MAX; + return ZEND_LONG_MAX; } } @@ -973,12 +973,12 @@ PHPAPI long _php_math_basetolong(zval *arg, int base) */ PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret) { - long num = 0; + zend_long num = 0; double fnum = 0; int i; int mode = 0; char c, *s; - long cutoff; + zend_long cutoff; int cutlim; if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) { @@ -987,8 +987,8 @@ PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret) s = Z_STRVAL_P(arg); - cutoff = LONG_MAX / base; - cutlim = LONG_MAX % base; + cutoff = ZEND_LONG_MAX / base; + cutlim = ZEND_LONG_MAX % base; for (i = Z_STRLEN_P(arg); i > 0; i--) { c = *s++; @@ -1038,9 +1038,9 @@ PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret) PHPAPI zend_string * _php_math_longtobase(zval *arg, int base TSRMLS_DC) { static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - char buf[(sizeof(unsigned long) << 3) + 1]; + char buf[(sizeof(zend_ulong) << 3) + 1]; char *ptr, *end; - unsigned long value; + zend_ulong value; if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) { return STR_EMPTY_ALLOC(); @@ -1056,7 +1056,7 @@ PHPAPI zend_string * _php_math_longtobase(zval *arg, int base TSRMLS_DC) value /= base; } while (ptr > buf && value); - return STR_INIT(ptr, end - ptr, 0); + return zend_string_init(ptr, end - ptr, 0); } /* }}} */ @@ -1092,7 +1092,7 @@ PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base TSRMLS_DC) fvalue /= base; } while (ptr > buf && fabs(fvalue) >= 1); - return STR_INIT(ptr, end - ptr, 0); + return zend_string_init(ptr, end - ptr, 0); } return _php_math_longtobase(arg, base TSRMLS_CC); @@ -1157,7 +1157,7 @@ PHP_FUNCTION(decbin) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { return; } - convert_to_long_ex(arg); + convert_to_int_ex(arg); result = _php_math_longtobase(arg, 2 TSRMLS_CC); RETURN_STR(result); } @@ -1173,7 +1173,7 @@ PHP_FUNCTION(decoct) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { return; } - convert_to_long_ex(arg); + convert_to_int_ex(arg); result = _php_math_longtobase(arg, 8 TSRMLS_CC); RETURN_STR(result); } @@ -1189,7 +1189,7 @@ PHP_FUNCTION(dechex) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { return; } - convert_to_long_ex(arg); + convert_to_int_ex(arg); result = _php_math_longtobase(arg, 16 TSRMLS_CC); RETURN_STR(result); } @@ -1200,7 +1200,7 @@ PHP_FUNCTION(dechex) PHP_FUNCTION(base_convert) { zval *number, temp; - long frombase, tobase; + zend_long frombase, tobase; zend_string *result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &number, &frombase, &tobase) == FAILURE) { @@ -1209,11 +1209,11 @@ PHP_FUNCTION(base_convert) convert_to_string_ex(number); if (frombase < 2 || frombase > 36) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `from base' (%ld)", frombase); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `from base' (%pd)", frombase); RETURN_FALSE; } if (tobase < 2 || tobase > 36) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `to base' (%ld)", tobase); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `to base' (%pd)", tobase); RETURN_FALSE; } @@ -1292,7 +1292,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin if (is_negative) { reslen++; } - res = STR_ALLOC(reslen, 0); + res = zend_string_alloc(reslen, 0); s = tmpbuf->val + tmpbuf->len - 1; t = res->val + reslen; @@ -1341,7 +1341,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin } res->len = reslen; - STR_RELEASE(tmpbuf); + zend_string_release(tmpbuf); return res; } @@ -1350,7 +1350,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin PHP_FUNCTION(number_format) { double num; - long dec = 0; + zend_long dec = 0; char *thousand_sep = NULL, *dec_point = NULL; char thousand_sep_chr = ',', dec_point_chr = '.'; int thousand_sep_len = 0, dec_point_len = 0; @@ -1422,7 +1422,7 @@ PHP_FUNCTION(fmod) Returns the integer division of the numerator by the divisor */ PHP_FUNCTION(intdiv) { - long numerator, divisor; + zend_long numerator, divisor; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &numerator, &divisor) == FAILURE) { return; @@ -1431,7 +1431,7 @@ PHP_FUNCTION(intdiv) if (divisor == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero"); RETURN_BOOL(0); - } else if (divisor == -1 && numerator == LONG_MIN) { + } else if (divisor == -1 && numerator == ZEND_LONG_MIN) { /* Prevent overflow error/crash We don't return a float here as that violates function contract */ RETURN_LONG(0); diff --git a/ext/standard/md5.c b/ext/standard/md5.c index d2545e913a..68161da326 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -46,20 +46,19 @@ PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) / Calculate the md5 hash of a string */ PHP_NAMED_FUNCTION(php_if_md5) { - char *arg; - int arg_len; + zend_string *arg; zend_bool raw_output = 0; char md5str[33]; PHP_MD5_CTX context; unsigned char digest[16]; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &raw_output) == FAILURE) { return; } md5str[0] = '\0'; PHP_MD5Init(&context); - PHP_MD5Update(&context, arg, arg_len); + PHP_MD5Update(&context, arg->val, arg->len); PHP_MD5Final(digest, &context); if (raw_output) { RETURN_STRINGL(digest, 16); @@ -82,7 +81,7 @@ PHP_NAMED_FUNCTION(php_if_md5_file) unsigned char buf[1024]; unsigned char digest[16]; PHP_MD5_CTX context; - int n; + size_t n; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|b", &arg, &arg_len, &raw_output) == FAILURE) { diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c index 9d22868b8c..f2feb72ebf 100644 --- a/ext/standard/metaphone.c +++ b/ext/standard/metaphone.c @@ -25,27 +25,25 @@ #include "php.h" #include "php_metaphone.h" -static int metaphone(unsigned char *word, int word_len, long max_phonemes, zend_string **phoned_word, int traditional); +static int metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional); /* {{{ proto string metaphone(string text[, int phones]) Break english phrases down into their phonemes */ PHP_FUNCTION(metaphone) { - char *str; + zend_string *str; zend_string *result = NULL; - int str_len; - long phones = 0; + zend_long phones = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, - &phones) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &str, &phones) == FAILURE) { return; } - if (metaphone((unsigned char *)str, str_len, phones, &result, 1) == 0) { + if (metaphone((unsigned char *)str->val, str->len, phones, &result, 1) == 0) { RETVAL_STR(result); } else { if (result) { - STR_FREE(result); + zend_string_free(result); } RETURN_FALSE; } @@ -144,7 +142,7 @@ static char Lookahead(char *word, int how_far) * could be one though; or more too). */ #define Phonize(c) { \ if (p_idx >= max_buffer_len) { \ - *phoned_word = STR_REALLOC(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \ + *phoned_word = zend_string_realloc(*phoned_word, 2 * sizeof(char) + max_buffer_len, 0); \ max_buffer_len += 2; \ } \ (*phoned_word)->val[p_idx++] = c; \ @@ -153,7 +151,7 @@ static char Lookahead(char *word, int how_far) /* Slap a null character on the end of the phoned word */ #define End_Phoned_Word { \ if (p_idx == max_buffer_len) { \ - *phoned_word = STR_REALLOC(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \ + *phoned_word = zend_string_realloc(*phoned_word, 1 * sizeof(char) + max_buffer_len, 0); \ max_buffer_len += 1; \ } \ (*phoned_word)->val[p_idx] = '\0'; \ @@ -167,11 +165,11 @@ static char Lookahead(char *word, int how_far) /* {{{ metaphone */ -static int metaphone(unsigned char *word, int word_len, long max_phonemes, zend_string **phoned_word, int traditional) +static int metaphone(unsigned char *word, size_t word_len, zend_long max_phonemes, zend_string **phoned_word, int traditional) { int w_idx = 0; /* point in the phonization we're at. */ int p_idx = 0; /* end of the phoned phrase */ - int max_buffer_len = 0; /* maximum length of the destination buffer */ + size_t max_buffer_len = 0; /* maximum length of the destination buffer */ /*-- Parameter checks --*/ /* Negative phoneme length is meaningless */ @@ -189,10 +187,10 @@ static int metaphone(unsigned char *word, int word_len, long max_phonemes, zend_ /*-- Allocate memory for our phoned_phrase --*/ if (max_phonemes == 0) { /* Assume largest possible */ max_buffer_len = word_len; - *phoned_word = STR_ALLOC(sizeof(char) * word_len + 1, 0); + *phoned_word = zend_string_alloc(sizeof(char) * word_len + 1, 0); } else { max_buffer_len = max_phonemes; - *phoned_word = STR_ALLOC(sizeof(char) * max_phonemes + 1, 0); + *phoned_word = zend_string_alloc(sizeof(char) * max_phonemes + 1, 0); } diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c index f8e19c74ca..e20223b011 100644 --- a/ext/standard/microtime.c +++ b/ext/standard/microtime.c @@ -111,7 +111,7 @@ PHP_FUNCTION(gettimeofday) PHP_FUNCTION(getrusage) { struct rusage usg; - long pwho = 0; + zend_long pwho = 0; int who = RUSAGE_SELF; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &pwho) == FAILURE) { diff --git a/ext/standard/pack.c b/ext/standard/pack.c index c77a1a40c6..59f878e217 100644 --- a/ext/standard/pack.c +++ b/ext/standard/pack.c @@ -84,12 +84,12 @@ static int little_endian_long_map[4]; /* {{{ php_pack */ -static void php_pack(zval *val, int size, int *map, char *output) +static void php_pack(zval *val, size_t size, int *map, char *output) { int i; char *v; - convert_to_long_ex(val); + convert_to_int_ex(val); v = (char *) &Z_LVAL_P(val); for (i = 0; i < size; i++) { @@ -329,7 +329,7 @@ PHP_FUNCTION(pack) (str->len < arg_cp) ? str->len : arg_cp); outputpos += arg; - STR_RELEASE(str); + zend_string_release(str); break; } @@ -372,7 +372,7 @@ PHP_FUNCTION(pack) } outputpos++; - STR_RELEASE(str); + zend_string_release(str); break; } @@ -480,9 +480,9 @@ PHP_FUNCTION(pack) /* {{{ php_unpack */ -static long php_unpack(char *data, int size, int issigned, int *map) +static zend_long php_unpack(char *data, size_t size, int issigned, int *map) { - long result; + zend_long result; char *cresult = (char *) &result; int i; @@ -512,19 +512,20 @@ static long php_unpack(char *data, int size, int issigned, int *map) Unpack binary string into named array elements according to format argument */ PHP_FUNCTION(unpack) { - char *format, *input, *formatarg, *inputarg; - int formatlen, formatarg_len, inputarg_len; - int inputpos, inputlen, i; + char *format, *input; + zend_string *formatarg, *inputarg; + size_t formatlen, inputpos, inputlen; + int i; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &formatarg, &formatarg_len, - &inputarg, &inputarg_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &formatarg, + &inputarg) == FAILURE) { return; } - format = formatarg; - formatlen = formatarg_len; - input = inputarg; - inputlen = inputarg_len; + format = formatarg->val; + formatlen = formatarg->len; + input = inputarg->val; + inputlen = inputarg->len; inputpos = 0; array_init(return_value); @@ -656,11 +657,11 @@ PHP_FUNCTION(unpack) inputpos = 0; } - if ((inputpos + size) <= inputlen) { + if ((size >=0 && (inputpos + size) <= inputlen) || (size < 0 && -size <= (inputlen - inputpos))) { switch ((int) type) { case 'a': { /* a will not strip any trailing whitespace or null padding */ - int len = inputlen - inputpos; /* Remaining string */ + size_t len = inputlen - inputpos; /* Remaining string */ /* If size was given take minimum of len and size */ if ((size >= 0) && (len > size)) { @@ -675,7 +676,7 @@ PHP_FUNCTION(unpack) case 'A': { /* A will strip any trailing whitespace */ char padn = '\0'; char pads = ' '; char padt = '\t'; char padc = '\r'; char padl = '\n'; - int len = inputlen - inputpos; /* Remaining string */ + size_t len = inputlen - inputpos; /* Remaining string */ /* If size was given take minimum of len and size */ if ((size >= 0) && (len > size)) { @@ -702,7 +703,7 @@ PHP_FUNCTION(unpack) case 'Z': { /* Z will strip everything after the first null character */ char pad = '\0'; - int s, + size_t s, len = inputlen - inputpos; /* Remaining string */ /* If size was given take minimum of len and size */ @@ -726,11 +727,11 @@ PHP_FUNCTION(unpack) case 'h': case 'H': { - int len = (inputlen - inputpos) * 2; /* Remaining */ + size_t len = (inputlen - inputpos) * 2; /* Remaining */ int nibbleshift = (type == 'h') ? 0 : 4; int first = 1; char *buf; - int ipos, opos; + size_t ipos, opos; /* If size was given take minimum of len and size */ if (size >= 0 && len > (size * 2)) { @@ -770,7 +771,7 @@ PHP_FUNCTION(unpack) case 'c': case 'C': { int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0; - long v = php_unpack(&input[inputpos], 1, issigned, byte_map); + zend_long v = php_unpack(&input[inputpos], 1, issigned, byte_map); add_assoc_long(return_value, n, v); break; } @@ -779,7 +780,7 @@ PHP_FUNCTION(unpack) case 'S': case 'n': case 'v': { - long v; + zend_long v; int issigned = 0; int *map = machine_endian_short_map; @@ -798,7 +799,7 @@ PHP_FUNCTION(unpack) case 'i': case 'I': { - long v; + zend_long v; int issigned = 0; if (type == 'i') { @@ -816,7 +817,7 @@ PHP_FUNCTION(unpack) case 'V': { int issigned = 0; int *map = machine_endian_long_map; - long v = 0; + zend_long v = 0; if (type == 'l' || type == 'L') { issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80; @@ -828,12 +829,12 @@ PHP_FUNCTION(unpack) map = little_endian_long_map; } - if (sizeof(long) > 4 && issigned) { + if (SIZEOF_ZEND_INT > 4 && issigned) { v = ~INT_MAX; } v |= php_unpack(&input[inputpos], 4, issigned, map); - if (sizeof(long) > 4) { + if (SIZEOF_ZEND_INT > 4) { if (type == 'l') { v = (signed int) v; } else { @@ -903,8 +904,10 @@ PHP_FUNCTION(unpack) } } - formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */ - format++; + if (formatlen > 0) { + formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */ + format++; + } } } /* }}} */ diff --git a/ext/standard/pageinfo.c b/ext/standard/pageinfo.c index a9a4e58de0..61a4ae6ec2 100644 --- a/ext/standard/pageinfo.c +++ b/ext/standard/pageinfo.c @@ -59,7 +59,7 @@ */ PHPAPI void php_statpage(TSRMLS_D) { - struct stat *pstat; + zend_stat_t *pstat; pstat = sapi_get_stat(TSRMLS_C); @@ -79,14 +79,14 @@ PHPAPI void php_statpage(TSRMLS_D) /* {{{ php_getuid */ -long php_getuid(TSRMLS_D) +zend_long php_getuid(TSRMLS_D) { php_statpage(TSRMLS_C); return (BG(page_uid)); } /* }}} */ -long php_getgid(TSRMLS_D) +zend_long php_getgid(TSRMLS_D) { php_statpage(TSRMLS_C); return (BG(page_gid)); @@ -96,7 +96,7 @@ long php_getgid(TSRMLS_D) Get PHP script owner's UID */ PHP_FUNCTION(getmyuid) { - long uid; + zend_long uid; if (zend_parse_parameters_none() == FAILURE) { return; @@ -115,7 +115,7 @@ PHP_FUNCTION(getmyuid) Get PHP script owner's GID */ PHP_FUNCTION(getmygid) { - long gid; + zend_long gid; if (zend_parse_parameters_none() == FAILURE) { return; @@ -134,7 +134,7 @@ PHP_FUNCTION(getmygid) Get current process ID */ PHP_FUNCTION(getmypid) { - int pid; + zend_long pid; if (zend_parse_parameters_none() == FAILURE) { return; @@ -144,7 +144,7 @@ PHP_FUNCTION(getmypid) if (pid < 0) { RETURN_FALSE; } else { - RETURN_LONG((long) pid); + RETURN_LONG(pid); } } /* }}} */ @@ -166,7 +166,7 @@ PHP_FUNCTION(getmyinode) } /* }}} */ -PHPAPI long php_getlastmod(TSRMLS_D) +PHPAPI time_t php_getlastmod(TSRMLS_D) { php_statpage(TSRMLS_C); return BG(page_mtime); @@ -176,7 +176,7 @@ PHPAPI long php_getlastmod(TSRMLS_D) Get time of last page modification */ PHP_FUNCTION(getlastmod) { - long lm; + zend_long lm; if (zend_parse_parameters_none() == FAILURE) { return; diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h index c3c1846058..204fb85c19 100644 --- a/ext/standard/pageinfo.h +++ b/ext/standard/pageinfo.h @@ -28,8 +28,8 @@ PHP_FUNCTION(getmyinode); PHP_FUNCTION(getlastmod); PHPAPI void php_statpage(TSRMLS_D); -PHPAPI long php_getlastmod(TSRMLS_D); -extern long php_getuid(TSRMLS_D); -extern long php_getgid(TSRMLS_D); +PHPAPI time_t php_getlastmod(TSRMLS_D); +extern zend_long php_getuid(TSRMLS_D); +extern zend_long php_getgid(TSRMLS_D); #endif diff --git a/ext/standard/password.c b/ext/standard/password.c index aa50ab1f00..73d468d126 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -89,20 +89,20 @@ static int php_password_salt_to64(const char *str, const size_t str_len, const s buffer = php_base64_encode((unsigned char*) str, (int) str_len); if (buffer->len < out_len) { /* Too short of an encoded string generated */ - STR_RELEASE(buffer); + zend_string_release(buffer); return FAILURE; } for (pos = 0; pos < out_len; pos++) { if (buffer->val[pos] == '+') { ret[pos] = '.'; } else if (buffer->val[pos] == '=') { - STR_FREE(buffer); + zend_string_free(buffer); return FAILURE; } else { ret[pos] = buffer->val[pos]; } } - STR_FREE(buffer); + zend_string_free(buffer); return SUCCESS; } /* }}} */ @@ -195,8 +195,8 @@ PHP_FUNCTION(password_get_info) switch (algo) { case PHP_PASSWORD_BCRYPT: { - long cost = PHP_PASSWORD_BCRYPT_COST; - sscanf(hash, "$2y$%ld$", &cost); + zend_long cost = PHP_PASSWORD_BCRYPT_COST; + sscanf(hash, "$2y$" ZEND_LONG_FMT "$", &cost); add_assoc_long(&options, "cost", cost); } break; @@ -214,7 +214,7 @@ PHP_FUNCTION(password_get_info) PHP_FUNCTION(password_needs_rehash) { - long new_algo = 0; + zend_long new_algo = 0; php_password_algo algo; int hash_len; char *hash; @@ -239,13 +239,13 @@ PHP_FUNCTION(password_needs_rehash) switch (algo) { case PHP_PASSWORD_BCRYPT: { - long new_cost = PHP_PASSWORD_BCRYPT_COST, cost = 0; + zend_long new_cost = PHP_PASSWORD_BCRYPT_COST, cost = 0; if (options && (option_buffer = zend_symtable_str_find(options, "cost", sizeof("cost")-1)) != NULL) { if (Z_TYPE_P(option_buffer) != IS_LONG) { zval cast_option_buffer; ZVAL_DUP(&cast_option_buffer, option_buffer); - convert_to_long(&cast_option_buffer); + convert_to_int(&cast_option_buffer); new_cost = Z_LVAL(cast_option_buffer); zval_dtor(&cast_option_buffer); } else { @@ -253,7 +253,7 @@ PHP_FUNCTION(password_needs_rehash) } } - sscanf(hash, "$2y$%ld$", &cost); + sscanf(hash, "$2y$" ZEND_LONG_FMT "$", &cost); if (cost != new_cost) { RETURN_TRUE; } @@ -283,7 +283,7 @@ PHP_FUNCTION(password_verify) } if (ret->len != hash_len || hash_len < 13) { - STR_FREE(ret); + zend_string_free(ret); RETURN_FALSE; } @@ -295,7 +295,7 @@ PHP_FUNCTION(password_verify) status |= (ret->val[i] ^ hash[i]); } - STR_FREE(ret); + zend_string_free(ret); RETURN_BOOL(status == 0); @@ -307,7 +307,7 @@ Hash a password */ PHP_FUNCTION(password_hash) { char *hash_format, *hash, *salt, *password; - long algo = 0; + zend_long algo = 0; int password_len = 0, hash_len; size_t salt_len = 0, required_salt_len = 0, hash_format_len; HashTable *options = 0; @@ -321,13 +321,13 @@ PHP_FUNCTION(password_hash) switch (algo) { case PHP_PASSWORD_BCRYPT: { - long cost = PHP_PASSWORD_BCRYPT_COST; + zend_long cost = PHP_PASSWORD_BCRYPT_COST; if (options && (option_buffer = zend_symtable_str_find(options, "cost", sizeof("cost")-1)) != NULL) { if (Z_TYPE_P(option_buffer) != IS_LONG) { zval cast_option_buffer; ZVAL_DUP(&cast_option_buffer, option_buffer); - convert_to_long(&cast_option_buffer); + convert_to_int(&cast_option_buffer); cost = Z_LVAL(cast_option_buffer); zval_dtor(&cast_option_buffer); } else { @@ -336,7 +336,7 @@ PHP_FUNCTION(password_hash) } if (cost < 4 || cost > 31) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid bcrypt cost parameter specified: %ld", cost); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid bcrypt cost parameter specified: " ZEND_LONG_FMT, cost); RETURN_NULL(); } @@ -348,7 +348,7 @@ PHP_FUNCTION(password_hash) break; case PHP_PASSWORD_UNKNOWN: default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown password hashing algorithm: %ld", algo); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown password hashing algorithm: " ZEND_LONG_FMT, algo); RETURN_NULL(); } @@ -443,7 +443,7 @@ PHP_FUNCTION(password_hash) efree(hash); if (result->len < 13) { - STR_FREE(result); + zend_string_free(result); RETURN_FALSE; } diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h index d123ddfe41..c001ee5509 100644 --- a/ext/standard/php_array.h +++ b/ext/standard/php_array.h @@ -107,7 +107,7 @@ PHPAPI HashTable* php_splice(HashTable *, int, int, zval *, int, HashTable *); PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC); PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC); PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC); -PHPAPI int php_count_recursive(zval *array, long mode TSRMLS_DC); +PHPAPI zend_long php_count_recursive(zval *array, zend_long mode TSRMLS_DC); #define PHP_SORT_REGULAR 0 #define PHP_SORT_NUMERIC 1 diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 9628c0d69d..3859e5b9a4 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -65,7 +65,7 @@ php_stream_ops php_stream_output_ops = { typedef struct php_stream_input { /* {{{ */ php_stream *body; - off_t position; + zend_off_t position; } php_stream_input_t; /* }}} */ @@ -118,7 +118,7 @@ static int php_stream_input_flush(php_stream *stream TSRMLS_DC) /* {{{ */ } /* }}} */ -static int php_stream_input_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */ +static int php_stream_input_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset TSRMLS_DC) /* {{{ */ { php_stream_input_t *input = stream->abstract; @@ -178,7 +178,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa int mode_rw = 0; php_stream * stream = NULL; char *p, *token, *pathdup; - long max_memory; + zend_long max_memory; FILE *file = NULL; if (!strncasecmp(path, "php://", 6)) { @@ -190,7 +190,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa max_memory = PHP_STREAM_MAX_MEM; if (!strncasecmp(path, "/maxmemory:", 11)) { path += 11; - max_memory = strtol(path, NULL, 10); + max_memory = ZEND_STRTOL(path, NULL, 10); if (max_memory < 0) { php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Max memory must be >= 0"); return NULL; @@ -286,7 +286,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa } else if (!strncasecmp(path, "fd/", 3)) { const char *start; char *end; - long fildes_ori; + zend_long fildes_ori; int dtablesize; if (strcmp(sapi_module.name, "cli")) { @@ -304,7 +304,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa } start = &path[3]; - fildes_ori = strtol(start, &end, 10); + fildes_ori = ZEND_STRTOL(start, &end, 10); if (end == start || *end != '\0') { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "php://fd/ stream must be specified in the form php://fd/<orig fd>"); @@ -326,7 +326,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa fd = dup(fildes_ori); if (fd == -1) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, - "Error duping file descriptor %ld; possibly it doesn't exist: " + "Error duping file descriptor " ZEND_LONG_FMT "; possibly it doesn't exist: " "[%d]: %s", fildes_ori, errno, strerror(errno)); return NULL; } @@ -380,9 +380,9 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, const char *pa #if defined(S_IFSOCK) && !defined(WIN32) && !defined(__BEOS__) do { - struct stat st; + zend_stat_t st; memset(&st, 0, sizeof(st)); - if (fstat(fd, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { + if (zend_fstat(fd, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { stream = php_stream_sock_open_from_socket(fd, NULL); if (stream) { stream->ops = &php_stream_socket_ops; diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h index 804ca05206..efca24acce 100644 --- a/ext/standard/php_incomplete_class.h +++ b/ext/standard/php_incomplete_class.h @@ -32,7 +32,7 @@ Z_OBJCE_P(struc) == BG(incomplete_class)) { \ class_name = php_lookup_class_name(struc); \ if (!class_name) { \ - class_name = STR_INIT(INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS) - 1, 0); \ + class_name = zend_string_init(INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS) - 1, 0); \ } \ incomplete_class = 1; \ } else { \ @@ -40,7 +40,7 @@ } #define PHP_CLEANUP_CLASS_ATTRIBUTES() \ - STR_RELEASE(class_name) + zend_string_release(class_name) #define PHP_CLASS_ATTRIBUTES \ zend_string *class_name; \ @@ -55,7 +55,7 @@ extern "C" { PHPAPI zend_class_entry *php_create_incomplete_class(TSRMLS_D); PHPAPI zend_string *php_lookup_class_name(zval *object); -PHPAPI void php_store_class_name(zval *object, const char *name, zend_uint len); +PHPAPI void php_store_class_name(zval *object, const char *name, uint32_t len); #ifdef __cplusplus }; diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h index a2dca282c5..afdf54166f 100644 --- a/ext/standard/php_math.h +++ b/ext/standard/php_math.h @@ -25,7 +25,7 @@ PHPAPI zend_string *_php_math_number_format(double, int, char, char); PHPAPI zend_string *_php_math_number_format_ex(double, int, char *, size_t, char *, size_t); PHPAPI zend_string * _php_math_longtobase(zval *arg, int base TSRMLS_DC); -PHPAPI long _php_math_basetolong(zval *arg, int base); +PHPAPI zend_long _php_math_basetolong(zval *arg, int base); PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret); PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base TSRMLS_DC); diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h index 0e8abb3613..6ec0f38706 100644 --- a/ext/standard/php_rand.h +++ b/ext/standard/php_rand.h @@ -42,19 +42,19 @@ #endif #define RAND_RANGE(__n, __min, __max, __tmax) \ - (__n) = (__min) + (long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))) + (__n) = (__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))) /* MT Rand */ -#define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */ +#define PHP_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */ #ifdef PHP_WIN32 -#define GENERATE_SEED() (((long) (time(0) * GetCurrentProcessId())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) +#define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ ((zend_long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) #else -#define GENERATE_SEED() (((long) (time(0) * getpid())) ^ ((long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) +#define GENERATE_SEED() (((zend_long) (time(0) * getpid())) ^ ((zend_long) (1000000.0 * php_combined_lcg(TSRMLS_C)))) #endif -PHPAPI void php_srand(long seed TSRMLS_DC); -PHPAPI long php_rand(TSRMLS_D); +PHPAPI void php_srand(zend_long seed TSRMLS_DC); +PHPAPI zend_long php_rand(TSRMLS_D); PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC); PHPAPI php_uint32 php_mt_rand(TSRMLS_D); diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h index 71bcf0b223..c153fa884c 100644 --- a/ext/standard/php_smart_str.h +++ b/ext/standard/php_smart_str.h @@ -62,7 +62,7 @@ (d)->a = newlen < SMART_STR_START_SIZE \ ? SMART_STR_START_SIZE \ : newlen + SMART_STR_PREALLOC; \ - (d)->s = STR_ALLOC((d)->a, (what)); \ + (d)->s = zend_string_alloc((d)->a, (what)); \ (d)->s->len = 0; \ } else { \ newlen = (d)->s->len + (n); \ @@ -108,7 +108,7 @@ #define smart_str_free_ex(buf, what) do { \ smart_str *__s = (smart_str *) (buf); \ if (__s->s) { \ - STR_RELEASE(__s->s); \ + zend_string_release(__s->s); \ __s->s = NULL; \ } \ __s->a = 0; \ @@ -130,15 +130,15 @@ * #define f(..) ({char *r;..;__r;}) */ -static inline char *smart_str_print_long(char *buf, long num) { +static inline char *smart_str_print_long(char *buf, zend_long num) { char *r; - _zend_print_signed_to_buf(buf, num, long, r); + _zend_print_signed_to_buf(buf, num, zend_long, r); return r; } -static inline char *smart_str_print_unsigned(char *buf, long num) { +static inline char *smart_str_print_unsigned(char *buf, zend_long num) { char *r; - _zend_print_unsigned_to_buf(buf, num, unsigned long, r); + _zend_print_unsigned_to_buf(buf, num, zend_ulong, r); return r; } @@ -150,13 +150,13 @@ static inline char *smart_str_print_unsigned(char *buf, long num) { } while (0) #define smart_str_append_unsigned_ex(dest, num, type) \ - smart_str_append_generic_ex((dest), (num), (type), unsigned long, _unsigned) + smart_str_append_generic_ex((dest), (num), (type), zend_ulong, _unsigned) #define smart_str_append_long_ex(dest, num, type) \ - smart_str_append_generic_ex((dest), (num), (type), unsigned long, _signed) + smart_str_append_generic_ex((dest), (num), (type), zend_ulong, _signed) #define smart_str_append_off_t_ex(dest, num, type) \ - smart_str_append_generic_ex((dest), (num), (type), off_t, _signed) + smart_str_append_generic_ex((dest), (num), (type), zend_off_t, _signed) #define smart_str_append_ex(dest, src, what) \ smart_str_appendl_ex((dest), ((smart_str *)(src))->s->val, \ diff --git a/ext/standard/php_smart_string.h b/ext/standard/php_smart_string.h index 02ba9fe84e..91530d94d3 100644 --- a/ext/standard/php_smart_string.h +++ b/ext/standard/php_smart_string.h @@ -119,13 +119,13 @@ __dest->len = __nl; \ } while (0) -static inline char *smart_string_print_long(char *buf, long num) { +static inline char *smart_string_print_long(char *buf, zend_long num) { char *r; _zend_print_signed_to_buf(buf, num, unsigned long, r); return r; } -static inline char *smart_string_print_unsigned(char *buf, long num) { +static inline char *smart_string_print_unsigned(char *buf, zend_long num) { char *r; _zend_print_unsigned_to_buf(buf, num, unsigned long, r); return r; diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index 0f4240ea57..e0ffff5e23 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -120,25 +120,25 @@ PHPAPI struct lconv *localeconv_r(struct lconv *out); PHPAPI char *php_strtoupper(char *s, size_t len); PHPAPI char *php_strtolower(char *s, size_t len); -PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen); -PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS_DC); -PHPAPI zend_string *php_addcslashes(const char *str, int length, int freeit, char *what, int wlength TSRMLS_DC); -PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC); -PHPAPI void php_stripcslashes(char *str, int *len); +PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size_t trlen); +PHPAPI zend_string *php_addslashes(char *str, size_t length, int should_free TSRMLS_DC); +PHPAPI zend_string *php_addcslashes(const char *str, size_t length, int freeit, char *what, size_t wlength TSRMLS_DC); +PHPAPI void php_stripslashes(char *str, size_t *len TSRMLS_DC); +PHPAPI void php_stripcslashes(char *str, size_t *len); PHPAPI zend_string *php_basename(const char *s, size_t len, char *suffix, size_t sufflen TSRMLS_DC); PHPAPI size_t php_dirname(char *str, size_t len); PHPAPI char *php_stristr(char *s, char *t, size_t s_len, size_t t_len); -PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len, int case_sensitivity, int *replace_count); -PHPAPI zend_string *php_str_to_str(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len); -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC); -PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len); -PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow, int allow_len, zend_bool allow_tag_spaces); -PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count); -PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result); +PHPAPI zend_string *php_str_to_str_ex(char *haystack, size_t length, char *needle, + size_t needle_len, char *str, size_t str_len, int case_sensitivity, size_t *replace_count); +PHPAPI zend_string *php_str_to_str(char *haystack, size_t length, char *needle, + size_t needle_len, char *str, size_t str_len); +PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *return_value, int mode TSRMLS_DC); +PHPAPI size_t php_strip_tags(char *rbuf, size_t len, int *state, char *allow, size_t allow_len); +PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, int *stateptr, char *allow, size_t allow_len, zend_bool allow_tag_spaces); +PHPAPI size_t php_char_to_str_ex(char *str, size_t len, char from, char *to, size_t to_len, zval *result, int case_sensitivity, size_t *replace_count); +PHPAPI size_t php_char_to_str(char *str, size_t len, char from, char *to, size_t to_len, zval *result); PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC); -PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long limit); +PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, zend_long limit); PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end); PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end); diff --git a/ext/standard/php_uuencode.h b/ext/standard/php_uuencode.h index fedfe660e9..f1dda2de45 100644 --- a/ext/standard/php_uuencode.h +++ b/ext/standard/php_uuencode.h @@ -24,8 +24,8 @@ PHP_FUNCTION(convert_uudecode); PHP_FUNCTION(convert_uuencode); -PHPAPI zend_string *php_uudecode(char *src, int src_len); -PHPAPI zend_string *php_uuencode(char *src, int src_len); +PHPAPI zend_string *php_uudecode(char *src, size_t src_len); +PHPAPI zend_string *php_uuencode(char *src, size_t src_len); #endif /* PHP_UUENCODE_H */ diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index dea8c16c07..fc58b9f7b8 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -110,7 +110,7 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent ZEND_HASH_FOREACH_STR_KEY_VAL(target_hash, string_key, element) { zend_string *str = zval_get_string(element); uint el_len = str->len; - STR_RELEASE(str); + zend_string_release(str); if (el_len == 0) { continue; @@ -162,7 +162,7 @@ static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent p += str->len + 1; } next_element: - STR_RELEASE(str); + zend_string_release(str); } ZEND_HASH_FOREACH_END(); assert((uint)(p - env.envp) <= sizeenv); @@ -260,7 +260,7 @@ PHP_FUNCTION(proc_terminate) { zval *zproc; struct php_process_handle *proc; - long sig_no = SIGTERM; + zend_long sig_no = SIGTERM; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zproc, &sig_no) == FAILURE) { RETURN_FALSE; @@ -328,7 +328,7 @@ PHP_FUNCTION(proc_get_status) array_init(return_value); add_assoc_string(return_value, "command", proc->command); - add_assoc_long(return_value, "pid", (long) proc->child); + add_assoc_long(return_value, "pid", (zend_long) proc->child); #ifdef PHP_WIN32 @@ -427,7 +427,7 @@ PHP_FUNCTION(proc_open) int i; zval *descitem = NULL; zend_string *str_index; - ulong nindex; + zend_ulong nindex; struct php_proc_open_descriptor_item descriptors[PHP_PROC_OPEN_MAX_DESCRIPTORS]; #ifdef PHP_WIN32 PROCESS_INFORMATION pi; @@ -534,7 +534,7 @@ PHP_FUNCTION(proc_open) #else descriptors[ndesc].childend = dup(fd); if (descriptors[ndesc].childend < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to dup File-Handle for descriptor %ld - %s", nindex, strerror(errno)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to dup File-Handle for descriptor %pd - %s", nindex, strerror(errno)); goto exit_fail; } #endif diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c index aa3d256c3a..8abccaf820 100644 --- a/ext/standard/quot_print.c +++ b/ext/standard/quot_print.c @@ -96,7 +96,7 @@ PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t lengt i--; } - retval = STR_ALLOC(buf_size, 0); + retval = zend_string_alloc(buf_size, 0); i = length; p1 = str; p2 = (unsigned char*)retval->val; decoded_len = 0; @@ -147,12 +147,12 @@ PHPAPI zend_string *php_quot_print_decode(const unsigned char *str, size_t lengt PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t length) /* {{{ */ { - unsigned long lp = 0; + zend_ulong lp = 0; unsigned char c, *d; char *hex = "0123456789ABCDEF"; zend_string *ret; - ret = STR_SAFE_ALLOC(3, (length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1)), 0, 0); + ret = zend_string_safe_alloc(3, (length + (((3 * length)/(PHP_QPRINT_MAXL-9)) + 1)), 0, 0); d = (unsigned char*)ret->val; while (length--) { @@ -187,7 +187,7 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt } } *d = '\0'; - ret = STR_REALLOC(ret, d - (unsigned char*)ret->val, 0); + ret = zend_string_realloc(ret, d - (unsigned char*)ret->val, 0); return ret; } /* }}} */ @@ -201,21 +201,22 @@ PHPAPI zend_string *php_quot_print_encode(const unsigned char *str, size_t lengt Convert a quoted-printable string to an 8 bit string */ PHP_FUNCTION(quoted_printable_decode) { - char *arg1, *str_in; + zend_string *arg1; + char *str_in; zend_string *str_out; - int arg1_len, i = 0, j = 0, k; + size_t i = 0, j = 0, k; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg1, &arg1_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &arg1) == FAILURE) { return; } - if (arg1_len == 0) { + if (arg1->len == 0) { /* shortcut */ RETURN_EMPTY_STRING(); } - str_in = arg1; - str_out = STR_ALLOC(arg1_len, 0); + str_in = arg1->val; + str_out = zend_string_alloc(arg1->len, 0); while (str_in[i]) { switch (str_in[i]) { case '=': @@ -263,19 +264,18 @@ PHP_FUNCTION(quoted_printable_decode) /* {{{ proto string quoted_printable_encode(string str) */ PHP_FUNCTION(quoted_printable_encode) { - char *str; + zend_string *str; zend_string *new_str; - int str_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) != SUCCESS) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) != SUCCESS) { return; } - if (!str_len) { + if (!str->len) { RETURN_EMPTY_STRING(); } - new_str = php_quot_print_encode((unsigned char *)str, (size_t)str_len); + new_str = php_quot_print_encode((unsigned char *)str->val, (size_t)str->len); RETURN_STR(new_str); } /* }}} */ diff --git a/ext/standard/rand.c b/ext/standard/rand.c index 702fec2311..fdc86632cd 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -38,7 +38,7 @@ /* {{{ php_srand */ -PHPAPI void php_srand(long seed TSRMLS_DC) +PHPAPI void php_srand(zend_long seed TSRMLS_DC) { #ifdef ZTS BG(rand_seed) = (unsigned int) seed; @@ -59,9 +59,9 @@ PHPAPI void php_srand(long seed TSRMLS_DC) /* {{{ php_rand */ -PHPAPI long php_rand(TSRMLS_D) +PHPAPI zend_long php_rand(TSRMLS_D) { - long ret; + zend_long ret; if (!BG(rand_is_seeded)) { php_srand(GENERATE_SEED() TSRMLS_CC); @@ -229,7 +229,7 @@ PHPAPI php_uint32 php_mt_rand(TSRMLS_D) Seeds random number generator */ PHP_FUNCTION(srand) { - long seed = 0; + zend_long seed = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) return; @@ -245,7 +245,7 @@ PHP_FUNCTION(srand) Seeds Mersenne Twister random number generator */ PHP_FUNCTION(mt_srand) { - long seed = 0; + zend_long seed = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) return; @@ -288,9 +288,9 @@ PHP_FUNCTION(mt_srand) Returns a random number */ PHP_FUNCTION(rand) { - long min; - long max; - long number; + zend_long min; + zend_long max; + zend_long number; int argc = ZEND_NUM_ARGS(); if (argc != 0 && zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) @@ -309,16 +309,16 @@ PHP_FUNCTION(rand) Returns a random number from Mersenne Twister */ PHP_FUNCTION(mt_rand) { - long min; - long max; - long number; + zend_long min; + zend_long max; + zend_long number; int argc = ZEND_NUM_ARGS(); if (argc != 0) { if (zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) { return; } else if (max < min) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(%ld) is smaller than min(%ld)", max, min); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "max(" ZEND_LONG_FMT ") is smaller than min(" ZEND_LONG_FMT ")", max, min); RETURN_FALSE; } } @@ -335,7 +335,7 @@ PHP_FUNCTION(mt_rand) * Update: * I talked with Cokus via email and it won't ruin the algorithm */ - number = (long) (php_mt_rand(TSRMLS_C) >> 1); + number = (zend_long) (php_mt_rand(TSRMLS_C) >> 1); if (argc == 2) { RAND_RANGE(number, min, max, PHP_MT_RAND_MAX); } diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c index f5f97161f2..7ae0df6df5 100644 --- a/ext/standard/scanf.c +++ b/ext/standard/scanf.c @@ -356,7 +356,7 @@ PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs) * must not be a mixture of XPG3 specs and non-XPG3 specs * in the same format string. */ - value = strtoul(format-1, &end, 10); + value = ZEND_STRTOUL(format-1, &end, 10); if (*end != '$') { goto notXpg; } @@ -403,7 +403,7 @@ xpgCheckDone: * Parse any width specifier. */ if (isdigit(UCHAR(*ch))) { - value = strtoul(format-1, &format, 10); + value = ZEND_STRTOUL(format-1, &format, 10); flags |= SCAN_WIDTH; ch = format++; } @@ -582,7 +582,7 @@ PHPAPI int php_sscanf_internal( char *string, char *format, { int numVars, nconversions, totalVars = -1; int i, result; - long value; + zend_long value; int objIndex; char *end, *baseString; zval *current; @@ -590,7 +590,7 @@ PHPAPI int php_sscanf_internal( char *string, char *format, int base = 0; int underflow = 0; size_t width; - long (*fn)() = NULL; + zend_long (*fn)() = NULL; char *ch, sch; int flags; char buf[64]; /* Temporary buffer to hold scanned number @@ -708,7 +708,7 @@ literal: flags |= SCAN_SUPPRESS; ch = format++; } else if ( isdigit(UCHAR(*ch))) { - value = strtoul(format-1, &end, 10); + value = ZEND_STRTOUL(format-1, &end, 10); if (*end == '$') { format = end+1; ch = format++; @@ -720,7 +720,7 @@ literal: * Parse any width specifier. */ if ( isdigit(UCHAR(*ch))) { - width = strtoul(format-1, &format, 10); + width = ZEND_STRTOUL(format-1, &format, 10); ch = format++; } else { width = 0; @@ -744,7 +744,7 @@ literal: } else if (numVars) { current = Z_REFVAL(args[objIndex++]); zval_ptr_dtor(current); - ZVAL_LONG(current, (long)(string - baseString) ); + ZVAL_LONG(current, (zend_long)(string - baseString) ); } else { add_index_long(return_value, objIndex++, string - baseString); } @@ -756,29 +756,29 @@ literal: case 'D': op = 'i'; base = 10; - fn = (long (*)())strtol; + fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'i': op = 'i'; base = 0; - fn = (long (*)())strtol; + fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'o': op = 'i'; base = 8; - fn = (long (*)())strtol; + fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'x': case 'X': op = 'i'; base = 16; - fn = (long (*)())strtol; + fn = (zend_long (*)())ZEND_STRTOL_PTR; break; case 'u': op = 'i'; base = 10; flags |= SCAN_UNSIGNED; - fn = (long (*)())strtoul; + fn = (zend_long (*)())ZEND_STRTOUL_PTR; break; case 'f': @@ -1049,9 +1049,9 @@ addToInt: */ if (!(flags & SCAN_SUPPRESS)) { *end = '\0'; - value = (long) (*fn)(buf, NULL, base); + value = (zend_long) (*fn)(buf, NULL, base); if ((flags & SCAN_UNSIGNED) && (value < 0)) { - snprintf(buf, sizeof(buf), "%lu", value); /* INTL: ISO digit */ + snprintf(buf, sizeof(buf), ZEND_ULONG_FMT, value); /* INTL: ISO digit */ if (numVars && objIndex >= argCount) { break; } else if (numVars) { @@ -1190,7 +1190,7 @@ done: scan_set_error_return( numVars, return_value ); result = SCAN_ERROR_EOF; } else if (numVars) { - convert_to_long(return_value ); + convert_to_int(return_value ); Z_LVAL_P(return_value) = nconversions; } else if (nconversions < totalVars) { /* TODO: not all elements converted. we need to prune the list - cc */ diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c index 84a7d258c1..2f596eed44 100644 --- a/ext/standard/sha1.c +++ b/ext/standard/sha1.c @@ -34,20 +34,19 @@ PHPAPI void make_sha1_digest(char *sha1str, unsigned char *digest) Calculate the sha1 hash of a string */ PHP_FUNCTION(sha1) { - char *arg; - int arg_len; + zend_string *arg; zend_bool raw_output = 0; char sha1str[41]; PHP_SHA1_CTX context; unsigned char digest[20]; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &arg, &raw_output) == FAILURE) { return; } sha1str[0] = '\0'; PHP_SHA1Init(&context); - PHP_SHA1Update(&context, arg, arg_len); + PHP_SHA1Update(&context, arg->val, arg->len); PHP_SHA1Final(digest, &context); if (raw_output) { RETURN_STRINGL(digest, 20); @@ -181,7 +180,7 @@ PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX * context) context. */ PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX * context, const unsigned char *input, - unsigned int inputLen) + size_t inputLen) { unsigned int i, index, partLen; diff --git a/ext/standard/sha1.h b/ext/standard/sha1.h index ea63a234cf..f852386a62 100644 --- a/ext/standard/sha1.h +++ b/ext/standard/sha1.h @@ -31,7 +31,7 @@ typedef struct { } PHP_SHA1_CTX; PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX *); -PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, unsigned int); +PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, size_t); PHPAPI void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *); PHPAPI void make_sha1_digest(char *sha1str, unsigned char *digest); diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 652512ce07..a0448803f4 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -51,7 +51,7 @@ static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC) Creates a pair of connected, indistinguishable socket streams */ PHP_FUNCTION(stream_socket_pair) { - long domain, type, protocol; + zend_long domain, type, protocol; php_stream *s1, *s2; php_socket_t pair[2]; @@ -96,7 +96,7 @@ PHP_FUNCTION(stream_socket_client) char *hashkey = NULL; php_stream *stream = NULL; int err; - long flags = PHP_STREAM_CLIENT_CONNECT; + zend_long flags = PHP_STREAM_CLIENT_CONNECT; zend_string *errstr = NULL; php_stream_context *context = NULL; @@ -141,7 +141,7 @@ PHP_FUNCTION(stream_socket_client) zend_string *quoted_host = php_addslashes(host, host_len, 0 TSRMLS_CC); php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host->val, errstr == NULL ? "Unknown error" : errstr->val); - STR_RELEASE(quoted_host); + zend_string_release(quoted_host); } if (hashkey) { @@ -157,13 +157,13 @@ PHP_FUNCTION(stream_socket_client) zval_dtor(zerrstr); ZVAL_STR(zerrstr, errstr); } else if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } RETURN_FALSE; } if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } php_stream_to_zval(stream, return_value); @@ -180,7 +180,7 @@ PHP_FUNCTION(stream_socket_server) zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL; php_stream *stream = NULL; int err = 0; - long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN; + zend_long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN; zend_string *errstr = NULL; php_stream_context *context = NULL; @@ -222,13 +222,13 @@ PHP_FUNCTION(stream_socket_server) zval_dtor(zerrstr); ZVAL_STR(zerrstr, errstr); } else if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } RETURN_FALSE; } if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } php_stream_to_zval(stream, return_value); @@ -284,7 +284,7 @@ PHP_FUNCTION(stream_socket_accept) } if (errstr) { - STR_RELEASE(errstr); + zend_string_release(errstr); } } /* }}} */ @@ -321,7 +321,7 @@ PHP_FUNCTION(stream_socket_sendto) { php_stream *stream; zval *zstream; - long flags = 0; + zend_long flags = 0; char *data, *target_addr = NULL; int datalen, target_addr_len = 0; php_sockaddr_storage sa; @@ -351,9 +351,9 @@ PHP_FUNCTION(stream_socket_recvfrom) php_stream *stream; zval *zstream, *zremote = NULL; zend_string *remote_addr = NULL; - long to_read = 0; + zend_long to_read = 0; zend_string *read_buf; - long flags = 0; + zend_long flags = 0; int recvd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|lz/", &zstream, &to_read, &flags, &zremote) == FAILURE) { @@ -372,7 +372,7 @@ PHP_FUNCTION(stream_socket_recvfrom) RETURN_FALSE; } - read_buf = STR_ALLOC(to_read, 0); + read_buf = zend_string_alloc(to_read, 0); recvd = php_stream_xport_recvfrom(stream, read_buf->val, to_read, flags, NULL, NULL, zremote ? &remote_addr : NULL @@ -387,7 +387,7 @@ PHP_FUNCTION(stream_socket_recvfrom) RETURN_NEW_STR(read_buf); } - STR_FREE(read_buf); + zend_string_free(read_buf); RETURN_FALSE; } /* }}} */ @@ -398,7 +398,7 @@ PHP_FUNCTION(stream_get_contents) { php_stream *stream; zval *zsrc; - long maxlen = PHP_STREAM_COPY_ALL, + zend_long maxlen = PHP_STREAM_COPY_ALL, desiredpos = -1L; zend_string *contents; @@ -423,13 +423,13 @@ PHP_FUNCTION(stream_get_contents) if (seek_res != 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Failed to seek to position %ld in the stream", desiredpos); + "Failed to seek to position %pd in the stream", desiredpos); RETURN_FALSE; } } if (maxlen > INT_MAX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "maxlen truncated from %ld to %d bytes", maxlen, INT_MAX); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "maxlen truncated from %pd to %d bytes", maxlen, INT_MAX); maxlen = INT_MAX; } if ((contents = php_stream_copy_to_mem(stream, maxlen, 0))) { @@ -446,7 +446,7 @@ PHP_FUNCTION(stream_copy_to_stream) { php_stream *src, *dest; zval *zsrc, *zdest; - long maxlen = PHP_STREAM_COPY_ALL, pos = 0; + zend_long maxlen = PHP_STREAM_COPY_ALL, pos = 0; size_t len; int ret; @@ -458,7 +458,7 @@ PHP_FUNCTION(stream_copy_to_stream) php_stream_from_zval(dest, zdest); if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position " ZEND_LONG_FMT " in the stream", pos); RETURN_FALSE; } @@ -541,7 +541,7 @@ PHP_FUNCTION(stream_get_transports) if ((stream_xport_hash = php_stream_xport_get_hash())) { array_init(return_value); ZEND_HASH_FOREACH_STR_KEY(stream_xport_hash, stream_xport) { - add_next_index_str(return_value, STR_COPY(stream_xport)); + add_next_index_str(return_value, zend_string_copy(stream_xport)); } ZEND_HASH_FOREACH_END(); } else { RETURN_FALSE; @@ -564,7 +564,7 @@ PHP_FUNCTION(stream_get_wrappers) array_init(return_value); ZEND_HASH_FOREACH_STR_KEY(url_stream_wrappers_hash, stream_protocol) { if (stream_protocol) { - add_next_index_str(return_value, STR_COPY(stream_protocol)); + add_next_index_str(return_value, zend_string_copy(stream_protocol)); } } ZEND_HASH_FOREACH_END(); } else { @@ -619,7 +619,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) php_stream *stream; int ret = 0; zend_string *key; - ulong num_ind; + zend_ulong num_ind; if (Z_TYPE_P(stream_array) != IS_ARRAY) { return 0; @@ -723,7 +723,7 @@ PHP_FUNCTION(stream_select) fd_set rfds, wfds, efds; php_socket_t max_fd = 0; int retval, sets = 0; - long usec = 0; + zend_long usec = 0; int set_count, max_set_count = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!a/!a/!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) @@ -763,7 +763,7 @@ PHP_FUNCTION(stream_select) /* If seconds is not set to null, build the timeval, else we wait indefinitely */ if (sec != NULL) { - convert_to_long_ex(sec); + convert_to_int_ex(sec); if (Z_LVAL_P(sec) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The seconds parameter must be greater than 0"); @@ -1118,7 +1118,7 @@ static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS) php_stream *stream; char *filtername; int filternamelen; - long read_write = 0; + zend_long read_write = 0; zval *filterparams = NULL; php_stream_filter *filter = NULL; int ret; @@ -1242,7 +1242,7 @@ PHP_FUNCTION(stream_get_line) { char *str = NULL; int str_len = 0; - long max_length; + zend_long max_length; zval *zstream; zend_string *buf; php_stream *stream; @@ -1276,7 +1276,7 @@ PHP_FUNCTION(stream_set_blocking) { zval *arg1; int block; - long arg2; + zend_long arg2; php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) { @@ -1302,7 +1302,7 @@ PHP_FUNCTION(stream_set_blocking) PHP_FUNCTION(stream_set_timeout) { zval *socket; - long seconds, microseconds = 0; + zend_long seconds, microseconds = 0; struct timeval t; php_stream *stream; int argc = ZEND_NUM_ARGS(); @@ -1337,7 +1337,7 @@ PHP_FUNCTION(stream_set_write_buffer) { zval *arg1; int ret; - long arg2; + zend_long arg2; size_t buff; php_stream *stream; @@ -1365,7 +1365,7 @@ PHP_FUNCTION(stream_set_write_buffer) PHP_FUNCTION(stream_set_chunk_size) { int ret; - long csize; + zend_long csize; zval *zstream; php_stream *stream; @@ -1374,7 +1374,7 @@ PHP_FUNCTION(stream_set_chunk_size) } if (csize <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given %ld", csize); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The chunk size must be a positive integer, given " ZEND_LONG_FMT, csize); RETURN_FALSE; } /* stream.chunk_size is actually a size_t, but php_stream_set_option @@ -1390,7 +1390,7 @@ PHP_FUNCTION(stream_set_chunk_size) ret = php_stream_set_option(stream, PHP_STREAM_OPTION_SET_CHUNK_SIZE, (int)csize, NULL); - RETURN_LONG(ret > 0 ? (long)ret : (long)EOF); + RETURN_LONG(ret > 0 ? (zend_long)ret : (zend_long)EOF); } /* }}} */ @@ -1400,7 +1400,7 @@ PHP_FUNCTION(stream_set_read_buffer) { zval *arg1; int ret; - long arg2; + zend_long arg2; size_t buff; php_stream *stream; @@ -1427,7 +1427,7 @@ PHP_FUNCTION(stream_set_read_buffer) Enable or disable a specific kind of crypto on the stream */ PHP_FUNCTION(stream_socket_enable_crypto) { - long cryptokind = 0; + zend_long cryptokind = 0; zval *zstream, *zsessstream = NULL; php_stream *stream, *sessstream = NULL; zend_bool enable, cryptokindnull; @@ -1558,7 +1558,7 @@ PHP_FUNCTION(stream_supports_lock) disallowed. */ PHP_FUNCTION(stream_socket_shutdown) { - long how; + zend_long how; zval *zstream; php_stream *stream; diff --git a/ext/standard/string.c b/ext/standard/string.c index 82b98eb094..325c66affa 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -115,7 +115,7 @@ void register_string_constants(INIT_FUNC_ARGS) } /* }}} */ -int php_tag_find(char *tag, int len, char *set); +int php_tag_find(char *tag, size_t len, char *set); /* this is read-only, so it's ok */ static char hexconvtab[] = "0123456789abcdef"; @@ -132,7 +132,7 @@ static zend_string *php_bin2hex(const unsigned char *old, const size_t oldlen) zend_string *result; size_t i, j; - result = STR_SAFE_ALLOC(oldlen, 2 * sizeof(char), 0, 0); + result = zend_string_safe_alloc(oldlen, 2 * sizeof(char), 0, 0); for (i = j = 0; i < oldlen; i++) { result->val[j++] = hexconvtab[old[i] >> 4]; @@ -149,7 +149,7 @@ static zend_string *php_bin2hex(const unsigned char *old, const size_t oldlen) static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen) { size_t target_length = oldlen >> 1; - zend_string *str = STR_ALLOC(target_length, 0); + zend_string *str = zend_string_alloc(target_length, 0); unsigned char *ret = (unsigned char *)str->val; size_t i, j; @@ -164,7 +164,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen) } else if (c >= 'A' && c <= 'F') { d = (c - 'A' + 10) << 4; } else { - STR_FREE(str); + zend_string_free(str); return NULL; } c = old[j++]; @@ -175,7 +175,7 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen) } else if (c >= 'A' && c <= 'F') { d |= c - 'A' + 10; } else { - STR_FREE(str); + zend_string_free(str); return NULL; } ret[i] = d; @@ -237,14 +237,13 @@ PHP_MSHUTDOWN_FUNCTION(localeconv) PHP_FUNCTION(bin2hex) { zend_string *result; - char *data; - int datalen; + zend_string *data; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &datalen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &data) == FAILURE) { return; } - result = php_bin2hex((unsigned char *)data, datalen); + result = php_bin2hex((unsigned char *)data->val, data->len); if (!result) { RETURN_FALSE; @@ -282,39 +281,38 @@ PHP_FUNCTION(hex2bin) static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ */ { - char *s11, *s22; - int len1, len2; - long start = 0, len = 0; + zend_string *s11, *s22; + zend_long start = 0, len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", &s11, &len1, - &s22, &len2, &start, &len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", &s11, + &s22, &start, &len) == FAILURE) { return; } if (ZEND_NUM_ARGS() < 4) { - len = len1; + len = s11->len; } /* look at substr() function for more information */ if (start < 0) { - start += len1; + start += (zend_long)s11->len; if (start < 0) { start = 0; } - } else if (start > len1) { + } else if ((size_t)start > s11->len) { RETURN_FALSE; } if (len < 0) { - len += (len1 - start); + len += (s11->len - start); if (len < 0) { len = 0; } } - if (len > len1 - start) { - len = len1 - start; + if (len > (zend_long)s11->len - start) { + len = s11->len - start; } if(len == 0) { @@ -322,15 +320,15 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) / } if (behavior == STR_STRSPN) { - RETURN_LONG(php_strspn(s11 + start /*str1_start*/, - s22 /*str2_start*/, - s11 + start + len /*str1_end*/, - s22 + len2 /*str2_end*/)); + RETURN_LONG(php_strspn(s11->val + start /*str1_start*/, + s22->val /*str2_start*/, + s11->val + start + len /*str1_end*/, + s22->val + s22->len /*str2_end*/)); } else if (behavior == STR_STRCSPN) { - RETURN_LONG(php_strcspn(s11 + start /*str1_start*/, - s22 /*str2_start*/, - s11 + start + len /*str1_end*/, - s22 + len2 /*str2_end*/)); + RETURN_LONG(php_strcspn(s11->val + start /*str1_start*/, + s22->val /*str2_start*/, + s11->val + start + len /*str1_end*/, + s22->val + s22->len /*str2_end*/)); } } @@ -526,7 +524,7 @@ PHP_MINIT_FUNCTION(nl_langinfo) Query language and locale information */ PHP_FUNCTION(nl_langinfo) { - long item; + zend_long item; char *value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &item) == FAILURE) { @@ -694,7 +692,7 @@ PHP_FUNCTION(nl_langinfo) #endif break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Item '%ld' is not valid", item); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Item '" ZEND_LONG_FMT "' is not valid", item); RETURN_FALSE; } /* }}} */ @@ -714,15 +712,14 @@ PHP_FUNCTION(nl_langinfo) Compares two strings using the current locale */ PHP_FUNCTION(strcoll) { - char *s1, *s2; - int s1len, s2len; + zend_string *s1, *s2; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1len, &s2, &s2len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &s1, &s2) == FAILURE) { return; } - RETURN_LONG(strcoll((const char *) s1, - (const char *) s2)); + RETURN_LONG(strcoll((const char *) s1->val, + (const char *) s2->val)); } /* }}} */ #endif @@ -732,7 +729,7 @@ PHP_FUNCTION(strcoll) * it needs to be incrementing. * Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors) */ -static inline int php_charmask(unsigned char *input, int len, char *mask TSRMLS_DC) +static inline int php_charmask(unsigned char *input, size_t len, char *mask TSRMLS_DC) { unsigned char *end; unsigned char c; @@ -781,9 +778,9 @@ static inline int php_charmask(unsigned char *input, int len, char *mask TSRMLS_ * mode 3 : trim left and right * what indicates which chars are to be trimmed. NULL->default (' \t\n\r\v\0') */ -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC) +PHPAPI char *php_trim(char *c, size_t len, char *what, size_t what_len, zval *return_value, int mode TSRMLS_DC) { - register int i; + register zend_long i; int trimmed = 0; char mask[256]; @@ -828,23 +825,22 @@ PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_v */ static void php_do_trim(INTERNAL_FUNCTION_PARAMETERS, int mode) { - char *str; - char *what = NULL; - int str_len, what_len = 0; + zend_string *str; + zend_string *what = NULL; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &what, &what_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &what) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_STRING(what, what_len) + Z_PARAM_STR(what) ZEND_PARSE_PARAMETERS_END(); #endif - php_trim(str, str_len, what, what_len, return_value, mode TSRMLS_CC); + php_trim(str->val, str->len, (what ? what->val : NULL), (what ? what->len : 0), return_value, mode TSRMLS_CC); } /* }}} */ @@ -876,23 +872,33 @@ PHP_FUNCTION(ltrim) Wraps buffer to selected number of characters using string break char */ PHP_FUNCTION(wordwrap) { - const char *text, *breakchar = "\n"; - int textlen, breakcharlen = 1, newtextlen, chk; + zend_string *text, *breakchar = NULL, *breakchar_save = NULL; + size_t newtextlen, chk; size_t alloced; - long current = 0, laststart = 0, lastspace = 0; - long linelength = 75; + zend_long current = 0, laststart = 0, lastspace = 0; + zend_long linelength = 75; zend_bool docut = 0; zend_string *newtext; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lsb", &text, &textlen, &linelength, &breakchar, &breakcharlen, &docut) == FAILURE) { + breakchar = breakchar_save = zend_string_init("\n", 1, 1); + if (!breakchar) { return; } - if (textlen == 0) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|lSb", &text, &linelength, &breakchar, &docut) == FAILURE) { + zend_string_free(breakchar); + return; + } + + if (breakchar != breakchar_save) { + zend_string_free(breakchar_save); + } + + if (text->len == 0) { RETURN_EMPTY_STRING(); } - if (breakcharlen == 0) { + if (breakchar->len == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Break string cannot be empty"); RETURN_FALSE; } @@ -904,21 +910,21 @@ PHP_FUNCTION(wordwrap) /* Special case for a single-character break as it needs no additional storage space */ - if (breakcharlen == 1 && !docut) { - newtext = STR_INIT(text, textlen, 0); + if (breakchar->len == 1 && !docut) { + newtext = zend_string_init(text->val, text->len, 0); laststart = lastspace = 0; - for (current = 0; current < textlen; current++) { - if (text[current] == breakchar[0]) { + for (current = 0; current < text->len; current++) { + if (text->val[current] == breakchar->val[0]) { laststart = lastspace = current + 1; - } else if (text[current] == ' ') { + } else if (text->val[current] == ' ') { if (current - laststart >= linelength) { - newtext->val[current] = breakchar[0]; + newtext->val[current] = breakchar->val[0]; laststart = current + 1; } lastspace = current; } else if (current - laststart >= linelength && laststart != lastspace) { - newtext->val[lastspace] = breakchar[0]; + newtext->val[lastspace] = breakchar->val[0]; laststart = lastspace + 1; } } @@ -927,44 +933,44 @@ PHP_FUNCTION(wordwrap) } else { /* Multiple character line break or forced cut */ if (linelength > 0) { - chk = (int)(textlen/linelength + 1); - newtext = STR_ALLOC(chk * breakcharlen + textlen, 0); - alloced = textlen + chk * breakcharlen + 1; + chk = (size_t)(text->len/linelength + 1); + newtext = zend_string_alloc(chk * breakchar->len + text->len, 0); + alloced = text->len + chk * breakchar->len + 1; } else { - chk = textlen; - alloced = textlen * (breakcharlen + 1) + 1; - newtext = STR_ALLOC(textlen * (breakcharlen + 1), 0); + chk = text->len; + alloced = text->len * (breakchar->len + 1) + 1; + newtext = zend_string_alloc(text->len * (breakchar->len + 1), 0); } /* now keep track of the actual new text length */ newtextlen = 0; laststart = lastspace = 0; - for (current = 0; current < textlen; current++) { + for (current = 0; current < text->len; current++) { if (chk <= 0) { - alloced += (int) (((textlen - current + 1)/linelength + 1) * breakcharlen) + 1; - newtext = STR_REALLOC(newtext, alloced, 0); - chk = (int) ((textlen - current)/linelength) + 1; + alloced += (size_t) (((text->len - current + 1)/linelength + 1) * breakchar->len) + 1; + newtext = zend_string_realloc(newtext, alloced, 0); + chk = (size_t) ((text->len - current)/linelength) + 1; } /* when we hit an existing break, copy to new buffer, and * fix up laststart and lastspace */ - if (text[current] == breakchar[0] - && current + breakcharlen < textlen - && !strncmp(text+current, breakchar, breakcharlen)) { - memcpy(newtext->val + newtextlen, text + laststart, current - laststart + breakcharlen); - newtextlen += current - laststart + breakcharlen; - current += breakcharlen - 1; + if (text->val[current] == breakchar->val[0] + && current + breakchar->len < text->len + && !strncmp(text->val+current, breakchar->val, breakchar->len)) { + memcpy(newtext->val + newtextlen, text->val + laststart, current - laststart + breakchar->len); + newtextlen += current - laststart + breakchar->len; + current += breakchar->len - 1; laststart = lastspace = current + 1; chk--; } /* if it is a space, check if it is at the line boundary, * copy and insert a break, or just keep track of it */ - else if (text[current] == ' ') { + else if (text->val[current] == ' ') { if (current - laststart >= linelength) { - memcpy(newtext->val + newtextlen, text + laststart, current - laststart); + memcpy(newtext->val + newtextlen, text->val + laststart, current - laststart); newtextlen += current - laststart; - memcpy(newtext->val + newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; + memcpy(newtext->val + newtextlen, breakchar->val, breakchar->len); + newtextlen += breakchar->len; laststart = current + 1; chk--; } @@ -975,10 +981,10 @@ PHP_FUNCTION(wordwrap) * copy and insert a break. */ else if (current - laststart >= linelength && docut && laststart >= lastspace) { - memcpy(newtext->val + newtextlen, text + laststart, current - laststart); + memcpy(newtext->val + newtextlen, text->val + laststart, current - laststart); newtextlen += current - laststart; - memcpy(newtext->val + newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; + memcpy(newtext->val + newtextlen, breakchar->val, breakchar->len); + newtextlen += breakchar->len; laststart = lastspace = current; chk--; } @@ -987,10 +993,10 @@ PHP_FUNCTION(wordwrap) * up the laststart */ else if (current - laststart >= linelength && laststart < lastspace) { - memcpy(newtext->val + newtextlen, text + laststart, lastspace - laststart); + memcpy(newtext->val + newtextlen, text->val + laststart, lastspace - laststart); newtextlen += lastspace - laststart; - memcpy(newtext->val + newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; + memcpy(newtext->val + newtextlen, breakchar->val, breakchar->len); + newtextlen += breakchar->len; laststart = lastspace = lastspace + 1; chk--; } @@ -998,13 +1004,13 @@ PHP_FUNCTION(wordwrap) /* copy over any stragglers */ if (laststart != current) { - memcpy(newtext->val + newtextlen, text + laststart, current - laststart); + memcpy(newtext->val + newtextlen, text->val + laststart, current - laststart); newtextlen += current - laststart; } newtext->val[newtextlen] = '\0'; /* free unused memory */ - newtext = STR_REALLOC(newtext, newtextlen, 0); + newtext = zend_string_realloc(newtext, newtextlen, 0); RETURN_NEW_STR(newtext); } @@ -1013,7 +1019,7 @@ PHP_FUNCTION(wordwrap) /* {{{ php_explode */ -PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long limit) +PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, zend_long limit) { char *p1, *p2, *endp; @@ -1039,7 +1045,7 @@ PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long limit) /* {{{ php_explode_negative_limit */ -PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_value, long limit) +PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_value, zend_long limit) { #define EXPLODE_ALLOC_STEP 64 char *p1, *p2, *endp; @@ -1055,8 +1061,8 @@ PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_valu by doing nothing we return empty array */ } else { - int allocated = EXPLODE_ALLOC_STEP, found = 0; - long i, to_return; + size_t allocated = EXPLODE_ALLOC_STEP, found = 0; + zend_long i, to_return; char **positions = emalloc(allocated * sizeof(char *)); positions[found++] = p1; @@ -1085,7 +1091,7 @@ PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_valu PHP_FUNCTION(explode) { zend_string *str, *delim; - long limit = LONG_MAX; /* No limit */ + zend_long limit = ZEND_LONG_MAX; /* No limit */ zval zdelim, zstr; #ifndef FAST_ZPP @@ -1167,7 +1173,7 @@ again: case IS_DOUBLE: { char *stmp; - int str_len = spprintf(&stmp, 0, "%.*G", (int) EG(precision), Z_DVAL_P(tmp)); + size_t str_len = spprintf(&stmp, 0, "%.*G", (int) EG(precision), Z_DVAL_P(tmp)); smart_str_appendl(&implstr, stmp, str_len); efree(stmp); } @@ -1180,7 +1186,7 @@ again: default: str = zval_get_string(tmp); smart_str_appendl(&implstr, str->val, str->len); - STR_RELEASE(str); + zend_string_release(str); break; } @@ -1255,26 +1261,24 @@ PHP_FUNCTION(implode) Tokenize a string */ PHP_FUNCTION(strtok) { - char *str, *tok = NULL; - int str_len, tok_len = 0; + zend_string *str, *tok = NULL; char *token; char *token_end; char *p; char *pe; int skipped = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &tok, &tok_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &tok) == FAILURE) { return; } if (ZEND_NUM_ARGS() == 1) { tok = str; - tok_len = str_len; } else { zval_ptr_dtor(&BG(strtok_zval)); - ZVAL_STRINGL(&BG(strtok_zval), str, str_len); + ZVAL_STRINGL(&BG(strtok_zval), str->val, str->len); BG(strtok_last) = BG(strtok_string) = Z_STRVAL(BG(strtok_zval)); - BG(strtok_len) = str_len; + BG(strtok_len) = str->len; } p = BG(strtok_last); /* Where we start to search */ @@ -1284,8 +1288,8 @@ PHP_FUNCTION(strtok) RETURN_FALSE; } - token = tok; - token_end = token + tok_len; + token = tok->val; + token_end = token + tok->len; while (token < token_end) { STRTOK_TABLE(token++) = 1; @@ -1320,7 +1324,7 @@ return_token: /* Restore table -- usually faster then memset'ing the table on every invocation */ restore: - token = tok; + token = tok->val; while (token < token_end) { STRTOK_TABLE(token++) = 0; @@ -1349,15 +1353,14 @@ PHPAPI char *php_strtoupper(char *s, size_t len) Makes a string uppercase */ PHP_FUNCTION(strtoupper) { - char *arg; - int arglen; + zend_string *arg; zend_string *result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arglen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &arg) == FAILURE) { return; } - result = STR_INIT(arg, arglen, 0); + result = zend_string_init(arg->val, arg->len, 0); php_strtoupper(result->val, result->len); RETURN_NEW_STR(result); } @@ -1384,21 +1387,20 @@ PHPAPI char *php_strtolower(char *s, size_t len) Makes a string lowercase */ PHP_FUNCTION(strtolower) { - char *str; - int arglen; + zend_string *str; zend_string *result; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &arglen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(str, arglen) + Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif - result = STR_INIT(str, arglen, 0); + result = zend_string_init(str->val, str->len, 0); php_strtolower(result->val, result->len); RETURN_NEW_STR(result); } @@ -1479,7 +1481,7 @@ quit_loop: len = cend - comp; - ret = STR_INIT(comp, len, 0); + ret = zend_string_init(comp, len, 0); return ret; } /* }}} */ @@ -1519,7 +1521,7 @@ PHP_FUNCTION(dirname) return; } - ret = STR_INIT(str, str_len, 0); + ret = zend_string_init(str, str_len, 0); ret->len = zend_dirname(ret->val, str_len); RETURN_NEW_STR(ret); @@ -1533,7 +1535,7 @@ PHP_FUNCTION(pathinfo) zval tmp; char *path, *dirname; int path_len, have_basename; - long opt = PHP_PATHINFO_ALL; + zend_long opt = PHP_PATHINFO_ALL; zend_string *ret = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &path_len, &opt) == FAILURE) { @@ -1555,7 +1557,7 @@ PHP_FUNCTION(pathinfo) if (have_basename) { ret = php_basename(path, path_len, NULL, 0 TSRMLS_CC); - add_assoc_str(&tmp, "basename", STR_COPY(ret)); + add_assoc_str(&tmp, "basename", zend_string_copy(ret)); } if ((opt & PHP_PATHINFO_EXTENSION) == PHP_PATHINFO_EXTENSION) { @@ -1590,7 +1592,7 @@ PHP_FUNCTION(pathinfo) } if (ret) { - STR_RELEASE(ret); + zend_string_release(ret); } if (opt == PHP_PATHINFO_ALL) { @@ -1678,7 +1680,7 @@ static int php_needle_char(zval *needle, char *target TSRMLS_DC) { zval holder = *needle; zval_copy_ctor(&(holder)); - convert_to_long(&(holder)); + convert_to_int(&(holder)); if(Z_TYPE(holder) != IS_LONG) { return FAILURE; } @@ -1698,19 +1700,18 @@ static int php_needle_char(zval *needle, char *target TSRMLS_DC) PHP_FUNCTION(stristr) { zval *needle; - char *haystack; - int haystack_len; + zend_string *haystack; char *found = NULL; - int found_offset; + size_t found_offset; char *haystack_dup; char needle_char[2]; zend_bool part = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|b", &haystack, &haystack_len, &needle, &part) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|b", &haystack, &needle, &part) == FAILURE) { return; } - haystack_dup = estrndup(haystack, haystack_len); + haystack_dup = estrndup(haystack->val, haystack->len); if (Z_TYPE_P(needle) == IS_STRING) { char *orig_needle; @@ -1720,7 +1721,7 @@ PHP_FUNCTION(stristr) RETURN_FALSE; } orig_needle = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); - found = php_stristr(haystack_dup, orig_needle, haystack_len, Z_STRLEN_P(needle)); + found = php_stristr(haystack_dup, orig_needle, haystack->len, Z_STRLEN_P(needle)); efree(orig_needle); } else { if (php_needle_char(needle, needle_char TSRMLS_CC) != SUCCESS) { @@ -1729,15 +1730,15 @@ PHP_FUNCTION(stristr) } needle_char[1] = 0; - found = php_stristr(haystack_dup, needle_char, haystack_len, 1); + found = php_stristr(haystack_dup, needle_char, haystack->len, 1); } if (found) { found_offset = found - haystack_dup; if (part) { - RETVAL_STRINGL(haystack, found_offset); + RETVAL_STRINGL(haystack->val, found_offset); } else { - RETVAL_STRINGL(haystack + found_offset, haystack_len - found_offset); + RETVAL_STRINGL(haystack->val + found_offset, haystack->len - found_offset); } } else { RETVAL_FALSE; @@ -1752,14 +1753,13 @@ PHP_FUNCTION(stristr) PHP_FUNCTION(strstr) { zval *needle; - char *haystack; - int haystack_len; + zend_string *haystack; char *found = NULL; char needle_char[2]; - long found_offset; + zend_long found_offset; zend_bool part = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|b", &haystack, &haystack_len, &needle, &part) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|b", &haystack, &needle, &part) == FAILURE) { return; } @@ -1769,22 +1769,22 @@ PHP_FUNCTION(strstr) RETURN_FALSE; } - found = (char*)php_memnstr(haystack, Z_STRVAL_P(needle), Z_STRLEN_P(needle), haystack + haystack_len); + found = (char*)php_memnstr(haystack->val, Z_STRVAL_P(needle), Z_STRLEN_P(needle), haystack->val + haystack->len); } else { if (php_needle_char(needle, needle_char TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } needle_char[1] = 0; - found = (char*)php_memnstr(haystack, needle_char, 1, haystack + haystack_len); + found = (char*)php_memnstr(haystack->val, needle_char, 1, haystack->val + haystack->len); } if (found) { - found_offset = found - haystack; + found_offset = found - haystack->val; if (part) { - RETURN_STRINGL(haystack, found_offset); + RETURN_STRINGL(haystack->val, found_offset); } else { - RETURN_STRINGL(found, haystack_len - found_offset); + RETURN_STRINGL(found, haystack->len - found_offset); } } RETURN_FALSE; @@ -1800,26 +1800,25 @@ PHP_FUNCTION(strstr) PHP_FUNCTION(strpos) { zval *needle; - char *haystack; + zend_string *haystack; char *found = NULL; char needle_char[2]; - long offset = 0; - int haystack_len; + zend_long offset = 0; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &needle, &offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_STRING(haystack, haystack_len) + Z_PARAM_STR(haystack) Z_PARAM_ZVAL(needle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) ZEND_PARSE_PARAMETERS_END(); #endif - if (offset < 0 || offset > haystack_len) { + if (offset < 0 || offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } @@ -1830,24 +1829,24 @@ PHP_FUNCTION(strpos) RETURN_FALSE; } - found = (char*)php_memnstr(haystack + offset, + found = (char*)php_memnstr(haystack->val + offset, Z_STRVAL_P(needle), Z_STRLEN_P(needle), - haystack + haystack_len); + haystack->val + haystack->len); } else { if (php_needle_char(needle, needle_char TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } needle_char[1] = 0; - found = (char*)php_memnstr(haystack + offset, + found = (char*)php_memnstr(haystack->val + offset, needle_char, 1, - haystack + haystack_len); + haystack->val + haystack->len); } if (found) { - RETURN_LONG(found - haystack); + RETURN_LONG(found - haystack->val); } else { RETURN_FALSE; } @@ -1859,38 +1858,37 @@ PHP_FUNCTION(strpos) PHP_FUNCTION(stripos) { char *found = NULL; - char *haystack; - int haystack_len; - long offset = 0; + zend_string *haystack; + zend_long offset = 0; char *needle_dup = NULL, *haystack_dup; char needle_char[2]; zval *needle; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &needle, &offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|l", &haystack, &needle, &offset) == FAILURE) { return; } - if (offset < 0 || offset > haystack_len) { + if (offset < 0 || offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string"); RETURN_FALSE; } - if (haystack_len == 0) { + if (haystack->len == 0) { RETURN_FALSE; } - haystack_dup = estrndup(haystack, haystack_len); - php_strtolower(haystack_dup, haystack_len); + haystack_dup = estrndup(haystack->val, haystack->len); + php_strtolower(haystack_dup, haystack->len); if (Z_TYPE_P(needle) == IS_STRING) { - if (Z_STRLEN_P(needle) == 0 || Z_STRLEN_P(needle) > haystack_len) { + if (Z_STRLEN_P(needle) == 0 || Z_STRLEN_P(needle) > haystack->len) { efree(haystack_dup); RETURN_FALSE; } needle_dup = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); php_strtolower(needle_dup, Z_STRLEN_P(needle)); - found = (char*)php_memnstr(haystack_dup + offset, needle_dup, Z_STRLEN_P(needle), haystack_dup + haystack_len); + found = (char*)php_memnstr(haystack_dup + offset, needle_dup, Z_STRLEN_P(needle), haystack_dup + haystack->len); } else { if (php_needle_char(needle, needle_char TSRMLS_CC) != SUCCESS) { efree(haystack_dup); @@ -1901,7 +1899,7 @@ PHP_FUNCTION(stripos) found = (char*)php_memnstr(haystack_dup + offset, needle_char, sizeof(needle_char) - 1, - haystack_dup + haystack_len); + haystack_dup + haystack->len); } efree(haystack_dup); @@ -1922,18 +1920,19 @@ PHP_FUNCTION(stripos) PHP_FUNCTION(strrpos) { zval *zneedle; - char *needle, *haystack; - int needle_len, haystack_len; - long offset = 0; + char *needle; + zend_string *haystack; + size_t needle_len; + zend_long offset = 0; char *p, *e, ord_needle[2]; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &zneedle, &offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } #else ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_STRING(haystack, haystack_len) + Z_PARAM_STR(haystack) Z_PARAM_ZVAL(zneedle) Z_PARAM_OPTIONAL Z_PARAM_LONG(offset) @@ -1952,28 +1951,28 @@ PHP_FUNCTION(strrpos) needle_len = 1; } - if ((haystack_len == 0) || (needle_len == 0)) { + if ((haystack->len == 0) || (needle_len == 0)) { RETURN_FALSE; } if (offset >= 0) { - if (offset > haystack_len) { + if (offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } - p = haystack + offset; - e = haystack + haystack_len - needle_len; + p = haystack->val + offset; + e = haystack->val + haystack->len - needle_len; } else { - if (offset < -INT_MAX || -offset > haystack_len) { + if (offset < -INT_MAX || -offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } - p = haystack; + p = haystack->val; if (needle_len > -offset) { - e = haystack + haystack_len - needle_len; + e = haystack->val + haystack->len - needle_len; } else { - e = haystack + haystack_len + offset; + e = haystack->val + haystack->len + offset; } } @@ -2004,13 +2003,14 @@ PHP_FUNCTION(strrpos) PHP_FUNCTION(strripos) { zval *zneedle; - char *needle, *haystack; - int needle_len, haystack_len; - long offset = 0; + char *needle; + zend_string *haystack; + size_t needle_len; + zend_long offset = 0; char *p, *e, ord_needle[2]; char *needle_dup, *haystack_dup; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &zneedle, &offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz|l", &haystack, &zneedle, &offset) == FAILURE) { RETURN_FALSE; } @@ -2026,7 +2026,7 @@ PHP_FUNCTION(strripos) needle_len = 1; } - if ((haystack_len == 0) || (needle_len == 0)) { + if ((haystack->len == 0) || (needle_len == 0)) { RETURN_FALSE; } @@ -2034,19 +2034,19 @@ PHP_FUNCTION(strripos) /* Single character search can shortcut memcmps Can also avoid tolower emallocs */ if (offset >= 0) { - if (offset > haystack_len) { + if (offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } - p = haystack + offset; - e = haystack + haystack_len - 1; + p = haystack->val + offset; + e = haystack->val + haystack->len - 1; } else { - p = haystack; - if (offset < -INT_MAX || -offset > haystack_len) { + p = haystack->val; + if (offset < -INT_MAX || -offset > haystack->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } - e = haystack + haystack_len + offset; + e = haystack->val + haystack->len + offset; } /* Borrow that ord_needle buffer to avoid repeatedly tolower()ing needle */ *ord_needle = tolower(*needle); @@ -2061,20 +2061,20 @@ PHP_FUNCTION(strripos) needle_dup = estrndup(needle, needle_len); php_strtolower(needle_dup, needle_len); - haystack_dup = estrndup(haystack, haystack_len); - php_strtolower(haystack_dup, haystack_len); + haystack_dup = estrndup(haystack->val, haystack->len); + php_strtolower(haystack_dup, haystack->len); if (offset >= 0) { - if (offset > haystack_len) { + if (offset > haystack->len) { efree(needle_dup); efree(haystack_dup); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); RETURN_FALSE; } p = haystack_dup + offset; - e = haystack_dup + haystack_len - needle_len; + e = haystack_dup + haystack->len - needle_len; } else { - if (offset < -INT_MAX || -offset > haystack_len) { + if (offset < -INT_MAX || -offset > haystack->len) { efree(needle_dup); efree(haystack_dup); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset is greater than the length of haystack string"); @@ -2082,9 +2082,9 @@ PHP_FUNCTION(strripos) } p = haystack_dup; if (needle_len > -offset) { - e = haystack_dup + haystack_len - needle_len; + e = haystack_dup + haystack->len - needle_len; } else { - e = haystack_dup + haystack_len + offset; + e = haystack_dup + haystack->len + offset; } } @@ -2108,29 +2108,28 @@ PHP_FUNCTION(strripos) PHP_FUNCTION(strrchr) { zval *needle; - char *haystack; + zend_string *haystack; const char *found = NULL; - long found_offset; - int haystack_len; + zend_long found_offset; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &haystack, &haystack_len, &needle) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sz", &haystack, &needle) == FAILURE) { return; } if (Z_TYPE_P(needle) == IS_STRING) { - found = zend_memrchr(haystack, *Z_STRVAL_P(needle), haystack_len); + found = zend_memrchr(haystack->val, *Z_STRVAL_P(needle), haystack->len); } else { char needle_chr; if (php_needle_char(needle, &needle_chr TSRMLS_CC) != SUCCESS) { RETURN_FALSE; } - found = zend_memrchr(haystack, needle_chr, haystack_len); + found = zend_memrchr(haystack->val, needle_chr, haystack->len); } if (found) { - found_offset = found - haystack; - RETURN_STRINGL(found, haystack_len - found_offset); + found_offset = found - haystack->val; + RETURN_STRINGL(found, haystack->len - found_offset); } else { RETURN_FALSE; } @@ -2139,12 +2138,12 @@ PHP_FUNCTION(strrchr) /* {{{ php_chunk_split */ -static zend_string *php_chunk_split(char *src, int srclen, char *end, int endlen, int chunklen) +static zend_string *php_chunk_split(char *src, size_t srclen, char *end, size_t endlen, size_t chunklen) { char *p, *q; - int chunks; /* complete chunks! */ - int restlen; - int out_len; + size_t chunks; /* complete chunks! */ + size_t restlen; + size_t out_len; zend_string *dest; chunks = srclen / chunklen; @@ -2163,7 +2162,7 @@ static zend_string *php_chunk_split(char *src, int srclen, char *end, int endlen } out_len += srclen + 1; - dest = STR_ALLOC(out_len * sizeof(char), 0); + dest = zend_string_alloc(out_len * sizeof(char), 0); for (p = src, q = dest->val; p < (src + srclen - chunklen + 1); ) { memcpy(q, p, chunklen); @@ -2191,14 +2190,13 @@ static zend_string *php_chunk_split(char *src, int srclen, char *end, int endlen Returns split line */ PHP_FUNCTION(chunk_split) { - char *str; + zend_string *str; char *end = "\r\n"; int endlen = 2; - long chunklen = 76; - int str_len; + zend_long chunklen = 76; zend_string *result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, &chunklen, &end, &endlen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ls", &str, &chunklen, &end, &endlen) == FAILURE) { return; } @@ -2207,20 +2205,20 @@ PHP_FUNCTION(chunk_split) RETURN_FALSE; } - if (chunklen > str_len) { + if (chunklen > str->len) { /* to maintain BC, we must return original string + ending */ - result = STR_ALLOC(endlen + str_len, 0); - memcpy(result->val, str, str_len); - memcpy(result->val + str_len, end, endlen); + result = zend_string_alloc(endlen + str->len, 0); + memcpy(result->val, str->val, str->len); + memcpy(result->val + str->len, end, endlen); result->val[result->len] = '\0'; RETURN_NEW_STR(result); } - if (!str_len) { + if (!str->len) { RETURN_EMPTY_STRING(); } - result = php_chunk_split(str, str_len, end, endlen, chunklen); + result = php_chunk_split(str->val, str->len, end, endlen, chunklen); if (result) { RETURN_STR(result); @@ -2234,18 +2232,17 @@ PHP_FUNCTION(chunk_split) Returns part of a string */ PHP_FUNCTION(substr) { - char *str; - long l = 0, f; - int str_len; + zend_string *str; + zend_long l = 0, f; int argc = ZEND_NUM_ARGS(); #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &str, &str_len, &f, &l) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl|l", &str, &f, &l) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(2, 3) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) Z_PARAM_LONG(f) Z_PARAM_OPTIONAL Z_PARAM_LONG(l) @@ -2253,22 +2250,22 @@ PHP_FUNCTION(substr) #endif if (argc > 2) { - if ((l < 0 && -l > str_len)) { + if ((l < 0 && -l > str->len)) { RETURN_FALSE; - } else if (l > str_len) { - l = str_len; + } else if (l > (zend_long)str->len) { + l = str->len; } } else { - l = str_len; + l = str->len; } - if (f > str_len) { + if (f > (zend_long)str->len) { RETURN_FALSE; - } else if (f < 0 && -f > str_len) { + } else if (f < 0 && -f > str->len) { f = 0; } - if (l < 0 && (l + str_len - f) < 0) { + if (l < 0 && (l + (zend_long)str->len - f) < 0) { RETURN_FALSE; } @@ -2276,7 +2273,7 @@ PHP_FUNCTION(substr) * of the string */ if (f < 0) { - f = str_len + f; + f = (zend_long)str->len + f; if (f < 0) { f = 0; } @@ -2286,21 +2283,21 @@ PHP_FUNCTION(substr) * needed to stop that many chars from the end of the string */ if (l < 0) { - l = (str_len - f) + l; + l = ((zend_long)str->len - f) + l; if (l < 0) { l = 0; } } - if (f >= str_len) { + if (f >= (zend_long)str->len) { RETURN_FALSE; } - if ((f + l) > str_len) { - l = str_len - f; + if ((f + l) > (zend_long)str->len) { + l = str->len - f; } - RETURN_STRINGL(str + f, l); + RETURN_STRINGL(str->val + f, l); } /* }}} */ @@ -2312,8 +2309,8 @@ PHP_FUNCTION(substr_replace) zval *from; zval *len = NULL; zval *repl; - int l = 0; - int f; + zend_long l = 0; /* l and f should be size_t, however this needs much closer below logic investigation.*/ + zend_long f; int argc = ZEND_NUM_ARGS(); zend_string *result; @@ -2331,7 +2328,7 @@ PHP_FUNCTION(substr_replace) convert_to_string_ex(repl); } if (Z_TYPE_P(from) != IS_ARRAY) { - convert_to_long_ex(from); + convert_to_int_ex(from); } if (argc > 3) { @@ -2350,19 +2347,19 @@ PHP_FUNCTION(substr_replace) (argc == 4 && Z_TYPE_P(from) != Z_TYPE_P(len)) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should be of same type - numerical or array "); - RETURN_STR(STR_COPY(Z_STR_P(str))); + RETURN_STR(zend_string_copy(Z_STR_P(str))); } if (argc == 4 && Z_TYPE_P(from) == IS_ARRAY) { if (zend_hash_num_elements(Z_ARRVAL_P(from)) != zend_hash_num_elements(Z_ARRVAL_P(len))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "'from' and 'len' should have the same number of elements"); - RETURN_STR(STR_COPY(Z_STR_P(str))); + RETURN_STR(zend_string_copy(Z_STR_P(str))); } } } if (Z_TYPE_P(str) != IS_ARRAY) { if (Z_TYPE_P(from) != IS_ARRAY) { - int repl_len = 0; + size_t repl_len = 0; f = Z_LVAL_P(from); @@ -2406,7 +2403,7 @@ PHP_FUNCTION(substr_replace) repl_len = Z_STRLEN_P(repl); } - result = STR_ALLOC(Z_STRLEN_P(str) - l + repl_len, 0); + result = zend_string_alloc(Z_STRLEN_P(str) - l + repl_len, 0); memcpy(result->val, Z_STRVAL_P(str), f); if (repl_len) { @@ -2417,12 +2414,12 @@ PHP_FUNCTION(substr_replace) RETURN_NEW_STR(result); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Functionality of 'from' and 'len' as arrays is not implemented"); - RETURN_STR(STR_COPY(Z_STR_P(str))); + RETURN_STR(zend_string_copy(Z_STR_P(str))); } } else { /* str is array of strings */ zend_string *str_index = NULL; - ulong num_index; - int result_len; + size_t result_len; + zend_ulong num_index; array_init(return_value); @@ -2538,7 +2535,7 @@ PHP_FUNCTION(substr_replace) result_len += Z_STRLEN_P(repl_str); zend_hash_move_forward_ex(Z_ARRVAL_P(repl), &pos_repl); - result = STR_ALLOC(result_len, 0); + result = zend_string_alloc(result_len, 0); memcpy(result->val, Z_STRVAL_P(orig_str), f); memcpy((result->val + f), Z_STRVAL_P(repl_str), Z_STRLEN_P(repl_str)); @@ -2547,7 +2544,7 @@ PHP_FUNCTION(substr_replace) zval_dtor(repl_str); } } else { - result = STR_ALLOC(result_len, 0); + result = zend_string_alloc(result_len, 0); memcpy(result->val, Z_STRVAL_P(orig_str), f); memcpy((result->val + f), Z_STRVAL_P(orig_str) + f + l, Z_STRLEN_P(orig_str) - f - l); @@ -2555,7 +2552,7 @@ PHP_FUNCTION(substr_replace) } else { result_len += Z_STRLEN_P(repl); - result = STR_ALLOC(result_len, 0); + result = zend_string_alloc(result_len, 0); memcpy(result->val, Z_STRVAL_P(orig_str), f); memcpy((result->val + f), Z_STRVAL_P(repl), Z_STRLEN_P(repl)); @@ -2587,26 +2584,25 @@ PHP_FUNCTION(substr_replace) Quotes meta characters */ PHP_FUNCTION(quotemeta) { - char *old; + zend_string *old; char *old_end; char *p, *q; char c; - int old_len; zend_string *str; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &old, &old_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &old) == FAILURE) { return; } - old_end = old + old_len; + old_end = old->val + old->len; - if (old == old_end) { + if (old->val == old_end) { RETURN_FALSE; } - str = STR_ALLOC(2 * old_len, 0); + str = zend_string_alloc(2 * old->len, 0); - for (p = old, q = str->val; p != old_end; p++) { + for (p = old->val, q = str->val; p != old_end; p++) { c = *p; switch (c) { case '.': @@ -2629,7 +2625,7 @@ PHP_FUNCTION(quotemeta) *q = '\0'; - RETURN_NEW_STR(STR_REALLOC(str, q - str->val, 0)); + RETURN_NEW_STR(zend_string_realloc(str, q - str->val, 0)); } /* }}} */ @@ -2658,7 +2654,7 @@ PHP_FUNCTION(ord) Converts ASCII code to a character */ PHP_FUNCTION(chr) { - long c; + zend_long c; char temp[2]; if (ZEND_NUM_ARGS() != 1) { @@ -2690,24 +2686,23 @@ static void php_ucfirst(char *str) Makes a string's first character uppercase */ PHP_FUNCTION(ucfirst) { - char *str; - int str_len; + zend_string *str; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif - if (!str_len) { + if (!str->len) { RETURN_EMPTY_STRING(); } - ZVAL_STRINGL(return_value, str, str_len); + ZVAL_STRINGL(return_value, str->val, str->len); php_ucfirst(Z_STRVAL_P(return_value)); } /* }}} */ @@ -2726,18 +2721,17 @@ static void php_lcfirst(char *str) Make a string's first character lowercase */ PHP_FUNCTION(lcfirst) { - char *str; - int str_len; + zend_string *str; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } - if (!str_len) { + if (!str->len) { RETURN_EMPTY_STRING(); } - ZVAL_STRINGL(return_value, str, str_len); + ZVAL_STRINGL(return_value, str->val, str->len); php_lcfirst(Z_STRVAL_P(return_value)); } /* }}} */ @@ -2746,30 +2740,31 @@ PHP_FUNCTION(lcfirst) Uppercase the first character of every word in a string */ PHP_FUNCTION(ucwords) { - char *str, *delims = " \t\r\n\f\v"; + zend_string *str; + char *delims = " \t\r\n\f\v"; register char *r, *r_end; - int str_len, delims_len = 6; + int delims_len = 6; char mask[256]; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &delims, &delims_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|s", &str, &delims, &delims_len) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 2) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) Z_PARAM_OPTIONAL Z_PARAM_STRING(delims, delims_len) ZEND_PARSE_PARAMETERS_END(); #endif - if (!str_len) { + if (!str->len) { RETURN_EMPTY_STRING(); } php_charmask((unsigned char *)delims, delims_len, mask TSRMLS_CC); - ZVAL_STRINGL(return_value, str, str_len); + ZVAL_STRINGL(return_value, str->val, str->len); r = Z_STRVAL_P(return_value); *r = toupper((unsigned char) *r); @@ -2783,9 +2778,9 @@ PHP_FUNCTION(ucwords) /* {{{ php_strtr */ -PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen) +PHPAPI char *php_strtr(char *str, size_t len, char *str_from, char *str_to, size_t trlen) { - int i; + size_t i; unsigned char xlat[256]; if ((trlen < 1) || (len < 1)) { @@ -2816,14 +2811,14 @@ static int php_strtr_key_compare(const void *a, const void *b TSRMLS_DC) /* {{{ /* }}} */ /* {{{ php_strtr_array */ -static void php_strtr_array(zval *return_value, char *str, int slen, HashTable *pats TSRMLS_DC) +static void php_strtr_array(zval *return_value, char *str, size_t slen, HashTable *pats TSRMLS_DC) { - ulong num_key; + zend_ulong num_key; zend_string *str_key; - int len, pos, found; + size_t len, pos, found; int num_keys = 0; - int minlen = 128*1024; - int maxlen = 0; + size_t minlen = 128*1024; + size_t maxlen = 0; HashTable str_hash, num_hash; zval *entry, tmp, dummy; char *key; @@ -2920,7 +2915,7 @@ static void php_strtr_array(zval *return_value, char *str, int slen, HashTable * smart_str_appendl(&result, str->val, str->len); pos += len; found = 1; - STR_RELEASE(str); + zend_string_release(str); break; } } ZEND_HASH_FOREACH_END(); @@ -2945,7 +2940,7 @@ static void php_strtr_array(zval *return_value, char *str, int slen, HashTable * smart_str_appendl(&result, str->val, str->len); pos += len; found = 1; - STR_RELEASE(str); + zend_string_release(str); break; } } @@ -3018,21 +3013,20 @@ PHP_FUNCTION(strtr) Reverse a string */ PHP_FUNCTION(strrev) { - char *str; + zend_string *str; char *e, *p; - int str_len; zend_string *n; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } - n = STR_ALLOC(str_len, 0); + n = zend_string_alloc(str->len, 0); p = n->val; - e = str + str_len; + e = str->val + str->len; - while (--e>=str) { + while (--e>=str->val) { *p++ = *e; } @@ -3044,12 +3038,12 @@ PHP_FUNCTION(strrev) /* {{{ php_similar_str */ -static void php_similar_str(const char *txt1, int len1, const char *txt2, int len2, int *pos1, int *pos2, int *max) +static void php_similar_str(const char *txt1, size_t len1, const char *txt2, size_t len2, size_t *pos1, size_t *pos2, size_t *max) { char *p, *q; char *end1 = (char *) txt1 + len1; char *end2 = (char *) txt2 + len2; - int l; + size_t l; *max = 0; for (p = (char *) txt1; p < end1; p++) { @@ -3067,10 +3061,10 @@ static void php_similar_str(const char *txt1, int len1, const char *txt2, int le /* {{{ php_similar_char */ -static int php_similar_char(const char *txt1, int len1, const char *txt2, int len2) +static size_t php_similar_char(const char *txt1, size_t len1, const char *txt2, size_t len2) { - int sum; - int pos1 = 0, pos2 = 0, max; + size_t sum; + size_t pos1 = 0, pos2 = 0, max; php_similar_str(txt1, len1, txt2, len2, &pos1, &pos2, &max); if ((sum = max)) { @@ -3092,13 +3086,12 @@ static int php_similar_char(const char *txt1, int len1, const char *txt2, int le Calculates the similarity between two strings */ PHP_FUNCTION(similar_text) { - char *t1, *t2; + zend_string *t1, *t2; zval *percent = NULL; int ac = ZEND_NUM_ARGS(); - int sim; - int t1_len, t2_len; + size_t sim; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z/", &t1, &t1_len, &t2, &t2_len, &percent) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/", &t1, &t2, &percent) == FAILURE) { return; } @@ -3106,7 +3099,7 @@ PHP_FUNCTION(similar_text) convert_to_double_ex(percent); } - if (t1_len + t2_len == 0) { + if (t1->len + t2->len == 0) { if (ac > 2) { Z_DVAL_P(percent) = 0; } @@ -3114,10 +3107,10 @@ PHP_FUNCTION(similar_text) RETURN_LONG(0); } - sim = php_similar_char(t1, t1_len, t2, t2_len); + sim = php_similar_char(t1->val, t1->len, t2->val, t2->len); if (ac > 2) { - Z_DVAL_P(percent) = sim * 200.0 / (t1_len + t2_len); + Z_DVAL_P(percent) = sim * 200.0 / (t1->len + t2->len); } RETURN_LONG(sim); @@ -3127,10 +3120,10 @@ PHP_FUNCTION(similar_text) /* {{{ php_stripslashes * * be careful, this edits the string in-place */ -PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC) +PHPAPI void php_stripslashes(char *str, size_t *len TSRMLS_DC) { char *s, *t; - int l; + size_t l; if (len != NULL) { l = *len; @@ -3171,22 +3164,21 @@ PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC) Escapes all chars mentioned in charlist with backslash. It creates octal representations if asked to backslash characters with 8th bit set or with ASCII<32 (except '\n', '\r', '\t' etc...) */ PHP_FUNCTION(addcslashes) { - char *str, *what; - int str_len, what_len; + zend_string *str, *what; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &str, &str_len, &what, &what_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &str, &what) == FAILURE) { return; } - if (str_len == 0) { + if (str->len == 0) { RETURN_EMPTY_STRING(); } - if (what_len == 0) { - RETURN_STRINGL(str, str_len); + if (what->len == 0) { + RETURN_STRINGL(str->val, str->len); } - RETURN_STR(php_addcslashes(str, str_len, 0, what, what_len TSRMLS_CC)); + RETURN_STR(php_addcslashes(str->val, str->len, 0, what->val, what->len TSRMLS_CC)); } /* }}} */ @@ -3194,24 +3186,23 @@ PHP_FUNCTION(addcslashes) Escapes single quote, double quotes and backslash characters in a string with backslashes */ PHP_FUNCTION(addslashes) { - char *str; - int str_len; + zend_string *str; #ifndef FAST_ZPP - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } #else ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(str, str_len) + Z_PARAM_STR(str) ZEND_PARSE_PARAMETERS_END(); #endif - if (str_len == 0) { + if (str->len == 0) { RETURN_EMPTY_STRING(); } - RETURN_STR(php_addslashes(str, str_len, 0 TSRMLS_CC)); + RETURN_STR(php_addslashes(str->val, str->len, 0 TSRMLS_CC)); } /* }}} */ @@ -3219,14 +3210,13 @@ PHP_FUNCTION(addslashes) Strips backslashes from a string. Uses C-style conventions */ PHP_FUNCTION(stripcslashes) { - char *str; - int str_len; + zend_string *str; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } - ZVAL_STRINGL(return_value, str, str_len); + ZVAL_STRINGL(return_value, str->val, str->len); php_stripcslashes(Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value)); } /* }}} */ @@ -3235,14 +3225,13 @@ PHP_FUNCTION(stripcslashes) Strips backslashes from a string */ PHP_FUNCTION(stripslashes) { - char *str; - int str_len; + zend_string *str; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) { return; } - ZVAL_STRINGL(return_value, str, str_len); + ZVAL_STRINGL(return_value, str->val, str->len); php_stripslashes(Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value) TSRMLS_CC); } /* }}} */ @@ -3268,10 +3257,10 @@ char *php_strerror(int errnum) /* {{{ php_stripcslashes */ -PHPAPI void php_stripcslashes(char *str, int *len) +PHPAPI void php_stripcslashes(char *str, size_t *len) { char *source, *target, *end; - int nlen = *len, i; + size_t nlen = *len, i; char numtmp[4]; for (source=str, end=str+nlen, target=str; source < end; source++) { @@ -3331,14 +3320,14 @@ PHPAPI void php_stripcslashes(char *str, int *len) /* {{{ php_addcslashes */ -PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free, char *what, int wlength TSRMLS_DC) +PHPAPI zend_string *php_addcslashes(const char *str, size_t length, int should_free, char *what, size_t wlength TSRMLS_DC) { char flags[256]; char *source, *target; char *end; char c; - int newlen; - zend_string *new_str = STR_ALLOC(4 * (length? length : (length = strlen(str))), 0); + size_t newlen; + zend_string *new_str = zend_string_alloc(4 * (length? length : (length = strlen(str))), 0); if (!wlength) { wlength = strlen(what); @@ -3370,7 +3359,7 @@ PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free *target = 0; newlen = target - new_str->val; if (newlen < length * 4) { - new_str = STR_REALLOC(new_str, newlen, 0); + new_str = zend_string_realloc(new_str, newlen, 0); } if (should_free) { efree((char*)str); @@ -3381,7 +3370,7 @@ PHPAPI zend_string *php_addcslashes(const char *str, int length, int should_free /* {{{ php_addslashes */ -PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS_DC) +PHPAPI zend_string *php_addslashes(char *str, size_t length, int should_free TSRMLS_DC) { /* maximum string length, worst case situation */ char *source, *target; @@ -3392,7 +3381,7 @@ PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS return STR_EMPTY_ALLOC(); } - new_str = STR_ALLOC(2 * (length ? length : (length = strlen(str))), 0); + new_str = zend_string_alloc(2 * (length ? length : (length = strlen(str))), 0); source = str; end = source + length; target = new_str->val; @@ -3420,7 +3409,7 @@ PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS if (should_free) { efree(str); } - new_str = STR_REALLOC(new_str, target - new_str->val, 0); + new_str = zend_string_realloc(new_str, target - new_str->val, 0); return new_str; } @@ -3434,10 +3423,10 @@ PHPAPI zend_string *php_addslashes(char *str, int length, int should_free TSRMLS /* {{{ php_char_to_str_ex */ -PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count) +PHPAPI size_t php_char_to_str_ex(char *str, size_t len, char from, char *to, size_t to_len, zval *result, int case_sensitivity, size_t *replace_count) { - int char_count = 0; - int replaced = 0; + size_t char_count = 0; + size_t replaced = 0; char *source, *target, *tmp, *source_end=str+len, *tmp_end = NULL; if (case_sensitivity) { @@ -3460,9 +3449,9 @@ PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_l } if (to_len > 0) { - ZVAL_NEW_STR(result, STR_SAFE_ALLOC(char_count, to_len - 1, len, 0)); + ZVAL_NEW_STR(result, zend_string_safe_alloc(char_count, to_len - 1, len, 0)); } else { - ZVAL_NEW_STR(result, STR_ALLOC(len - char_count, 0)); + ZVAL_NEW_STR(result, zend_string_alloc(len - char_count, 0)); } target = Z_STRVAL_P(result); @@ -3507,7 +3496,7 @@ PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_l /* {{{ php_char_to_str */ -PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result) +PHPAPI size_t php_char_to_str(char *str, size_t len, char from, char *to, size_t to_len, zval *result) { return php_char_to_str_ex(str, len, from, to, to_len, result, 1, NULL); } @@ -3515,8 +3504,8 @@ PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, /* {{{ php_str_to_str_ex */ -PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, - char *needle, int needle_len, char *str, int str_len, int case_sensitivity, int *replace_count) +PHPAPI zend_string *php_str_to_str_ex(char *haystack, size_t length, + char *needle, size_t needle_len, char *str, size_t str_len, int case_sensitivity, size_t *replace_count) { zend_string *new_str; @@ -3525,7 +3514,7 @@ PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, char *e, *s, *p, *r; if (needle_len == str_len) { - new_str = STR_INIT(haystack, length, 0); + new_str = zend_string_init(haystack, length, 0); if (case_sensitivity) { end = new_str->val + length; @@ -3560,9 +3549,9 @@ PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, } if (str_len < needle_len) { - new_str = STR_ALLOC(length, 0); + new_str = zend_string_alloc(length, 0); } else { - int count = 0; + size_t count = 0; char *o, *n, *endp; if (case_sensitivity) { @@ -3586,10 +3575,10 @@ PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, if (needle_dup) { efree(needle_dup); } - new_str = STR_INIT(haystack, length, 0); + new_str = zend_string_init(haystack, length, 0); return new_str; } else { - new_str = STR_ALLOC(count * (str_len - needle_len) + length, 0); + new_str = zend_string_alloc(count * (str_len - needle_len) + length, 0); } } @@ -3639,12 +3628,12 @@ PHPAPI zend_string *php_str_to_str_ex(char *haystack, int length, *e = '\0'; - new_str = STR_REALLOC(new_str, e - s, 0); + new_str = zend_string_realloc(new_str, e - s, 0); return new_str; } } else if (needle_len > length) { nothing_todo: - new_str = STR_INIT(haystack, length, 0); + new_str = zend_string_init(haystack, length, 0); return new_str; } else { if (case_sensitivity && memcmp(haystack, needle, length)) { @@ -3667,7 +3656,7 @@ nothing_todo: efree(l_needle); } - new_str = STR_INIT(str, str_len, 0); + new_str = zend_string_init(str, str_len, 0); if (replace_count) { (*replace_count)++; @@ -3680,7 +3669,7 @@ nothing_todo: /* {{{ php_str_to_str */ -PHPAPI zend_string *php_str_to_str(char *haystack, int length, char *needle, int needle_len, char *str, int str_len) +PHPAPI zend_string *php_str_to_str(char *haystack, size_t length, char *needle, size_t needle_len, char *str, size_t str_len) { return php_str_to_str_ex(haystack, length, needle, needle_len, str, str_len, 1, NULL); } @@ -3688,14 +3677,14 @@ PHPAPI zend_string *php_str_to_str(char *haystack, int length, char *needle, int /* {{{ php_str_replace_in_subject */ -static void php_str_replace_in_subject(zval *search, zval *replace, zval *subject, zval *result, int case_sensitivity, int *replace_count TSRMLS_DC) +static void php_str_replace_in_subject(zval *search, zval *replace, zval *subject, zval *result, int case_sensitivity, size_t *replace_count TSRMLS_DC) { zval *search_entry, *replace_entry = NULL, temp_result, tmp_subject; char *replace_value = NULL; - int replace_len = 0; + size_t replace_len = 0; HashPosition pos; /* Make sure we're dealing with strings. */ @@ -3774,7 +3763,7 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval *subjec replace_value, replace_len, case_sensitivity, replace_count)); } - STR_FREE(Z_STR_P(result)); + zend_string_free(Z_STR_P(result)); Z_STR_P(result) = Z_STR(temp_result); Z_TYPE_INFO_P(result) = Z_TYPE_INFO(temp_result); @@ -3812,8 +3801,8 @@ static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensit zval *subject, *search, *replace, *subject_entry, *zcount = NULL; zval result; zend_string *string_key; - ulong num_key; - int count = 0; + zend_ulong num_key; + zend_long count = 0; int argc = ZEND_NUM_ARGS(); #ifndef FAST_ZPP @@ -3898,7 +3887,7 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines) char *str; char *heb_str, *tmp, *target; int block_start, block_end, block_type, block_length, i; - long max_chars=0; + zend_long max_chars=0; int begin, end, char_count, orig_begin; int str_len; zend_string *broken_str; @@ -3993,7 +3982,7 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines) } while (block_end < str_len-1); - broken_str = STR_ALLOC(str_len, 0); + broken_str = zend_string_alloc(str_len, 0); begin = end = str_len-1; target = broken_str->val; @@ -4053,7 +4042,7 @@ static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines) if (convert_newlines) { php_char_to_str(broken_str->val, broken_str->len,'\n', "<br />\n", 7, return_value); - STR_FREE(broken_str); + zend_string_free(broken_str); } else { RETURN_NEW_STR(broken_str); } @@ -4081,19 +4070,19 @@ PHP_FUNCTION(hebrevc) PHP_FUNCTION(nl2br) { /* in brief this inserts <br /> or <br> before matched regexp \n\r?|\r\n? */ - char *tmp, *str; + char *tmp; + zend_string *str; char *end, *target; - int repl_cnt = 0; - int str_len; + size_t repl_cnt = 0; zend_bool is_xhtml = 1; zend_string *result; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &str, &str_len, &is_xhtml) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|b", &str, &is_xhtml) == FAILURE) { return; } - tmp = str; - end = str + str_len; + tmp = str->val; + end = str->val + str->len; /* it is really faster to scan twice and allocate mem once instead of scanning once and constantly reallocing */ @@ -4114,18 +4103,19 @@ PHP_FUNCTION(nl2br) } if (repl_cnt == 0) { - RETURN_STRINGL(str, str_len); + RETURN_STRINGL(str->val, str->len); } { size_t repl_len = is_xhtml ? (sizeof("<br />") - 1) : (sizeof("<br>") - 1); - result = STR_ALLOC(repl_cnt * repl_len + str_len, 0); + result = zend_string_alloc(repl_cnt * repl_len + str->len, 0); target = result->val; } - while (str < end) { - switch (*str) { + tmp = str->val; + while (tmp < end) { + switch (*tmp) { case '\r': case '\n': *target++ = '<'; @@ -4139,15 +4129,15 @@ PHP_FUNCTION(nl2br) *target++ = '>'; - if ((*str == '\r' && *(str+1) == '\n') || (*str == '\n' && *(str+1) == '\r')) { - *target++ = *str++; + if ((*tmp == '\r' && *(tmp+1) == '\n') || (*tmp == '\n' && *(tmp+1) == '\r')) { + *target++ = *tmp++; } /* lack of a break; is intentional */ default: - *target++ = *str; + *target++ = *tmp; } - str++; + tmp++; } *target = '\0'; @@ -4161,13 +4151,12 @@ PHP_FUNCTION(nl2br) PHP_FUNCTION(strip_tags) { zend_string *buf; - char *str; + zend_string *str; zval *allow=NULL; char *allowed_tags=NULL; int allowed_tags_len=0; - int str_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &str, &str_len, &allow) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &allow) == FAILURE) { return; } @@ -4184,8 +4173,8 @@ PHP_FUNCTION(strip_tags) } } - buf = STR_INIT(str, str_len, 0); - buf->len = php_strip_tags_ex(buf->val, str_len, NULL, allowed_tags, allowed_tags_len, 0); + buf = zend_string_init(str->val, str->len, 0); + buf->len = php_strip_tags_ex(buf->val, str->len, NULL, allowed_tags, allowed_tags_len, 0); // TODO: reimplement to avoid reallocation ??? if (allow && IS_INTERNED(Z_STR_P(allow))) { @@ -4284,7 +4273,7 @@ PHP_FUNCTION(setlocale) if (retval) { /* Remember if locale was changed */ if (loc) { -//??? STR_FREE(BG(locale_string)); +//??? zend_string_free(BG(locale_string)); if (BG(locale_string)) { efree(BG(locale_string)); } @@ -4352,7 +4341,7 @@ PHP_FUNCTION(parse_str) * 0 start tag * 1 first non-whitespace char seen */ -int php_tag_find(char *tag, int len, char *set) { +int php_tag_find(char *tag, size_t len, char *set) { char c, *n, *t; int state=0, done=0; char *norm; @@ -4407,7 +4396,7 @@ int php_tag_find(char *tag, int len, char *set) { } /* }}} */ -PHPAPI size_t php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int allow_len) /* {{{ */ +PHPAPI size_t php_strip_tags(char *rbuf, size_t len, int *stateptr, char *allow, size_t allow_len) /* {{{ */ { return php_strip_tags_ex(rbuf, len, stateptr, allow, allow_len, 0); } @@ -4433,7 +4422,7 @@ PHPAPI size_t php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, in swm: Added ability to strip <?xml tags without assuming it PHP code. */ -PHPAPI size_t php_strip_tags_ex(char *rbuf, int len, int *stateptr, char *allow, int allow_len, zend_bool allow_tag_spaces) +PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, int *stateptr, char *allow, size_t allow_len, zend_bool allow_tag_spaces) { char *tbuf, *buf, *p, *tp, *rp, c, lc; int br, i=0, depth=0, in_q = 0; @@ -4711,11 +4700,12 @@ reg_char: Parse a CSV string into an array */ PHP_FUNCTION(str_getcsv) { - char *str, delim = ',', enc = '"', esc = '\\'; + zend_string *str; + char delim = ',', enc = '"', esc = '\\'; char *delim_str = NULL, *enc_str = NULL, *esc_str = NULL; - int str_len = 0, delim_len = 0, enc_len = 0, esc_len = 0; + int delim_len = 0, enc_len = 0, esc_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sss", &str, &str_len, &delim_str, &delim_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|sss", &str, &delim_str, &delim_len, &enc_str, &enc_len, &esc_str, &esc_len) == FAILURE) { return; } @@ -4724,7 +4714,7 @@ PHP_FUNCTION(str_getcsv) enc = enc_len ? enc_str[0] : enc; esc = esc_len ? esc_str[0] : esc; - php_fgetcsv(NULL, delim, enc, esc, str_len, str, return_value TSRMLS_CC); + php_fgetcsv(NULL, delim, enc, esc, str->len, str->val, return_value TSRMLS_CC); } /* }}} */ @@ -4732,13 +4722,12 @@ PHP_FUNCTION(str_getcsv) Returns the input string repeat mult times */ PHP_FUNCTION(str_repeat) { - char *input_str; /* Input string */ - int input_len; - long mult; /* Multiplier */ + zend_string *input_str; /* Input string */ + zend_long mult; /* Multiplier */ zend_string *result; /* Resulting string */ size_t result_len; /* Length of the resulting string */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &input_str, &input_len, &mult) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl", &input_str, &mult) == FAILURE) { return; } @@ -4749,22 +4738,22 @@ PHP_FUNCTION(str_repeat) /* Don't waste our time if it's empty */ /* ... or if the multiplier is zero */ - if (input_len == 0 || mult == 0) + if (input_str->len == 0 || mult == 0) RETURN_EMPTY_STRING(); /* Initialize the result string */ - result = STR_SAFE_ALLOC(input_len, mult, 0, 0); - result_len = input_len * mult; + result = zend_string_safe_alloc(input_str->len, mult, 0, 0); + result_len = input_str->len * mult; /* Heavy optimization for situations where input string is 1 byte long */ - if (input_len == 1) { - memset(result->val, *(input_str), mult); + if (input_str->len == 1) { + memset(result->val, *(input_str->val), mult); } else { char *s, *e, *ee; - int l=0; - memcpy(result->val, input_str, input_len); + ptrdiff_t l=0; + memcpy(result->val, input_str->val, input_str->len); s = result->val; - e = result->val + input_len; + e = result->val + input_str->len; ee = result->val + result_len; while (e<ee) { @@ -4784,15 +4773,16 @@ PHP_FUNCTION(str_repeat) Returns info about what characters are used in input */ PHP_FUNCTION(count_chars) { - char *input; + zend_string *input; int chars[256]; - long mymode=0; + zend_long mymode=0; unsigned char *buf; - int len, inx; + int inx; char retstr[256]; - int retlen=0; + size_t retlen=0; + size_t tmp = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &input, &len, &mymode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &input, &mymode) == FAILURE) { return; } @@ -4801,13 +4791,13 @@ PHP_FUNCTION(count_chars) RETURN_FALSE; } - buf = (unsigned char *) input; + buf = (unsigned char *) input->val; memset((void*) chars, 0, sizeof(chars)); - while (len > 0) { + while (tmp < input->len) { chars[*buf]++; buf++; - len--; + tmp++; } if (mymode < 3) { @@ -4852,15 +4842,14 @@ PHP_FUNCTION(count_chars) */ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case) { - char *s1, *s2; - int s1_len, s2_len; + zend_string *s1, *s2; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &s1, &s1_len, &s2, &s2_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &s1, &s2) == FAILURE) { return; } - RETURN_LONG(strnatcmp_ex(s1, s1_len, - s2, s2_len, + RETURN_LONG(strnatcmp_ex(s1->val, s1->len, + s2->val, s2->len, fold_case)); } /* }}} */ @@ -4872,8 +4861,8 @@ PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2 ZVAL_LONG(result, strnatcmp_ex(str1->val, str1->len, str2->val, str2->len, case_insensitive)); - STR_RELEASE(str1); - STR_RELEASE(str2); + zend_string_release(str1); + zend_string_release(str2); return SUCCESS; } /* }}} */ @@ -4994,7 +4983,7 @@ PHP_FUNCTION(strnatcasecmp) PHP_FUNCTION(substr_count) { char *haystack, *needle; - long offset = 0, length = 0; + zend_long offset = 0, length = 0; int ac = ZEND_NUM_ARGS(); int count = 0; int haystack_len, needle_len; @@ -5018,7 +5007,7 @@ PHP_FUNCTION(substr_count) } if (offset > haystack_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset value %ld exceeds string length", offset); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset value " ZEND_LONG_FMT " exceeds string length", offset); RETURN_FALSE; } p += offset; @@ -5030,7 +5019,7 @@ PHP_FUNCTION(substr_count) RETURN_FALSE; } if (length > (haystack_len - offset)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length value %ld exceeds string length", length); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length value " ZEND_LONG_FMT " exceeds string length", length); RETURN_FALSE; } endp = p + length; @@ -5059,30 +5048,37 @@ PHP_FUNCTION(substr_count) PHP_FUNCTION(str_pad) { /* Input arguments */ - char *input; /* Input string */ - int input_len; - long pad_length; /* Length to pad to */ + zend_string *input; /* Input string */ + zend_long pad_length; /* Length to pad to */ /* Helper variables */ size_t num_pad_chars; /* Number of padding characters (total - input size) */ - char *pad_str_val = " "; /* Pointer to padding string */ - int pad_str_len = 1; /* Length of the padding string */ - long pad_type_val = STR_PAD_RIGHT; /* The padding type value */ + zend_string *pad_str, *pad_str_save; /* Pointer to padding string */ + zend_long pad_type_val = STR_PAD_RIGHT; /* The padding type value */ int i, left_pad=0, right_pad=0; zend_string *result = NULL; /* Resulting string */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|sl", &input, &input_len, &pad_length, - &pad_str_val, &pad_str_len, &pad_type_val) == FAILURE) { + pad_str = pad_str_save = zend_string_init(" ", 1, 1); + if (!pad_str) { + return; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl|Sl", &input, &pad_length, &pad_str, &pad_type_val) == FAILURE) { + zend_string_free(pad_str); return; } + if (pad_str != pad_str_save) { + zend_string_free(pad_str_save); + } + /* If resulting string turns out to be shorter than input string, we simply copy the input and return. */ - if (pad_length <= 0 || (pad_length - input_len) <= 0) { - RETURN_STRINGL(input, input_len); + if (pad_length < 0 || pad_length <= input->len) { + RETURN_STRINGL(input->val, input->len); } - if (pad_str_len == 0) { + if (pad_str->len == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Padding string cannot be empty"); return; } @@ -5092,13 +5088,13 @@ PHP_FUNCTION(str_pad) return; } - num_pad_chars = pad_length - input_len; + num_pad_chars = pad_length - input->len; if (num_pad_chars >= INT_MAX) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Padding length is too long"); return; } - result = STR_ALLOC(input_len + num_pad_chars, 0); + result = zend_string_alloc(input->len + num_pad_chars, 0); result->len = 0; /* We need to figure out the left/right padding lengths. */ @@ -5121,15 +5117,15 @@ PHP_FUNCTION(str_pad) /* First we pad on the left. */ for (i = 0; i < left_pad; i++) - result->val[result->len++] = pad_str_val[i % pad_str_len]; + result->val[result->len++] = pad_str->val[i % pad_str->len]; /* Then we copy the input string. */ - memcpy(result->val + result->len, input, input_len); - result->len += input_len; + memcpy(result->val + result->len, input->val, input->len); + result->len += input->len; /* Finally, we pad on the right. */ for (i = 0; i < right_pad; i++) - result->val[result->len++] = pad_str_val[i % pad_str_len]; + result->val[result->len++] = pad_str->val[i % pad_str->len]; result->val[result->len] = '\0'; @@ -5165,22 +5161,21 @@ static char rot13_to[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"; Perform the rot13 transform on a string */ PHP_FUNCTION(str_rot13) { - char *arg; - int arglen; + zend_string *arg; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arglen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &arg) == FAILURE) { return; } - RETVAL_STRINGL(arg, arglen); + RETVAL_STRINGL(arg->val, arg->len); php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), rot13_from, rot13_to, 52); } /* }}} */ -static void php_string_shuffle(char *str, long len TSRMLS_DC) /* {{{ */ +static void php_string_shuffle(char *str, zend_long len TSRMLS_DC) /* {{{ */ { - long n_elems, rnd_idx, n_left; + zend_long n_elems, rnd_idx, n_left; char temp; /* The implementation is stolen from array_data_shuffle */ /* Thus the characteristics of the randomization are the same */ @@ -5208,16 +5203,15 @@ static void php_string_shuffle(char *str, long len TSRMLS_DC) /* {{{ */ Shuffles string. One permutation of all possible is created */ PHP_FUNCTION(str_shuffle) { - char *arg; - int arglen; + zend_string *arg; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arglen) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &arg) == FAILURE) { return; } - RETVAL_STRINGL(arg, arglen); + RETVAL_STRINGL(arg->val, arg->len); if (Z_STRLEN_P(return_value) > 1) { - php_string_shuffle(Z_STRVAL_P(return_value), (long) Z_STRLEN_P(return_value) TSRMLS_CC); + php_string_shuffle(Z_STRVAL_P(return_value), (zend_long) Z_STRLEN_P(return_value) TSRMLS_CC); } } /* }}} */ @@ -5235,11 +5229,12 @@ PHP_FUNCTION(str_shuffle) */ PHP_FUNCTION(str_word_count) { - char *str, *char_list = NULL, *p, *e, *s, ch[256]; - int str_len, char_list_len = 0, word_count = 0; - long type = 0; + zend_string *str; + char *char_list = NULL, *p, *e, *s, ch[256]; + int char_list_len = 0, word_count = 0; + zend_long type = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, &type, &char_list, &char_list_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ls", &str, &type, &char_list, &char_list_len) == FAILURE) { return; } @@ -5247,18 +5242,18 @@ PHP_FUNCTION(str_word_count) case 1: case 2: array_init(return_value); - if (!str_len) { + if (!str->len) { return; } break; case 0: - if (!str_len) { + if (!str->len) { RETURN_LONG(0); } /* nothing to be done */ break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid format value %ld", type); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid format value " ZEND_LONG_FMT, type); RETURN_FALSE; } @@ -5266,8 +5261,8 @@ PHP_FUNCTION(str_word_count) php_charmask((unsigned char *)char_list, char_list_len, ch TSRMLS_CC); } - p = str; - e = str + str_len; + p = str->val; + e = str->val + str->len; /* first character cannot be ' or -, unless explicitly allowed by the user */ if ((*p == '\'' && (!char_list || !ch['\''])) || (*p == '-' && (!char_list || !ch['-']))) { @@ -5290,7 +5285,7 @@ PHP_FUNCTION(str_word_count) add_next_index_stringl(return_value, s, p - s); break; case 2: - add_index_stringl(return_value, (s - str), s, p - s); + add_index_stringl(return_value, (s - str->val), s, p - s); break; default: word_count++; @@ -5336,14 +5331,14 @@ PHP_FUNCTION(money_format) } } - str = STR_ALLOC(format_len + 1024, 0); + str = zend_string_alloc(format_len + 1024, 0); if ((str->len = strfmon(str->val, str->len, format, value)) < 0) { - STR_FREE(str); + zend_string_free(str); RETURN_FALSE; } str->val[str->len] = '\0'; - RETURN_NEW_STR(STR_REALLOC(str, str->len, 0)); + RETURN_NEW_STR(zend_string_realloc(str, str->len, 0)); } /* }}} */ #endif @@ -5352,13 +5347,12 @@ PHP_FUNCTION(money_format) Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */ PHP_FUNCTION(str_split) { - char *str; - int str_len; - long split_length = 1; + zend_string *str; + zend_long split_length = 1; char *p; - int n_reg_segments; + size_t n_reg_segments; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &split_length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &str, &split_length) == FAILURE) { return; } @@ -5367,23 +5361,25 @@ PHP_FUNCTION(str_split) RETURN_FALSE; } - array_init_size(return_value, ((str_len - 1) / split_length) + 1); - if (split_length >= str_len) { - add_next_index_stringl(return_value, str, str_len); + if (0 == str->len || split_length >= str->len) { + array_init_size(return_value, 1); + add_next_index_stringl(return_value, str->val, str->len); return; } - n_reg_segments = str_len / split_length; - p = str; + array_init_size(return_value, ((str->len - 1) / split_length) + 1); + + n_reg_segments = str->len / split_length; + p = str->val; while (n_reg_segments-- > 0) { add_next_index_stringl(return_value, p, split_length); p += split_length; } - if (p != (str + str_len)) { - add_next_index_stringl(return_value, p, (str + str_len - p)); + if (p != (str->val + str->len)) { + add_next_index_stringl(return_value, p, (str->val + str->len - p)); } } /* }}} */ @@ -5392,23 +5388,22 @@ PHP_FUNCTION(str_split) Search a string for any of a set of characters */ PHP_FUNCTION(strpbrk) { - char *haystack, *char_list; - int haystack_len, char_list_len; + zend_string *haystack, *char_list; char *haystack_ptr, *cl_ptr; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &haystack, &haystack_len, &char_list, &char_list_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS", &haystack, &char_list) == FAILURE) { RETURN_FALSE; } - if (!char_list_len) { + if (!char_list->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The character list cannot be empty"); RETURN_FALSE; } - for (haystack_ptr = haystack; haystack_ptr < (haystack + haystack_len); ++haystack_ptr) { - for (cl_ptr = char_list; cl_ptr < (char_list + char_list_len); ++cl_ptr) { + for (haystack_ptr = haystack->val; haystack_ptr < (haystack->val + haystack->len); ++haystack_ptr) { + for (cl_ptr = char_list->val; cl_ptr < (char_list->val + char_list->len); ++cl_ptr) { if (*cl_ptr == *haystack_ptr) { - RETURN_STRINGL(haystack_ptr, (haystack + haystack_len - haystack_ptr)); + RETURN_STRINGL(haystack_ptr, (haystack->val + haystack->len - haystack_ptr)); } } } @@ -5421,13 +5416,12 @@ PHP_FUNCTION(strpbrk) Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length characters */ PHP_FUNCTION(substr_compare) { - char *s1, *s2; - int s1_len, s2_len; - long offset, len=0; + zend_string *s1, *s2; + zend_long offset, len=0; zend_bool cs=0; - uint cmp_len; + size_t cmp_len; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SSl|lb", &s1, &s2, &offset, &len, &cs) == FAILURE) { RETURN_FALSE; } @@ -5441,21 +5435,21 @@ PHP_FUNCTION(substr_compare) } if (offset < 0) { - offset = s1_len + offset; + offset = s1->len + offset; offset = (offset < 0) ? 0 : offset; } - if (offset >= s1_len) { + if (offset >= s1->len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length"); RETURN_FALSE; } - cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset))); + cmp_len = (size_t) (len ? len : MAX(s2->len, (s1->len - offset))); if (!cs) { - RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len)); + RETURN_LONG(zend_binary_strncmp(s1->val + offset, (s1->len - offset), s2->val, s2->len, cmp_len)); } else { - RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len)); + RETURN_LONG(zend_binary_strncasecmp_l(s1->val + offset, (s1->len - offset), s2->val, s2->len, cmp_len)); } } /* }}} */ diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c index acbffe49ad..046393b6bb 100644 --- a/ext/standard/syslog.c +++ b/ext/standard/syslog.c @@ -135,7 +135,7 @@ PHP_MSHUTDOWN_FUNCTION(syslog) PHP_FUNCTION(openlog) { char *ident; - long option, facility; + zend_long option, facility; int ident_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident, @@ -175,7 +175,7 @@ PHP_FUNCTION(closelog) Generate a system log message */ PHP_FUNCTION(syslog) { - long priority; + zend_long priority; char *message; int message_len; diff --git a/ext/standard/tests/http/bug60570.phpt b/ext/standard/tests/http/bug60570.phpt index d1784b0554..29c6a46f17 100644 --- a/ext/standard/tests/http/bug60570.phpt +++ b/ext/standard/tests/http/bug60570.phpt @@ -19,7 +19,7 @@ function do_test() { $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); - $a = $b = null; + $a = $b = count(get_resources()); $i = 3; while ($i--) { @@ -28,7 +28,7 @@ function do_test() { unset($context); $b = $a; - $a = memory_get_usage(); + $a = count(get_resources()); } http_server_kill($pid); diff --git a/ext/standard/tests/strings/bug55871.phpt b/ext/standard/tests/strings/bug55871.phpt index 7b743fdfc1..249d1bd3a3 100644 --- a/ext/standard/tests/strings/bug55871.phpt +++ b/ext/standard/tests/strings/bug55871.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #55871 (Interruption in substr_replace()) +Bug #55871 (Interruption in substr_replace()) (PHP7) --FILE-- <?php class test1 { @@ -25,23 +25,29 @@ class test3 { $my_var = str_repeat('A', 40); $out = substr_replace(array(&$my_var), array(new test1), 40, 0); -var_dump($out); +var_dump($out, $my_var); $my_var = str_repeat('A', 40); $out = substr_replace(array(&$my_var), array(new test2), 40, 0); -var_dump($out); +var_dump($out, $my_var); $my_var = str_repeat('A', 40); $out = substr_replace(array(&$my_var), array(new test3), 40, 0); -var_dump($out); +var_dump($out, $my_var); --EXPECTF-- - -Warning: substr_replace(): Argument was modified while replacing in %s on line %d -array(0) { +array(1) { + [0]=> + string(40) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" } - -Warning: substr_replace(): Argument was modified while replacing in %s on line %d -array(0) { +array(1) { + [0]=> + string(0) "" } - -Warning: substr_replace(): Argument was modified while replacing in %s on line %d -array(0) { +array(1) { + [0]=> + string(40) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" +} +int(134512640) +array(1) { + [0]=> + string(40) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" } +string(48) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" diff --git a/ext/standard/tests/strings/setlocale_variation2.phpt b/ext/standard/tests/strings/setlocale_variation2.phpt index 038ba58c5e..10ae22fe0c 100644 --- a/ext/standard/tests/strings/setlocale_variation2.phpt +++ b/ext/standard/tests/strings/setlocale_variation2.phpt @@ -18,8 +18,11 @@ if (substr(PHP_OS, 0, 3) == 'WIN') { /* setlocale() to set all available locales in the system and check the success count */ echo "*** Testing setlocale() : usage variations ***\n"; -function good_locale($locale) { - return $locale !== 'tt_RU@iqtelif.UTF-8'; +function good_locale($locale) { + /** + * Note: no_NO is a bogus locale and should not be used, see https://bugzilla.redhat.com/show_bug.cgi?id=532487 + **/ + return $locale !== 'tt_RU@iqtelif.UTF-8' && substr($locale, 0, 5) !== "no_NO"; } /* Prototype : array list_system_locales( void ) diff --git a/ext/standard/type.c b/ext/standard/type.c index 2a2988dee5..0ac849d81e 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -103,9 +103,9 @@ PHP_FUNCTION(settype) ZVAL_DEREF(var); SEPARATE_ZVAL_NOREF(var); if (!strcasecmp(type, "integer")) { - convert_to_long(var); + convert_to_int(var); } else if (!strcasecmp(type, "int")) { - convert_to_long(var); + convert_to_int(var); } else if (!strcasecmp(type, "float")) { convert_to_double(var); } else if (!strcasecmp(type, "double")) { /* deprecated */ @@ -138,7 +138,7 @@ PHP_FUNCTION(settype) PHP_FUNCTION(intval) { zval *num; - long base = 10; + zend_long base = 10; if (ZEND_NUM_ARGS() != 1 && ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; @@ -156,7 +156,7 @@ PHP_FUNCTION(intval) #endif RETVAL_ZVAL(num, 1, 0); - convert_to_long_base(return_value, base); + convert_to_int_base(return_value, base); } /* }}} */ @@ -401,7 +401,7 @@ PHP_FUNCTION(is_callable) //??? is it necessary to be consistent with old PHP ("\0" support) if (UNEXPECTED(name->len) != strlen(name->val)) { ZVAL_STRINGL(callable_name, name->val, strlen(name->val)); - STR_RELEASE(name); + zend_string_release(name); } else { ZVAL_STR(callable_name, name); } diff --git a/ext/standard/url.c b/ext/standard/url.c index 3b9b22af90..6534d7a034 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -186,10 +186,10 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) } if (pp - p > 0 && pp - p < 6 && (*pp == '/' || *pp == '\0')) { - long port; + zend_long port; memcpy(port_buf, p, (pp - p)); port_buf[pp - p] = '\0'; - port = strtol(port_buf, NULL, 10); + port = ZEND_STRTOL(port_buf, NULL, 10); if (port > 0 && port <= 65535) { ret->port = (unsigned short) port; } else { @@ -280,10 +280,10 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) efree(ret); return NULL; } else if (e - p > 0) { - long port; + zend_long port; memcpy(port_buf, p, (e - p)); port_buf[e - p] = '\0'; - port = strtol(port_buf, NULL, 10); + port = ZEND_STRTOL(port_buf, NULL, 10); if (port > 0 && port <= 65535) { ret->port = (unsigned short)port; } else { @@ -377,7 +377,7 @@ PHP_FUNCTION(parse_url) char *str; int str_len; php_url *resource; - long key = -1; + zend_long key = -1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &key) == FAILURE) { return; @@ -416,7 +416,7 @@ PHP_FUNCTION(parse_url) if (resource->fragment != NULL) RETVAL_STRING(resource->fragment); break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL component identifier %ld", key); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid URL component identifier " ZEND_LONG_FMT, key); RETVAL_FALSE; } goto done; @@ -494,7 +494,7 @@ PHPAPI zend_string *php_url_encode(char const *s, int len) from = (unsigned char *)s; end = (unsigned char *)s + len; - start = STR_ALLOC(3 * len, 0); + start = zend_string_alloc(3 * len, 0); to = (unsigned char*)start->val; while (from < end) { @@ -525,7 +525,7 @@ PHPAPI zend_string *php_url_encode(char const *s, int len) } *to = '\0'; - start = STR_REALLOC(start, to - (unsigned char*)start->val, 0); + start = zend_string_realloc(start, to - (unsigned char*)start->val, 0); return start; } @@ -567,7 +567,7 @@ PHP_FUNCTION(urldecode) ZEND_PARSE_PARAMETERS_END(); #endif - out_str = STR_INIT(in_str->val, in_str->len, 0); + out_str = zend_string_init(in_str->val, in_str->len, 0); out_str->len = php_url_decode(out_str->val, out_str->len); RETURN_NEW_STR(out_str); @@ -612,7 +612,7 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, int len) register int x, y; zend_string *str; - str = STR_ALLOC(3 * len, 0); + str = zend_string_alloc(3 * len, 0); for (x = 0, y = 0; len--; x++, y++) { str->val[y] = (unsigned char) s[x]; #ifndef CHARSET_EBCDIC @@ -632,7 +632,7 @@ PHPAPI zend_string *php_raw_url_encode(char const *s, int len) } } str->val[y] = '\0'; - str = STR_REALLOC(str, y, 0); + str = zend_string_realloc(str, y, 0); return str; } @@ -674,7 +674,7 @@ PHP_FUNCTION(rawurldecode) ZEND_PARSE_PARAMETERS_END(); #endif - out_str = STR_INIT(in_str->val, in_str->len, 0); + out_str = zend_string_init(in_str->val, in_str->len, 0); out_str->len = php_raw_url_decode(out_str->val, out_str->len); RETURN_NEW_STR(out_str); @@ -719,7 +719,7 @@ PHP_FUNCTION(get_headers) php_stream *stream; zval *prev_val, *hdr = NULL, *h; HashTable *hashT; - long format = 0; + zend_long format = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) { return; @@ -755,7 +755,7 @@ PHP_FUNCTION(get_headers) } if (!format) { no_name_header: - add_next_index_str(return_value, STR_COPY(Z_STR_P(hdr))); + add_next_index_str(return_value, zend_string_copy(Z_STR_P(hdr))); } else { char c; char *s, *p; diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index fc865b64a7..48910515f7 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -1057,7 +1057,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />"); if (urlencode) { - STR_FREE(encoded); + zend_string_free(encoded); } smart_str_free(&val); diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index 240e504d6d..cfee6c31a7 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -509,7 +509,7 @@ PHPAPI int php_url_scanner_add_var(char *name, int name_len, char *value, int va smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />"); if (urlencode) { - STR_FREE(encoded); + zend_string_free(encoded); } smart_str_free(&val); diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c index 7dce126ac3..560fd9b910 100644 --- a/ext/standard/user_filters.c +++ b/ext/standard/user_filters.c @@ -220,7 +220,7 @@ php_stream_filter_status_t userfilter_filter( zval_ptr_dtor(&func_name); if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { - convert_to_long(&retval); + convert_to_int(&retval); ret = Z_LVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call filter function"); @@ -397,7 +397,7 @@ static php_stream_filter_factory user_filter_factory = { static void filter_item_dtor(zval *zv) { struct php_user_filter_data *fdat = Z_PTR_P(zv); - STR_RELEASE(fdat->classname); + zend_string_release(fdat->classname); efree(fdat); } @@ -547,7 +547,7 @@ PHP_FUNCTION(stream_get_filters) if (filters_hash) { ZEND_HASH_FOREACH_STR_KEY(filters_hash, filter_name) { if (filter_name) { - add_next_index_str(return_value, STR_COPY(filter_name)); + add_next_index_str(return_value, zend_string_copy(filter_name)); } } ZEND_HASH_FOREACH_END(); } @@ -584,13 +584,13 @@ PHP_FUNCTION(stream_filter_register) } fdat = ecalloc(1, sizeof(struct php_user_filter_data)); - fdat->classname = STR_COPY(classname); + fdat->classname = zend_string_copy(classname); if (zend_hash_add_ptr(BG(user_filter_map), filtername, fdat) != NULL && php_stream_filter_register_factory_volatile(filtername->val, &user_filter_factory TSRMLS_CC) == SUCCESS) { RETVAL_TRUE; } else { - STR_RELEASE(classname); + zend_string_release(classname); efree(fdat); } } diff --git a/ext/standard/uuencode.c b/ext/standard/uuencode.c index 0689de5636..40ab379a30 100644 --- a/ext/standard/uuencode.c +++ b/ext/standard/uuencode.c @@ -65,14 +65,14 @@ #define PHP_UU_DEC(c) (((c) - ' ') & 077) -PHPAPI zend_string *php_uuencode(char *src, int src_len) /* {{{ */ +PHPAPI zend_string *php_uuencode(char *src, size_t src_len) /* {{{ */ { - int len = 45; + size_t len = 45; char *p, *s, *e, *ee; zend_string *dest; /* encoded length is ~ 38% greater than the original */ - dest = STR_ALLOC((size_t)ceil(src_len * 1.38) + 46, 0); + dest = zend_string_alloc((size_t)ceil(src_len * 1.38) + 46, 0); p = dest->val; s = src; e = src + src_len; @@ -122,18 +122,18 @@ PHPAPI zend_string *php_uuencode(char *src, int src_len) /* {{{ */ *p++ = '\n'; *p = '\0'; - dest = STR_REALLOC(dest, p - dest->val, 0); + dest = zend_string_realloc(dest, p - dest->val, 0); return dest; } /* }}} */ -PHPAPI zend_string *php_uudecode(char *src, int src_len) /* {{{ */ +PHPAPI zend_string *php_uudecode(char *src, size_t src_len) /* {{{ */ { - int len, total_len=0; + size_t len, total_len=0; char *s, *e, *p, *ee; zend_string *dest; - dest = STR_ALLOC((size_t) ceil(src_len * 0.75), 0); + dest = zend_string_alloc((size_t) ceil(src_len * 0.75), 0); p = dest->val; s = src; e = src + src_len; @@ -189,7 +189,7 @@ PHPAPI zend_string *php_uudecode(char *src, int src_len) /* {{{ */ return dest; err: - STR_FREE(dest); + zend_string_free(dest); return NULL; } @@ -199,14 +199,13 @@ err: uuencode a string */ PHP_FUNCTION(convert_uuencode) { - char *src; - int src_len; + zend_string *src; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &src) == FAILURE || src->len < 1) { RETURN_FALSE; } - RETURN_STR(php_uuencode(src, src_len)); + RETURN_STR(php_uuencode(src->val, src->len)); } /* }}} */ @@ -214,15 +213,14 @@ PHP_FUNCTION(convert_uuencode) decode a uuencoded string */ PHP_FUNCTION(convert_uudecode) { - char *src; - int src_len; + zend_string *src; zend_string *dest; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &src, &src_len) == FAILURE || src_len < 1) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &src) == FAILURE || src->len < 1) { RETURN_FALSE; } - if ((dest = php_uudecode(src, src_len)) == NULL) { + if ((dest = php_uudecode(src->val, src->len)) == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The given parameter is not a valid uuencoded string"); RETURN_FALSE; } diff --git a/ext/standard/var.c b/ext/standard/var.c index 96b1ee40ec..b5ece11332 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -54,10 +54,10 @@ static uint zend_obj_num_elements(HashTable *ht) return num; } -static void php_array_element_dump(zval *zv, ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ +static void php_array_element_dump(zval *zv, zend_ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ { if (key == NULL) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', index); + php_printf("%*c[" ZEND_LONG_FMT "]=>\n", level + 1, ' ', index); } else { /* string key */ php_printf("%*c[\"", level + 1, ' '); PHPWRITE(key->val, key->len); @@ -67,12 +67,12 @@ static void php_array_element_dump(zval *zv, ulong index, zend_string *key, int } /* }}} */ -static void php_object_property_dump(zval *zv, ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ +static void php_object_property_dump(zval *zv, zend_ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ { const char *prop_name, *class_name; if (key == NULL) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', index); + php_printf("%*c[" ZEND_LONG_FMT "]=>\n", level + 1, ' ', index); } else { /* string key */ int unmangle = zend_unmangle_property_name(key->val, key->len, &class_name, &prop_name); php_printf("%*c[", level + 1, ' '); @@ -100,7 +100,7 @@ PHPAPI void php_var_dump(zval *struc, int level TSRMLS_DC) /* {{{ */ zend_string *class_name; int is_temp; int is_ref = 0; - ulong num; + zend_ulong num; zend_string *key; zval *val; @@ -120,7 +120,7 @@ again: php_printf("%sNULL\n", COMMON); break; case IS_LONG: - php_printf("%sint(%ld)\n", COMMON, Z_LVAL_P(struc)); + php_printf("%sint(" ZEND_LONG_FMT ")\n", COMMON, Z_LVAL_P(struc)); break; case IS_DOUBLE: php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_P(struc)); @@ -166,12 +166,12 @@ again: if (Z_OBJ_HANDLER_P(struc, get_class_name)) { class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc), 0 TSRMLS_CC); php_printf("%sobject(%s)#%d (%d) {\n", COMMON, class_name->val, Z_OBJ_HANDLE_P(struc), myht ? zend_obj_num_elements(myht) : 0); - STR_RELEASE(class_name); + zend_string_release(class_name); } else { php_printf("%sobject(unknown class)#%d (%d) {\n", COMMON, Z_OBJ_HANDLE_P(struc), myht ? zend_obj_num_elements(myht) : 0); } if (myht) { - ulong num; + zend_ulong num; zend_string *key; zval *val; @@ -191,7 +191,7 @@ again: break; case IS_RESOURCE: { const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(struc) TSRMLS_CC); - php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_RES_P(struc)->handle, type_name ? type_name : "Unknown"); + php_printf("%sresource(%pd) of type (%s)\n", COMMON, Z_RES_P(struc)->handle, type_name ? type_name : "Unknown"); break; } case IS_REFERENCE: @@ -227,10 +227,10 @@ PHP_FUNCTION(var_dump) } /* }}} */ -static void zval_array_element_dump(zval *zv, ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ +static void zval_array_element_dump(zval *zv, zend_ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ { if (key == NULL) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', index); + php_printf("%*c[" ZEND_LONG_FMT "]=>\n", level + 1, ' ', index); } else { /* string key */ php_printf("%*c[\"", level + 1, ' '); PHPWRITE(key->val, key->len); @@ -240,12 +240,12 @@ static void zval_array_element_dump(zval *zv, ulong index, zend_string *key, int } /* }}} */ -static void zval_object_property_dump(zval *zv, ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ +static void zval_object_property_dump(zval *zv, zend_ulong index, zend_string *key, int level TSRMLS_DC) /* {{{ */ { const char *prop_name, *class_name; if (key == NULL) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', index); + php_printf("%*c[" ZEND_LONG_FMT "]=>\n", level + 1, ' ', index); } else { /* string key */ zend_unmangle_property_name(key->val, key->len, &class_name, &prop_name); php_printf("%*c[", level + 1, ' '); @@ -271,7 +271,7 @@ PHPAPI void php_debug_zval_dump(zval *struc, int level TSRMLS_DC) /* {{{ */ zend_string *class_name; int is_temp = 0; int is_ref = 0; - ulong index; + zend_ulong index; zend_string *key; zval *val; @@ -291,7 +291,7 @@ again: php_printf("%sNULL\n", COMMON); break; case IS_LONG: - php_printf("%slong(%ld)\n", COMMON, Z_LVAL_P(struc)); + php_printf("%slong(" ZEND_LONG_FMT ")\n", COMMON, Z_LVAL_P(struc)); break; case IS_DOUBLE: php_printf("%sdouble(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_P(struc)); @@ -336,7 +336,7 @@ again: } class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc), 0 TSRMLS_CC); php_printf("%sobject(%s)#%d (%d) refcount(%u){\n", COMMON, class_name->val, Z_OBJ_HANDLE_P(struc), myht ? zend_obj_num_elements(myht) : 0, Z_REFCOUNT_P(struc)); - STR_RELEASE(class_name); + zend_string_release(class_name); if (myht) { ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) { zval_object_property_dump(val, index, key, level TSRMLS_CC); @@ -354,7 +354,7 @@ again: break; case IS_RESOURCE: { const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(struc) TSRMLS_CC); - php_printf("%sresource(%ld) of type (%s) refcount(%u)\n", COMMON, Z_RES_P(struc)->handle, type_name ? type_name : "Unknown", Z_REFCOUNT_P(struc)); + php_printf("%sresource(" ZEND_LONG_FMT ") of type (%s) refcount(%u)\n", COMMON, Z_RES_P(struc)->handle, type_name ? type_name : "Unknown", Z_REFCOUNT_P(struc)); break; } case IS_REFERENCE: @@ -398,11 +398,11 @@ PHP_FUNCTION(debug_zval_dump) efree(tmp_spaces); \ } while(0); -static void php_array_element_export(zval *zv, ulong index, zend_string *key, int level, smart_str *buf TSRMLS_DC) /* {{{ */ +static void php_array_element_export(zval *zv, zend_ulong index, zend_string *key, int level, smart_str *buf TSRMLS_DC) /* {{{ */ { if (key == NULL) { /* numeric key */ buffer_append_spaces(buf, level+1); - smart_str_append_long(buf, (long) index); + smart_str_append_long(buf, (zend_long) index); smart_str_appendl(buf, " => ", 4); } else { /* string key */ @@ -416,8 +416,8 @@ static void php_array_element_export(zval *zv, ulong index, zend_string *key, in smart_str_appendl(buf, tmp_str->val, tmp_str->len); smart_str_appendl(buf, "' => ", 5); - STR_FREE(ckey); - STR_FREE(tmp_str); + zend_string_free(ckey); + zend_string_free(tmp_str); } php_var_export_ex(zv, level + 2, buf TSRMLS_CC); @@ -426,7 +426,7 @@ static void php_array_element_export(zval *zv, ulong index, zend_string *key, in } /* }}} */ -static void php_object_element_export(zval *zv, ulong index, zend_string *key, int level, smart_str *buf TSRMLS_DC) /* {{{ */ +static void php_object_element_export(zval *zv, zend_ulong index, zend_string *key, int level, smart_str *buf TSRMLS_DC) /* {{{ */ { buffer_append_spaces(buf, level + 2); if (key != NULL) { @@ -441,9 +441,9 @@ static void php_object_element_export(zval *zv, ulong index, zend_string *key, i smart_str_appendc(buf, '\''); smart_str_appendl(buf, pname_esc->val, pname_esc->len); smart_str_appendc(buf, '\''); - STR_RELEASE(pname_esc); + zend_string_release(pname_esc); } else { - smart_str_append_long(buf, (long) index); + smart_str_append_long(buf, (zend_long) index); } smart_str_appendl(buf, " => ", 4); php_var_export_ex(zv, level + 2, buf TSRMLS_CC); @@ -456,10 +456,10 @@ PHPAPI void php_var_export_ex(zval *struc, int level, smart_str *buf TSRMLS_DC) { HashTable *myht; char *tmp_str; - int tmp_len; + size_t tmp_len; zend_string *class_name; zend_string *ztmp, *ztmp2; - ulong index; + zend_ulong index; zend_string *key; zval *val; @@ -490,8 +490,8 @@ again: smart_str_appendl(buf, ztmp2->val, ztmp2->len); smart_str_appendc(buf, '\''); - STR_FREE(ztmp); - STR_FREE(ztmp2); + zend_string_free(ztmp); + zend_string_free(ztmp2); break; case IS_ARRAY: myht = Z_ARRVAL_P(struc); @@ -539,7 +539,7 @@ again: smart_str_appendl(buf, class_name->val, class_name->len); smart_str_appendl(buf, "::__set_state(array(\n", 21); - STR_RELEASE(class_name); + zend_string_release(class_name); if (myht) { ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, val) { php_object_element_export(val, index, key, level, buf TSRMLS_CC); @@ -613,16 +613,16 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var_ptr, zval *var } if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) { p = smart_str_print_long(id + sizeof(id) - 1, - (long) Z_OBJ_P(var)); + (zend_long) Z_OBJ_P(var)); *(--p) = 'O'; len = id + sizeof(id) - 1 - p; } else if (var_ptr != var) { p = smart_str_print_long(id + sizeof(id) - 1, - (long) Z_REF_P(var_ptr)); + (zend_long) Z_REF_P(var_ptr)); *(--p) = 'R'; len = id + sizeof(id) - 1 - p; } else { - p = smart_str_print_long(id + sizeof(id) - 1, (long) var); + p = smart_str_print_long(id + sizeof(id) - 1, (zend_long) var); len = id + sizeof(id) - 1 - p; } @@ -635,7 +635,7 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var_ptr, zval *var zend_hash_next_index_insert(var_hash, &var_no); } #if 0 - fprintf(stderr, "- had var (%d): %lu\n", Z_TYPE_P(var), **(ulong**)var_old); + fprintf(stderr, "- had var (%d): %lu\n", Z_TYPE_P(var), **(zend_ulong**)var_old); #endif return FAILURE; } @@ -650,7 +650,7 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var_ptr, zval *var } /* }}} */ -static inline void php_var_serialize_long(smart_str *buf, long val) /* {{{ */ +static inline void php_var_serialize_long(smart_str *buf, zend_long val) /* {{{ */ { smart_str_appendl(buf, "i:", 2); smart_str_append_long(buf, val); @@ -746,26 +746,26 @@ static void php_var_serialize_class(smart_str *buf, zval *struc, zval *retval_pt } } php_var_serialize_string(buf, priv_name->val, priv_name->len); - STR_FREE(priv_name); + zend_string_free(priv_name); php_var_serialize_intern(buf, d, var_hash TSRMLS_CC); break; } - STR_FREE(priv_name); + zend_string_free(priv_name); prot_name = zend_mangle_property_name("*", 1, Z_STRVAL_P(name), Z_STRLEN_P(name), ce->type & ZEND_INTERNAL_CLASS); if ((d = zend_hash_find(propers, prot_name)) != NULL) { if (Z_TYPE_P(d) == IS_INDIRECT) { d = Z_INDIRECT_P(d); if (Z_TYPE_P(d) == IS_UNDEF) { - STR_FREE(prot_name); + zend_string_free(prot_name); break; } } php_var_serialize_string(buf, prot_name->val, prot_name->len); - STR_FREE(prot_name); + zend_string_free(prot_name); php_var_serialize_intern(buf, d, var_hash TSRMLS_CC); break; } - STR_FREE(prot_name); + zend_string_free(prot_name); php_var_serialize_string(buf, Z_STRVAL_P(name), Z_STRLEN_P(name)); php_var_serialize_intern(buf, nvalp, var_hash TSRMLS_CC); php_error_docref(NULL TSRMLS_CC, E_NOTICE, "\"%s\" returned as member variable from __sleep() but does not exist", Z_STRVAL_P(name)); @@ -855,7 +855,7 @@ again: if (ce && ce->serialize != NULL) { /* has custom handler */ unsigned char *serialized_data = NULL; - zend_uint serialized_length; + uint32_t serialized_length; if (ce->serialize(struc, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash TSRMLS_CC) == SUCCESS) { smart_str_appendl(buf, "C:", 2); @@ -928,7 +928,7 @@ again: if (i > 0) { zend_string *key; zval *data; - ulong index; + zend_ulong index; ZEND_HASH_FOREACH_KEY_VAL_IND(myht, index, key, data) { @@ -1031,7 +1031,7 @@ PHP_FUNCTION(unserialize) PHP_VAR_UNSERIALIZE_DESTROY(var_hash); zval_dtor(return_value); if (!EG(exception)) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes", (long)((char*)p - buf), buf_len); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset " ZEND_LONG_FMT " of %d bytes", (zend_long)((char*)p - buf), buf_len); } RETURN_FALSE; } diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c index b6fcd79c2d..3ae0aaf633 100644 --- a/ext/standard/var_unserializer.c +++ b/ext/standard/var_unserializer.c @@ -30,13 +30,13 @@ typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; typedef struct { zval data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_dtor_entries; @@ -119,7 +119,7 @@ PHPAPI void var_push_dtor_no_addref(php_unserialize_data_t *var_hashx, zval *rva PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); @@ -136,7 +136,7 @@ PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nz } } -static zval *var_access(php_unserialize_data_t *var_hashx, long id) +static zval *var_access(php_unserialize_data_t *var_hashx, zend_long id) { var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG @@ -158,7 +158,7 @@ static zval *var_access(php_unserialize_data_t *var_hashx, long id) PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; #if VAR_ENTRIES_DBG @@ -186,17 +186,17 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t maxlen) { size_t i, j; - zend_string *str = STR_ALLOC(len, 0); + zend_string *str = zend_string_alloc(len, 0); unsigned char *end = *(unsigned char **)p+maxlen; if (end < *p) { - STR_FREE(str); + zend_string_free(str); return NULL; } for (i = 0; i < len; i++) { if (*p >= end) { - STR_FREE(str); + zend_string_free(str); return NULL; } if (**p != '\\') { @@ -213,7 +213,7 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t } else if (**p >= 'A' && **p <= 'F') { ch = (ch << 4) + (**p -'A'+10); } else { - STR_FREE(str); + zend_string_free(str); return NULL; } } @@ -238,10 +238,10 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t -static inline long parse_iv2(const unsigned char *p, const unsigned char **q) +static inline zend_long parse_iv2(const unsigned char *p, const unsigned char **q) { char cursor; - long result = 0; + zend_long result = 0; int neg = 0; switch (*p) { @@ -266,7 +266,7 @@ static inline long parse_iv2(const unsigned char *p, const unsigned char **q) return result; } -static inline long parse_iv(const unsigned char *p) +static inline zend_long parse_iv(const unsigned char *p) { return parse_iv2(p, NULL); } @@ -296,7 +296,7 @@ static inline size_t parse_uiv(const unsigned char *p) #define UNSERIALIZE_PARAMETER zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC #define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC -static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops) +static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, zend_long elements, int objprops) { while (elements-- > 0) { zval key, *data, d, *old_data; @@ -380,14 +380,14 @@ static inline int finish_nested_data(UNSERIALIZE_PARAMETER) static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce) { - long datalen; + zend_long datalen; datalen = parse_iv2((*p) + 2, p); (*p) += 2; if (datalen < 0 || (*p) + datalen >= max) { - zend_error(E_WARNING, "Insufficient data for unserializing - %ld required, %ld present", datalen, (long)(max - (*p))); + zend_error(E_WARNING, "Insufficient data for unserializing - %ld required, %pd present", datalen, (zend_long)(max - (*p))); return 0; } @@ -403,9 +403,9 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce) return finish_nested_data(UNSERIALIZE_PASSTHRU); } -static inline long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) +static inline zend_long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) { - long elements; + zend_long elements; elements = parse_iv2((*p) + 2, p); @@ -426,7 +426,7 @@ static inline long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { zval retval; zval fname; @@ -625,7 +625,7 @@ yy20: #line 681 "ext/standard/var_unserializer.re" { size_t len, len2, len3, maxlen; - long elements; + zend_long elements; char *str; zend_string *class_name; zend_class_entry *ce; @@ -669,7 +669,7 @@ yy20: return 0; } - class_name = STR_INIT(str, len, 0); + class_name = zend_string_init(str, len, 0); do { /* Try to find class directly */ @@ -678,7 +678,7 @@ yy20: if (ce) { BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); return 0; } break; @@ -686,7 +686,7 @@ yy20: BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); return 0; } @@ -700,12 +700,12 @@ yy20: /* Call unserialize callback */ ZVAL_STRING(&user_func, PG(unserialize_callback_func)); - ZVAL_STR(&args[0], STR_COPY(class_name)); + ZVAL_STR(&args[0], zend_string_copy(class_name)); BG(serialize_lock)++; if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); zval_ptr_dtor(&user_func); zval_ptr_dtor(&args[0]); return 0; @@ -720,7 +720,7 @@ yy20: BG(serialize_lock)--; zval_ptr_dtor(&retval); if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); zval_ptr_dtor(&user_func); zval_ptr_dtor(&args[0]); return 0; @@ -748,7 +748,7 @@ yy20: if (ret && incomplete_class) { php_store_class_name(rval, class_name->val, len2); } - STR_RELEASE(class_name); + zend_string_release(class_name); return ret; } @@ -757,7 +757,7 @@ yy20: if (incomplete_class) { php_store_class_name(rval, class_name->val, len2); } - STR_RELEASE(class_name); + zend_string_release(class_name); return object_common2(UNSERIALIZE_PASSTHRU, elements); } @@ -817,7 +817,7 @@ yy34: ++YYCURSOR; #line 652 "ext/standard/var_unserializer.re" { - long elements = parse_iv(start + 2); + zend_long elements = parse_iv(start + 2); /* use iv() not uiv() in order to check data range */ *p = YYCURSOR; @@ -874,7 +874,7 @@ yy41: } if (*(YYCURSOR) != '"') { - STR_FREE(str); + zend_string_free(str); *p = YYCURSOR; return 0; } @@ -1023,7 +1023,7 @@ yy63: ++YYCURSOR; #line 588 "ext/standard/var_unserializer.re" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_INT == 4 use_double: #endif *p = YYCURSOR; @@ -1134,14 +1134,14 @@ yy79: ++YYCURSOR; #line 546 "ext/standard/var_unserializer.re" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_INT == 4 int digits = YYCURSOR - start - 3; if (start[2] == '-' || start[2] == '+') { digits--; } - /* Use double for large long values that were serialized on a 64-bit system */ + /* Use double for large zend_long values that were serialized on a 64-bit system */ if (digits >= MAX_LENGTH_OF_LONG - 1) { if (digits == MAX_LENGTH_OF_LONG - 1) { int cmp = strncmp((char*)YYCURSOR - MAX_LENGTH_OF_LONG, long_min_digits, MAX_LENGTH_OF_LONG - 1); @@ -1206,7 +1206,7 @@ yy91: ++YYCURSOR; #line 511 "ext/standard/var_unserializer.re" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; @@ -1252,7 +1252,7 @@ yy97: ++YYCURSOR; #line 489 "ext/standard/var_unserializer.re" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re index 5636429c8b..054580ac41 100644 --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@ -28,13 +28,13 @@ typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; typedef struct { zval data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_dtor_entries; @@ -117,7 +117,7 @@ PHPAPI void var_push_dtor_no_addref(php_unserialize_data_t *var_hashx, zval *rva PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); @@ -134,7 +134,7 @@ PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nz } } -static zval *var_access(php_unserialize_data_t *var_hashx, long id) +static zval *var_access(php_unserialize_data_t *var_hashx, zend_long id) { var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG @@ -156,7 +156,7 @@ static zval *var_access(php_unserialize_data_t *var_hashx, long id) PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; #if VAR_ENTRIES_DBG @@ -184,17 +184,17 @@ PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t maxlen) { size_t i, j; - zend_string *str = STR_ALLOC(len, 0); + zend_string *str = zend_string_alloc(len, 0); unsigned char *end = *(unsigned char **)p+maxlen; if (end < *p) { - STR_FREE(str); + zend_string_free(str); return NULL; } for (i = 0; i < len; i++) { if (*p >= end) { - STR_FREE(str); + zend_string_free(str); return NULL; } if (**p != '\\') { @@ -211,7 +211,7 @@ static zend_string *unserialize_str(const unsigned char **p, size_t len, size_t } else if (**p >= 'A' && **p <= 'F') { ch = (ch << 4) + (**p -'A'+10); } else { - STR_FREE(str); + zend_string_free(str); return NULL; } } @@ -242,10 +242,10 @@ object = [OC]; -static inline long parse_iv2(const unsigned char *p, const unsigned char **q) +static inline zend_long parse_iv2(const unsigned char *p, const unsigned char **q) { char cursor; - long result = 0; + zend_long result = 0; int neg = 0; switch (*p) { @@ -270,7 +270,7 @@ static inline long parse_iv2(const unsigned char *p, const unsigned char **q) return result; } -static inline long parse_iv(const unsigned char *p) +static inline zend_long parse_iv(const unsigned char *p) { return parse_iv2(p, NULL); } @@ -300,7 +300,7 @@ static inline size_t parse_uiv(const unsigned char *p) #define UNSERIALIZE_PARAMETER zval *rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC #define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC -static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops) +static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, zend_long elements, int objprops) { while (elements-- > 0) { zval key, *data, d, *old_data; @@ -384,14 +384,14 @@ static inline int finish_nested_data(UNSERIALIZE_PARAMETER) static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce) { - long datalen; + zend_long datalen; datalen = parse_iv2((*p) + 2, p); (*p) += 2; if (datalen < 0 || (*p) + datalen >= max) { - zend_error(E_WARNING, "Insufficient data for unserializing - %ld required, %ld present", datalen, (long)(max - (*p))); + zend_error(E_WARNING, "Insufficient data for unserializing - %ld required, %pd present", datalen, (zend_long)(max - (*p))); return 0; } @@ -407,9 +407,9 @@ static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce) return finish_nested_data(UNSERIALIZE_PASSTHRU); } -static inline long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) +static inline zend_long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) { - long elements; + zend_long elements; elements = parse_iv2((*p) + 2, p); @@ -430,7 +430,7 @@ static inline long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { zval retval; zval fname; @@ -487,7 +487,7 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) /*!re2c "R:" iv ";" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; @@ -509,7 +509,7 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) } "r:" iv ";" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; @@ -544,14 +544,14 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) } "i:" iv ";" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_INT == 4 int digits = YYCURSOR - start - 3; if (start[2] == '-' || start[2] == '+') { digits--; } - /* Use double for large long values that were serialized on a 64-bit system */ + /* Use double for large zend_long values that were serialized on a 64-bit system */ if (digits >= MAX_LENGTH_OF_LONG - 1) { if (digits == MAX_LENGTH_OF_LONG - 1) { int cmp = strncmp((char*)YYCURSOR - MAX_LENGTH_OF_LONG, long_min_digits, MAX_LENGTH_OF_LONG - 1); @@ -586,7 +586,7 @@ PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) } "d:" (iv | nv | nvexp) ";" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_INT == 4 use_double: #endif *p = YYCURSOR; @@ -637,7 +637,7 @@ use_double: } if (*(YYCURSOR) != '"') { - STR_FREE(str); + zend_string_free(str); *p = YYCURSOR; return 0; } @@ -650,7 +650,7 @@ use_double: } "a:" uiv ":" "{" { - long elements = parse_iv(start + 2); + zend_long elements = parse_iv(start + 2); /* use iv() not uiv() in order to check data range */ *p = YYCURSOR; @@ -680,7 +680,7 @@ use_double: object ":" uiv ":" ["] { size_t len, len2, len3, maxlen; - long elements; + zend_long elements; char *str; zend_string *class_name; zend_class_entry *ce; @@ -724,7 +724,7 @@ object ":" uiv ":" ["] { return 0; } - class_name = STR_INIT(str, len, 0); + class_name = zend_string_init(str, len, 0); do { /* Try to find class directly */ @@ -733,7 +733,7 @@ object ":" uiv ":" ["] { if (ce) { BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); return 0; } break; @@ -741,7 +741,7 @@ object ":" uiv ":" ["] { BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); return 0; } @@ -755,12 +755,12 @@ object ":" uiv ":" ["] { /* Call unserialize callback */ ZVAL_STRING(&user_func, PG(unserialize_callback_func)); - ZVAL_STR(&args[0], STR_COPY(class_name)); + ZVAL_STR(&args[0], zend_string_copy(class_name)); BG(serialize_lock)++; if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { BG(serialize_lock)--; if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); zval_ptr_dtor(&user_func); zval_ptr_dtor(&args[0]); return 0; @@ -775,7 +775,7 @@ object ":" uiv ":" ["] { BG(serialize_lock)--; zval_ptr_dtor(&retval); if (EG(exception)) { - STR_RELEASE(class_name); + zend_string_release(class_name); zval_ptr_dtor(&user_func); zval_ptr_dtor(&args[0]); return 0; @@ -803,7 +803,7 @@ object ":" uiv ":" ["] { if (ret && incomplete_class) { php_store_class_name(rval, class_name->val, len2); } - STR_RELEASE(class_name); + zend_string_release(class_name); return ret; } @@ -812,7 +812,7 @@ object ":" uiv ":" ["] { if (incomplete_class) { php_store_class_name(rval, class_name->val, len2); } - STR_RELEASE(class_name); + zend_string_release(class_name); return object_common2(UNSERIALIZE_PASSTHRU, elements); } |