summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2014-04-25 14:41:12 +0200
committerNikita Popov <nikic@php.net>2014-04-25 23:21:05 +0200
commitdd419d24ca01db3e3be66b4414c4d7926c6fdc69 (patch)
treec839d8808ab356bffd8552fd2dab610569fde793
parent93f9518a58b5e56803197e1a27d8426465d77f5e (diff)
downloadphp-git-dd419d24ca01db3e3be66b4414c4d7926c6fdc69.tar.gz
Replace more convert_to_* calls
-rw-r--r--Zend/zend_operators.h19
-rw-r--r--ext/standard/array.c89
-rw-r--r--ext/standard/file.c3
-rw-r--r--ext/standard/http_fopen_wrapper.c33
-rw-r--r--ext/standard/math.c6
-rw-r--r--ext/standard/pack.c42
-rw-r--r--ext/standard/string.c23
7 files changed, 59 insertions, 156 deletions
diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h
index 7d786fa8ed..93a79705c8 100644
--- a/Zend/zend_operators.h
+++ b/Zend/zend_operators.h
@@ -342,14 +342,19 @@ ZEND_API long _zval_get_long_func(zval *op TSRMLS_DC);
ZEND_API double _zval_get_double_func(zval *op TSRMLS_DC);
ZEND_API zend_string *_zval_get_string_func(zval *op TSRMLS_DC);
-#define zval_get_long(op) ((Z_TYPE_P(op) == IS_LONG) ? \
- Z_LVAL_P(op) : _zval_get_long_func((op) TSRMLS_CC))
-
-#define zval_get_double(op) ((Z_TYPE_P(op) == IS_DOUBLE) ? \
- Z_DVAL_P(op) : _zval_get_double_func((op) TSRMLS_CC))
+static zend_always_inline long _zval_get_long(zval *op TSRMLS_DC) {
+ return Z_TYPE_P(op) == IS_LONG ? Z_LVAL_P(op) : _zval_get_long_func(op TSRMLS_CC);
+}
+static zend_always_inline double _zval_get_double(zval *op TSRMLS_DC) {
+ return Z_TYPE_P(op) == IS_DOUBLE ? Z_DVAL_P(op) : _zval_get_double_func(op TSRMLS_CC);
+}
+static zend_always_inline zend_string *_zval_get_string(zval *op TSRMLS_DC) {
+ return Z_TYPE_P(op) == IS_STRING ? STR_COPY(Z_STR_P(op)) : _zval_get_string_func(op TSRMLS_CC);
+}
-#define zval_get_string(op) ((Z_TYPE_P(op) == IS_STRING) ? \
- STR_COPY(Z_STR_P(op)) : _zval_get_string_func((op) TSRMLS_CC))
+#define zval_get_long(op) _zval_get_long((op) TSRMLS_CC)
+#define zval_get_double(op) _zval_get_double((op) TSRMLS_CC)
+#define zval_get_string(op) _zval_get_string((op) TSRMLS_CC)
ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2);
ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2);
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 414c804bc8..3d587fa98e 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -198,24 +198,11 @@ static int php_array_key_compare(const void *a, const void *b TSRMLS_DC) /* {{{
}
if (Z_TYPE(result) == IS_DOUBLE) {
- if (Z_DVAL(result) < 0) {
- return -1;
- } else if (Z_DVAL(result) > 0) {
- return 1;
- } else {
- return 0;
- }
+ return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
}
convert_to_long(&result);
-
- if (Z_LVAL(result) < 0) {
- return -1;
- } else if (Z_LVAL(result) > 0) {
- return 1;
- }
-
- return 0;
+ return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
}
/* }}} */
@@ -327,8 +314,7 @@ PHP_FUNCTION(count)
ZVAL_LONG(&mode_zv, mode);
zend_call_method_with_1_params(array, NULL, NULL, "count", &retval, &mode_zv);
if (Z_TYPE(retval) != IS_UNDEF) {
- convert_to_long_ex(&retval);
- RETVAL_LONG(Z_LVAL(retval));
+ RETVAL_LONG(zval_get_long(&retval));
zval_ptr_dtor(&retval);
}
zval_dtor(&mode_zv);
@@ -374,24 +360,11 @@ static int php_array_data_compare(const void *a, const void *b TSRMLS_DC) /* {{{
}
if (Z_TYPE(result) == IS_DOUBLE) {
- if (Z_DVAL(result) < 0) {
- return -1;
- } else if (Z_DVAL(result) > 0) {
- return 1;
- } else {
- return 0;
- }
+ return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
}
convert_to_long(&result);
-
- if (Z_LVAL(result) < 0) {
- return -1;
- } else if (Z_LVAL(result) > 0) {
- return 1;
- }
-
- return 0;
+ return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
}
/* }}} */
@@ -564,10 +537,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;
-
- convert_to_long_ex(&retval);
- ret = Z_LVAL(retval);
+ long ret = zval_get_long(&retval);
zval_ptr_dtor(&retval);
zval_ptr_dtor(&args[1]);
zval_ptr_dtor(&args[0]);
@@ -725,8 +695,7 @@ static int php_array_user_key_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) {
- convert_to_long_ex(&retval);
- result = Z_LVAL(retval);
+ result = zval_get_long(&retval);
zval_ptr_dtor(&retval);
} else {
result = 0;
@@ -1582,7 +1551,7 @@ PHP_FUNCTION(range)
int err = 0, is_step_double = 0;
double step = 1.0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z/|z/", &zlow, &zhigh, &zstep) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &zlow, &zhigh, &zstep) == FAILURE) {
RETURN_FALSE;
}
@@ -1593,8 +1562,7 @@ PHP_FUNCTION(range)
is_step_double = 1;
}
- convert_to_double_ex(zstep);
- step = Z_DVAL_P(zstep);
+ step = zval_get_double(zstep);
/* We only want positive step values. */
if (step < 0.0) {
@@ -1620,8 +1588,6 @@ PHP_FUNCTION(range)
goto long_str;
}
- convert_to_string(zlow);
- convert_to_string(zhigh);
low = (unsigned char *)Z_STRVAL_P(zlow);
high = (unsigned char *)Z_STRVAL_P(zhigh);
@@ -1659,10 +1625,8 @@ PHP_FUNCTION(range)
double low, high, value;
long i;
double_str:
- convert_to_double(zlow);
- convert_to_double(zhigh);
- low = Z_DVAL_P(zlow);
- high = Z_DVAL_P(zhigh);
+ low = zval_get_double(zlow);
+ high = zval_get_double(zhigh);
i = 0;
if (low > high) { /* Negative steps */
@@ -1690,10 +1654,8 @@ double_str:
double low, high;
long lstep;
long_str:
- convert_to_double(zlow);
- convert_to_double(zhigh);
- low = Z_DVAL_P(zlow);
- high = Z_DVAL_P(zhigh);
+ low = zval_get_double(zlow);
+ high = zval_get_double(zhigh);
lstep = (long) step;
if (low > high) { /* Negative steps */
@@ -2179,8 +2141,7 @@ PHP_FUNCTION(array_slice)
if (ZEND_NUM_ARGS() < 3 || Z_TYPE_P(z_length) == IS_NULL) {
length = num_in;
} else {
- convert_to_long_ex(z_length);
- length = Z_LVAL_P(z_length);
+ length = zval_get_long(z_length);
}
/* Clamp the offset.. */
@@ -2921,24 +2882,11 @@ static int zval_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */
}
if (Z_TYPE(result) == IS_DOUBLE) {
- if (Z_DVAL(result) < 0) {
- return -1;
- } else if (Z_DVAL(result) > 0) {
- return 1;
- } else {
- return 0;
- }
+ return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
}
convert_to_long(&result);
-
- if (Z_LVAL(result) < 0) {
- return -1;
- } else if (Z_LVAL(result) > 0) {
- return 1;
- }
-
- return 0;
+ return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
}
/* }}} */
@@ -2963,10 +2911,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;
-
- convert_to_long_ex(&retval);
- ret = Z_LVAL(retval);
+ long ret = zval_get_long(&retval);
zval_ptr_dtor(&retval);
return ret < 0 ? -1 : ret > 0 ? 1 : 0;;
} else {
diff --git a/ext/standard/file.c b/ext/standard/file.c
index b1dc0be1ff..afd7cba000 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -2002,8 +2002,7 @@ PHP_FUNCTION(fgetcsv)
}
if (len_zv != NULL && Z_TYPE_P(len_zv) != IS_NULL) {
- convert_to_long_ex(len_zv);
- len = Z_LVAL_P(len_zv);
+ len = zval_get_long(len_zv);
if (len < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
RETURN_FALSE;
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
index 7ac15a69ca..931857e798 100644
--- a/ext/standard/http_fopen_wrapper.c
+++ b/ext/standard/http_fopen_wrapper.c
@@ -198,10 +198,9 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
}
if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) {
- SEPARATE_ZVAL(tmpzval);
- convert_to_double_ex(tmpzval);
- timeout.tv_sec = (time_t) Z_DVAL_P(tmpzval);
- timeout.tv_usec = (size_t) ((Z_DVAL_P(tmpzval) - timeout.tv_sec) * 1000000);
+ double d = zval_get_double(tmpzval);
+ timeout.tv_sec = (time_t) d;
+ timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000);
} else {
timeout.tv_sec = FG(default_socket_timeout);
timeout.tv_usec = 0;
@@ -339,9 +338,7 @@ finish:
php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0);
if (header_init && context && (tmpzval = php_stream_context_get_option(context, "http", "max_redirects")) != NULL) {
- SEPARATE_ZVAL(tmpzval);
- convert_to_long_ex(tmpzval);
- redirect_max = Z_LVAL_P(tmpzval);
+ redirect_max = zval_get_long(tmpzval);
}
if (context && (tmpzval = php_stream_context_get_option(context, "http", "method")) != NULL) {
@@ -361,9 +358,7 @@ finish:
}
if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) {
- SEPARATE_ZVAL(tmpzval);
- convert_to_double_ex(tmpzval);
- protocol_version_len = spprintf(&protocol_version, 0, "%.1F", Z_DVAL_P(tmpzval));
+ protocol_version_len = spprintf(&protocol_version, 0, "%.1F", zval_get_double(tmpzval));
}
if (!scratch) {
@@ -373,15 +368,9 @@ finish:
}
/* Should we send the entire path in the request line, default to no. */
- if (!request_fulluri &&
- context &&
+ if (!request_fulluri && context &&
(tmpzval = php_stream_context_get_option(context, "http", "request_fulluri")) != NULL) {
- zval ztmp;
-
- ZVAL_DUP(&ztmp, tmpzval);
- convert_to_boolean(&ztmp);
- request_fulluri = Z_BVAL(ztmp) ? 1 : 0;
- zval_dtor(&ztmp);
+ request_fulluri = zend_is_true(tmpzval TSRMLS_CC) ? 1 : 0;
}
if (request_fulluri) {
@@ -736,9 +725,7 @@ finish:
if (!strncasecmp(http_header_line, "Location: ", 10)) {
if (context && (tmpzval = php_stream_context_get_option(context, "http", "follow_location")) != NULL) {
- SEPARATE_ZVAL(tmpzval);
- convert_to_long_ex(tmpzval);
- follow_location = Z_LVAL_P(tmpzval);
+ follow_location = zval_get_long(tmpzval);
} else if (!((response_code >= 300 && response_code < 304) || 307 == response_code)) {
/* we shouldn't redirect automatically
if follow_location isn't set and response_code not in (300, 301, 302, 303 and 307)
@@ -758,9 +745,7 @@ finish:
long decode = 1;
if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) {
- SEPARATE_ZVAL(tmpzval);
- convert_to_boolean(tmpzval);
- decode = Z_LVAL_P( tmpzval);
+ decode = zend_is_true(tmpzval TSRMLS_CC);
}
if (decode) {
transfer_encoding = php_stream_filter_create("dechunk", NULL, php_stream_is_persistent(stream) TSRMLS_CC);
diff --git a/ext/standard/math.c b/ext/standard/math.c
index b5ad90e8d8..71a2abc6d3 100644
--- a/ext/standard/math.c
+++ b/ext/standard/math.c
@@ -310,8 +310,7 @@ PHP_FUNCTION(ceil)
if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(ceil(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) {
- convert_to_double_ex(value);
- RETURN_DOUBLE(Z_DVAL_P(value));
+ RETURN_DOUBLE(zval_get_double(value));
}
RETURN_FALSE;
}
@@ -331,8 +330,7 @@ PHP_FUNCTION(floor)
if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(floor(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) {
- convert_to_double_ex(value);
- RETURN_DOUBLE(Z_DVAL_P(value));
+ RETURN_DOUBLE(zval_get_double(value));
}
RETURN_FALSE;
}
diff --git a/ext/standard/pack.c b/ext/standard/pack.c
index 53a18c8fec..c77a1a40c6 100644
--- a/ext/standard/pack.c
+++ b/ext/standard/pack.c
@@ -315,22 +315,21 @@ PHP_FUNCTION(pack)
for (i = 0; i < formatcount; i++) {
int code = (int) formatcodes[i];
int arg = formatargs[i];
- zval *val;
switch ((int) code) {
case 'a':
case 'A':
case 'Z': {
int arg_cp = (code != 'Z') ? arg : MAX(0, arg - 1);
+
+ zend_string *str = zval_get_string(&argv[currentarg++]);
+
memset(&output[outputpos], (code == 'a' || code == 'Z') ? '\0' : ' ', arg);
- val = &argv[currentarg++];
- if (Z_ISREF_P(val)) {
- SEPARATE_ZVAL(val);
- }
- convert_to_string_ex(val);
- memcpy(&output[outputpos], Z_STRVAL_P(val),
- (Z_STRLEN_P(val) < arg_cp) ? Z_STRLEN_P(val) : arg_cp);
+ memcpy(&output[outputpos], str->val,
+ (str->len < arg_cp) ? str->len : arg_cp);
+
outputpos += arg;
+ STR_RELEASE(str);
break;
}
@@ -338,18 +337,14 @@ PHP_FUNCTION(pack)
case 'H': {
int nibbleshift = (code == 'h') ? 0 : 4;
int first = 1;
- char *v;
- val = &argv[currentarg++];
- if (Z_ISREF_P(val)) {
- SEPARATE_ZVAL(val);
- }
- convert_to_string_ex(val);
- v = Z_STRVAL_P(val);
+ zend_string *str = zval_get_string(&argv[currentarg++]);
+ char *v = str->val;
+
outputpos--;
- if(arg > Z_STRLEN_P(val)) {
+ if(arg > str->len) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough characters in string", code);
- arg = Z_STRLEN_P(val);
+ arg = str->len;
}
while (arg-- > 0) {
@@ -377,6 +372,7 @@ PHP_FUNCTION(pack)
}
outputpos++;
+ STR_RELEASE(str);
break;
}
@@ -435,12 +431,8 @@ PHP_FUNCTION(pack)
}
case 'f': {
- float v;
-
while (arg-- > 0) {
- val = &argv[currentarg++];
- convert_to_double_ex(val);
- v = (float) Z_DVAL_P(val);
+ float v = (float) zval_get_double(&argv[currentarg++]);
memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v);
}
@@ -448,12 +440,8 @@ PHP_FUNCTION(pack)
}
case 'd': {
- double v;
-
while (arg-- > 0) {
- val = &argv[currentarg++];
- convert_to_double_ex(val);
- v = (double) Z_DVAL_P(val);
+ double v = (double) zval_get_double(&argv[currentarg++]);
memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v);
}
diff --git a/ext/standard/string.c b/ext/standard/string.c
index a77084551e..67c8001b5b 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -2296,8 +2296,7 @@ PHP_FUNCTION(substr_replace)
if (argc > 3) {
SEPARATE_ZVAL(len);
if (Z_TYPE_P(len) != IS_ARRAY) {
- convert_to_long_ex(len);
- l = Z_LVAL_P(len);
+ l = zval_get_long(len);
}
} else {
if (Z_TYPE_P(str) != IS_ARRAY) {
@@ -2422,15 +2421,7 @@ PHP_FUNCTION(substr_replace)
if (Z_TYPE_P(from) == IS_ARRAY) {
if (NULL != (tmp_from = zend_hash_get_current_data_ex(Z_ARRVAL_P(from), &pos_from))) {
- if(Z_TYPE_P(tmp_from) != IS_LONG) {
- zval dummy;
-
- ZVAL_DUP(&dummy, tmp_from);
- convert_to_long(&dummy);
- f = Z_LVAL(dummy);
- } else {
- f = Z_LVAL_P(tmp_from);
- }
+ f = zval_get_long(tmp_from);
if (f < 0) {
f = Z_STRLEN_P(orig_str) + f;
@@ -2458,15 +2449,7 @@ PHP_FUNCTION(substr_replace)
if (argc > 3 && Z_TYPE_P(len) == IS_ARRAY) {
if (NULL != (tmp_len = zend_hash_get_current_data_ex(Z_ARRVAL_P(len), &pos_len))) {
- if(Z_TYPE_P(tmp_len) != IS_LONG) {
- zval dummy;
-
- ZVAL_DUP(&dummy, tmp_len);
- convert_to_long(&dummy);
- l = Z_LVAL(dummy);
- } else {
- l = Z_LVAL_P(tmp_len);
- }
+ l = zval_get_long(tmp_len);
zend_hash_move_forward_ex(Z_ARRVAL_P(len), &pos_len);
} else {
l = Z_STRLEN_P(orig_str);