diff options
-rw-r--r-- | ext/bz2/bz2_filter.c | 23 | ||||
-rw-r--r-- | ext/iconv/iconv.c | 18 | ||||
-rw-r--r-- | ext/soap/php_encoding.c | 12 | ||||
-rw-r--r-- | ext/standard/array.c | 16 | ||||
-rw-r--r-- | ext/standard/filters.c | 81 | ||||
-rw-r--r-- | ext/standard/password.c | 26 | ||||
-rw-r--r-- | ext/wddx/wddx.c | 9 | ||||
-rw-r--r-- | ext/zip/php_zip.c | 11 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 2 | ||||
-rw-r--r-- | ext/zlib/zlib_filter.c | 47 | ||||
-rw-r--r-- | main/php_ini.c | 12 |
11 files changed, 65 insertions, 192 deletions
diff --git a/ext/bz2/bz2_filter.c b/ext/bz2/bz2_filter.c index c2710d99f9..c0e128a9e1 100644 --- a/ext/bz2/bz2_filter.c +++ b/ext/bz2/bz2_filter.c @@ -377,28 +377,21 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi if (Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) { if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "blocks", sizeof("blocks")-1))) { /* How much memory to allocate (1 - 9) x 100kb */ - zval tmp; - - ZVAL_DUP(&tmp, tmpzval); - convert_to_long(&tmp); - if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > 9) { - php_error_docref(NULL, E_WARNING, "Invalid parameter given for number of blocks to allocate. (%pd)", Z_LVAL_P(tmpzval)); + zend_long blocks = zval_get_long(tmpzval); + if (blocks < 1 || blocks > 9) { + php_error_docref(NULL, E_WARNING, "Invalid parameter given for number of blocks to allocate. (%pd)", blocks); } else { - blockSize100k = (int)Z_LVAL(tmp); + blockSize100k = (int) blocks; } } if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "work", sizeof("work")-1))) { /* Work Factor (0 - 250) */ - zval tmp; - - ZVAL_DUP(&tmp, tmpzval); - convert_to_long(&tmp); - - if (Z_LVAL(tmp) < 0 || Z_LVAL(tmp) > 250) { - php_error_docref(NULL, E_WARNING, "Invalid parameter given for work factor. (%pd)", Z_LVAL(tmp)); + zend_long work = zval_get_long(tmpzval); + if (work < 0 || work > 250) { + php_error_docref(NULL, E_WARNING, "Invalid parameter given for work factor. (%pd)", work); } else { - workFactor = (int)Z_LVAL(tmp); + workFactor = (int) work; } } } diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 638160cb69..35e4d943d5 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -2214,39 +2214,31 @@ PHP_FUNCTION(iconv_mime_encode) } } - if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "input-charset", sizeof("input-charset") - 1)) != NULL) { + if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "input-charset", sizeof("input-charset") - 1)) != NULL && Z_TYPE_P(pzval) == IS_STRING) { if (Z_STRLEN_P(pzval) >= ICONV_CSNMAXLEN) { php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN); RETURN_FALSE; } - if (Z_TYPE_P(pzval) == IS_STRING && Z_STRLEN_P(pzval) > 0) { + if (Z_STRLEN_P(pzval) > 0) { in_charset = Z_STRVAL_P(pzval); } } - if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "output-charset", sizeof("output-charset") - 1)) != NULL) { + if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "output-charset", sizeof("output-charset") - 1)) != NULL && Z_TYPE_P(pzval) == IS_STRING) { if (Z_STRLEN_P(pzval) >= ICONV_CSNMAXLEN) { php_error_docref(NULL, E_WARNING, "Charset parameter exceeds the maximum allowed length of %d characters", ICONV_CSNMAXLEN); RETURN_FALSE; } - if (Z_TYPE_P(pzval) == IS_STRING && Z_STRLEN_P(pzval) > 0) { + if (Z_STRLEN_P(pzval) > 0) { out_charset = Z_STRVAL_P(pzval); } } if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "line-length", sizeof("line-length") - 1)) != NULL) { - zval val; - - if (Z_TYPE_P(pzval) != IS_LONG) { - ZVAL_DUP(&val, pzval); - convert_to_long(&val); - pzval = &val; - } - - line_len = Z_LVAL_P(pzval); + line_len = zval_get_long(pzval); } if ((pzval = zend_hash_str_find(Z_ARRVAL_P(pref), "line-break-chars", sizeof("line-break-chars") - 1)) != NULL) { diff --git a/ext/soap/php_encoding.c b/ext/soap/php_encoding.c index 993a2fa4fc..9c25067f42 100644 --- a/ext/soap/php_encoding.c +++ b/ext/soap/php_encoding.c @@ -1065,15 +1065,9 @@ static xmlNodePtr to_xml_long(encodeTypePtr type, zval *data, int style, xmlNode snprintf(s, sizeof(s), "%0.0F",floor(Z_DVAL_P(data))); xmlNodeSetContent(ret, BAD_CAST(s)); } else { - zval tmp; - - ZVAL_DUP(&tmp, data); - if (Z_TYPE(tmp) != IS_LONG) { - convert_to_long(&tmp); - } - convert_to_string(&tmp); - xmlNodeSetContentLen(ret, BAD_CAST(Z_STRVAL(tmp)), Z_STRLEN(tmp)); - zval_dtor(&tmp); + zend_string *str = zend_long_to_str(zval_get_long(data)); + xmlNodeSetContentLen(ret, BAD_CAST(str->val), str->len); + zend_string_release(str); } if (style == SOAP_ENCODED) { diff --git a/ext/standard/array.c b/ext/standard/array.c index 1e354266a1..a20a588b1e 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -1470,12 +1470,9 @@ PHP_FUNCTION(extract) if (var_name) { var_exists = zend_hash_exists_ind(symbol_table, var_name); } else if (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID) { - zval num; - - ZVAL_LONG(&num, num_key); - convert_to_string(&num); - php_prefix_varname(&final_name, prefix, Z_STRVAL(num), Z_STRLEN(num), 1); - zval_dtor(&num); + zend_string *str = zend_long_to_str(num_key); + php_prefix_varname(&final_name, prefix, str->val, str->len, 1); + zend_string_release(str); } else { continue; } @@ -3364,14 +3361,9 @@ PHP_FUNCTION(array_unique) } /* }}} */ -static int zval_compare(zval *a, zval *b) /* {{{ */ +static int zval_compare(zval *first, zval *second) /* {{{ */ { zval result; - zval *first; - zval *second; - - first = a; - second = b; if (Z_TYPE_P(first) == IS_INDIRECT) { first = Z_INDIRECT_P(first); diff --git a/ext/standard/filters.c b/ext/standard/filters.c index 3babd23d57..de3a3b2026 100644 --- a/ext/standard/filters.c +++ b/ext/standard/filters.c @@ -1232,92 +1232,35 @@ static php_conv_err_t php_conv_get_string_prop_ex(const HashTable *ht, char **pr return PHP_CONV_ERR_SUCCESS; } -#if IT_WAS_USED -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; - - *pretval = 0; - - if (zend_hash_find((HashTable *)ht, field_name, field_name_len, (void **)&tmpval) == SUCCESS) { - zval tmp, *ztval = *tmpval; - - if (Z_TYPE_PP(tmpval) != IS_LONG) { - tmp = *ztval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - ztval = &tmp; - } - *pretval = Z_LVAL_P(ztval); - } else { - return PHP_CONV_ERR_NOT_FOUND; - } - return PHP_CONV_ERR_SUCCESS; -} -#endif - 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; - - *pretval = 0; + zval *tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1); + if (tmpval != NULL) { + zend_long lval = zval_get_long(tmpval); - if ((tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1)) != NULL) { - zval tmp; - - if (Z_TYPE_P(tmpval) != IS_LONG) { - ZVAL_DUP(&tmp, tmpval); - convert_to_long(&tmp); - tmpval = &tmp; - } - if (Z_LVAL_P(tmpval) < 0) { + if (lval < 0) { *pretval = 0; } else { - *pretval = Z_LVAL_P(tmpval); + *pretval = lval; } + return PHP_CONV_ERR_SUCCESS; } else { + *pretval = 0; return PHP_CONV_ERR_NOT_FOUND; } - return PHP_CONV_ERR_SUCCESS; } static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len) { - zval *tmpval; - - *pretval = 0; - - if ((tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1)) != NULL) { - zval tmp; - - if (Z_TYPE_P(tmpval) != IS_FALSE || Z_TYPE_P(tmpval) != IS_TRUE) { - ZVAL_DUP(&tmp, tmpval); - zval_copy_ctor(&tmp); - convert_to_boolean(&tmp); - tmpval = &tmp; - } - *pretval = (Z_TYPE_P(tmpval) == IS_TRUE); + zval *tmpval = zend_hash_str_find((HashTable *)ht, field_name, field_name_len-1); + if (tmpval != NULL) { + *pretval = zend_is_true(tmpval); + return PHP_CONV_ERR_SUCCESS; } else { + *pretval = 0; return PHP_CONV_ERR_NOT_FOUND; } - return PHP_CONV_ERR_SUCCESS; -} - - -#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) -{ - zend_long l; - php_conv_err_t err; - - *pretval = 0; - - if ((err = php_conv_get_long_prop_ex(ht, &l, field_name, field_name_len)) == PHP_CONV_ERR_SUCCESS) { - *pretval = l; - } - return err; } -#endif /* XXX this might need an additional fix so it uses size_t, whereby unsigned is quite big so leaving as is for now */ static int php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len) diff --git a/ext/standard/password.c b/ext/standard/password.c index 656dc50cbb..209e2533f8 100644 --- a/ext/standard/password.c +++ b/ext/standard/password.c @@ -231,16 +231,8 @@ PHP_FUNCTION(password_needs_rehash) { 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); - new_cost = Z_LVAL(cast_option_buffer); - zval_dtor(&cast_option_buffer); - } else { - new_cost = Z_LVAL_P(option_buffer); - } + if (options && (option_buffer = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) { + new_cost = zval_get_long(option_buffer); } sscanf(hash, "$2y$" ZEND_LONG_FMT "$", &cost); @@ -314,16 +306,8 @@ PHP_FUNCTION(password_hash) { 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); - cost = Z_LVAL(cast_option_buffer); - zval_dtor(&cast_option_buffer); - } else { - cost = Z_LVAL_P(option_buffer); - } + if (options && (option_buffer = zend_hash_str_find(options, "cost", sizeof("cost")-1)) != NULL) { + cost = zval_get_long(option_buffer); } if (cost < 4 || cost > 31) { @@ -343,7 +327,7 @@ PHP_FUNCTION(password_hash) RETURN_NULL(); } - if (options && (option_buffer = zend_symtable_str_find(options, "salt", sizeof("salt")-1)) != NULL) { + if (options && (option_buffer = zend_hash_str_find(options, "salt", sizeof("salt")-1)) != NULL) { char *buffer; size_t buffer_len = 0; diff --git a/ext/wddx/wddx.c b/ext/wddx/wddx.c index c0dc964e57..19e4369aef 100644 --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -407,12 +407,9 @@ static void php_wddx_serialize_string(wddx_packet *packet, zval *var) static void php_wddx_serialize_number(wddx_packet *packet, zval *var) { char tmp_buf[WDDX_BUF_LEN]; - zval tmp; - - ZVAL_DUP(&tmp, var); - convert_to_string(&tmp); - snprintf(tmp_buf, sizeof(tmp_buf), WDDX_NUMBER, Z_STRVAL(tmp)); - zval_ptr_dtor(&tmp); + zend_string *str = zval_get_string(var); + snprintf(tmp_buf, sizeof(tmp_buf), WDDX_NUMBER, str->val); + zend_string_release(str); php_wddx_add_chunk(packet, tmp_buf); } diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 34b3733d7e..991ab90220 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -315,16 +315,7 @@ static int php_zip_parse_options(zval *options, zend_long *remove_all_path, char { zval *option; if ((option = zend_hash_str_find(HASH_OF(options), "remove_all_path", sizeof("remove_all_path") - 1)) != NULL) { - zend_long opt; - if (Z_TYPE_P(option) != IS_LONG) { - zval tmp; - ZVAL_DUP(&tmp, option); - convert_to_long(&tmp); - opt = Z_LVAL(tmp); - } else { - opt = Z_LVAL_P(option); - } - *remove_all_path = opt; + *remove_all_path = zval_get_long(option); } /* If I add more options, it would make sense to create a nice static struct and loop over it. */ diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 7fcb6a1e51..715fdaff1c 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -899,7 +899,7 @@ PHP_FUNCTION(deflate_init) RETURN_FALSE; } - if (options && (option_buffer = zend_symtable_str_find(options, "memory", sizeof("memory")-1)) != NULL) { + if (options && (option_buffer = zend_hash_str_find(options, "memory", sizeof("memory")-1)) != NULL) { memory = zval_get_long(option_buffer); } if (memory < 1 || memory > 9) { diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 1ac90a4d47..c0705f8b31 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -326,15 +326,12 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) && (tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { - zval tmp; - /* log-2 base of history window (9 - 15) */ - ZVAL_DUP(&tmp, tmpzval); - convert_to_long(&tmp); - if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 32) { - php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", Z_LVAL(tmp)); + zend_long tmp = zval_get_long(tmpzval); + if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 32) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", tmp); } else { - windowBits = Z_LVAL(tmp); + windowBits = tmp; } } } @@ -351,7 +348,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f if (filterparams) { - zval *tmpzval, tmp; + zval *tmpzval; + zend_long tmp; /* filterparams can either be a scalar value to indicate compression level (shortcut method) Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ @@ -360,31 +358,27 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_ARRAY: case IS_OBJECT: if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "memory", sizeof("memory") -1))) { - ZVAL_DUP(&tmp, tmpzval); - convert_to_long(&tmp); - /* Memory Level (1 - 9) */ - if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > MAX_MEM_LEVEL) { - php_error_docref(NULL, E_WARNING, "Invalid parameter give for memory level. (%pd)", Z_LVAL(tmp)); + tmp = zval_get_long(tmpzval); + if (tmp < 1 || tmp > MAX_MEM_LEVEL) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for memory level. (%pd)", tmp); } else { - memLevel = Z_LVAL(tmp); + memLevel = tmp; } } if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) { - ZVAL_DUP(&tmp, tmpzval); - convert_to_long(&tmp); - /* log-2 base of history window (9 - 15) */ - if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 16) { - php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", Z_LVAL(tmp)); + tmp = zval_get_long(tmpzval); + if (tmp < -MAX_WBITS || tmp > MAX_WBITS + 16) { + php_error_docref(NULL, E_WARNING, "Invalid parameter give for window size. (%pd)", tmp); } else { - windowBits = Z_LVAL(tmp); + windowBits = tmp; } } if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "level", sizeof("level") - 1))) { - ZVAL_COPY_VALUE(&tmp, tmpzval); + tmp = zval_get_long(tmpzval); /* Pseudo pass through to catch level validating code */ goto factory_setlevel; @@ -393,16 +387,13 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f case IS_STRING: case IS_DOUBLE: case IS_LONG: - ZVAL_COPY_VALUE(&tmp, filterparams); + tmp = zval_get_long(filterparams); factory_setlevel: - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ - if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) { - php_error_docref(NULL, E_WARNING, "Invalid compression level specified. (%pd)", Z_LVAL(tmp)); + if (tmp < -1 || tmp > 9) { + php_error_docref(NULL, E_WARNING, "Invalid compression level specified. (%pd)", tmp); } else { - level = Z_LVAL(tmp); + level = tmp; } break; default: diff --git a/main/php_ini.c b/main/php_ini.c index 7914244147..80d34848f8 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -886,15 +886,13 @@ PHPAPI zval *cfg_get_entry(const char *name, size_t name_length) */ PHPAPI int cfg_get_long(const char *varname, zend_long *result) { - zval *tmp, var; + zval *tmp; if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) { *result = 0; return FAILURE; } - ZVAL_DUP(&var, tmp); - convert_to_long(&var); - *result = Z_LVAL(var); + *result = zval_get_long(tmp); return SUCCESS; } /* }}} */ @@ -903,15 +901,13 @@ PHPAPI int cfg_get_long(const char *varname, zend_long *result) */ PHPAPI int cfg_get_double(const char *varname, double *result) { - zval *tmp, var; + zval *tmp; if ((tmp = zend_hash_str_find(&configuration_hash, varname, strlen(varname))) == NULL) { *result = (double) 0; return FAILURE; } - ZVAL_DUP(&var, tmp); - convert_to_double(&var); - *result = Z_DVAL(var); + *result = zval_get_double(tmp); return SUCCESS; } /* }}} */ |