Replace more convert_to_* calls

This commit is contained in:
Nikita Popov 2014-04-25 14:41:12 +02:00
parent 93f9518a58
commit dd419d24ca
7 changed files with 59 additions and 156 deletions

View file

@ -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 double _zval_get_double_func(zval *op TSRMLS_DC);
ZEND_API zend_string *_zval_get_string_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) ? \ static zend_always_inline long _zval_get_long(zval *op TSRMLS_DC) {
Z_LVAL_P(op) : _zval_get_long_func((op) TSRMLS_CC)) 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_double(op) ((Z_TYPE_P(op) == IS_DOUBLE) ? \ #define zval_get_long(op) _zval_get_long((op) TSRMLS_CC)
Z_DVAL_P(op) : _zval_get_double_func((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)
#define zval_get_string(op) ((Z_TYPE_P(op) == IS_STRING) ? \
STR_COPY(Z_STR_P(op)) : _zval_get_string_func((op) TSRMLS_CC))
ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2); 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); ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2);

View file

@ -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_TYPE(result) == IS_DOUBLE) {
if (Z_DVAL(result) < 0) { return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
return -1;
} else if (Z_DVAL(result) > 0) {
return 1;
} else {
return 0;
}
} }
convert_to_long(&result); convert_to_long(&result);
return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
if (Z_LVAL(result) < 0) {
return -1;
} else if (Z_LVAL(result) > 0) {
return 1;
}
return 0;
} }
/* }}} */ /* }}} */
@ -327,8 +314,7 @@ PHP_FUNCTION(count)
ZVAL_LONG(&mode_zv, mode); ZVAL_LONG(&mode_zv, mode);
zend_call_method_with_1_params(array, NULL, NULL, "count", &retval, &mode_zv); zend_call_method_with_1_params(array, NULL, NULL, "count", &retval, &mode_zv);
if (Z_TYPE(retval) != IS_UNDEF) { if (Z_TYPE(retval) != IS_UNDEF) {
convert_to_long_ex(&retval); RETVAL_LONG(zval_get_long(&retval));
RETVAL_LONG(Z_LVAL(retval));
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
} }
zval_dtor(&mode_zv); 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_TYPE(result) == IS_DOUBLE) {
if (Z_DVAL(result) < 0) { return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
return -1;
} else if (Z_DVAL(result) > 0) {
return 1;
} else {
return 0;
}
} }
convert_to_long(&result); convert_to_long(&result);
return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
if (Z_LVAL(result) < 0) {
return -1;
} else if (Z_LVAL(result) > 0) {
return 1;
}
return 0;
} }
/* }}} */ /* }}} */
@ -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).retval = &retval;
BG(user_compare_fci).no_separation = 0; 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) { if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
long ret; long ret = zval_get_long(&retval);
convert_to_long_ex(&retval);
ret = Z_LVAL(retval);
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
zval_ptr_dtor(&args[1]); zval_ptr_dtor(&args[1]);
zval_ptr_dtor(&args[0]); 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).retval = &retval;
BG(user_compare_fci).no_separation = 0; 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) { 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 = zval_get_long(&retval);
result = Z_LVAL(retval);
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
} else { } else {
result = 0; result = 0;
@ -1582,7 +1551,7 @@ PHP_FUNCTION(range)
int err = 0, is_step_double = 0; int err = 0, is_step_double = 0;
double step = 1.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; RETURN_FALSE;
} }
@ -1593,8 +1562,7 @@ PHP_FUNCTION(range)
is_step_double = 1; is_step_double = 1;
} }
convert_to_double_ex(zstep); step = zval_get_double(zstep);
step = Z_DVAL_P(zstep);
/* We only want positive step values. */ /* We only want positive step values. */
if (step < 0.0) { if (step < 0.0) {
@ -1620,8 +1588,6 @@ PHP_FUNCTION(range)
goto long_str; goto long_str;
} }
convert_to_string(zlow);
convert_to_string(zhigh);
low = (unsigned char *)Z_STRVAL_P(zlow); low = (unsigned char *)Z_STRVAL_P(zlow);
high = (unsigned char *)Z_STRVAL_P(zhigh); high = (unsigned char *)Z_STRVAL_P(zhigh);
@ -1659,10 +1625,8 @@ PHP_FUNCTION(range)
double low, high, value; double low, high, value;
long i; long i;
double_str: double_str:
convert_to_double(zlow); low = zval_get_double(zlow);
convert_to_double(zhigh); high = zval_get_double(zhigh);
low = Z_DVAL_P(zlow);
high = Z_DVAL_P(zhigh);
i = 0; i = 0;
if (low > high) { /* Negative steps */ if (low > high) { /* Negative steps */
@ -1690,10 +1654,8 @@ double_str:
double low, high; double low, high;
long lstep; long lstep;
long_str: long_str:
convert_to_double(zlow); low = zval_get_double(zlow);
convert_to_double(zhigh); high = zval_get_double(zhigh);
low = Z_DVAL_P(zlow);
high = Z_DVAL_P(zhigh);
lstep = (long) step; lstep = (long) step;
if (low > high) { /* Negative steps */ 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) { if (ZEND_NUM_ARGS() < 3 || Z_TYPE_P(z_length) == IS_NULL) {
length = num_in; length = num_in;
} else { } else {
convert_to_long_ex(z_length); length = zval_get_long(z_length);
length = Z_LVAL_P(z_length);
} }
/* Clamp the offset.. */ /* 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_TYPE(result) == IS_DOUBLE) {
if (Z_DVAL(result) < 0) { return ZEND_NORMALIZE_BOOL(Z_DVAL(result));
return -1;
} else if (Z_DVAL(result) > 0) {
return 1;
} else {
return 0;
}
} }
convert_to_long(&result); convert_to_long(&result);
return ZEND_NORMALIZE_BOOL(Z_LVAL(result));
if (Z_LVAL(result) < 0) {
return -1;
} else if (Z_LVAL(result) > 0) {
return 1;
}
return 0;
} }
/* }}} */ /* }}} */
@ -2963,10 +2911,7 @@ static int zval_user_compare(zval *a, zval *b TSRMLS_DC) /* {{{ */
BG(user_compare_fci).no_separation = 0; 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) { if (zend_call_function(&BG(user_compare_fci), &BG(user_compare_fci_cache) TSRMLS_CC) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
long ret; long ret = zval_get_long(&retval);
convert_to_long_ex(&retval);
ret = Z_LVAL(retval);
zval_ptr_dtor(&retval); zval_ptr_dtor(&retval);
return ret < 0 ? -1 : ret > 0 ? 1 : 0;; return ret < 0 ? -1 : ret > 0 ? 1 : 0;;
} else { } else {

View file

@ -2002,8 +2002,7 @@ PHP_FUNCTION(fgetcsv)
} }
if (len_zv != NULL && Z_TYPE_P(len_zv) != IS_NULL) { if (len_zv != NULL && Z_TYPE_P(len_zv) != IS_NULL) {
convert_to_long_ex(len_zv); len = zval_get_long(len_zv);
len = Z_LVAL_P(len_zv);
if (len < 0) { if (len < 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
RETURN_FALSE; RETURN_FALSE;

View file

@ -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) { if (context && (tmpzval = php_stream_context_get_option(context, wrapper->wops->label, "timeout")) != NULL) {
SEPARATE_ZVAL(tmpzval); double d = zval_get_double(tmpzval);
convert_to_double_ex(tmpzval); timeout.tv_sec = (time_t) d;
timeout.tv_sec = (time_t) Z_DVAL_P(tmpzval); timeout.tv_usec = (size_t) ((d - timeout.tv_sec) * 1000000);
timeout.tv_usec = (size_t) ((Z_DVAL_P(tmpzval) - timeout.tv_sec) * 1000000);
} else { } else {
timeout.tv_sec = FG(default_socket_timeout); timeout.tv_sec = FG(default_socket_timeout);
timeout.tv_usec = 0; timeout.tv_usec = 0;
@ -339,9 +338,7 @@ finish:
php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); 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) { if (header_init && context && (tmpzval = php_stream_context_get_option(context, "http", "max_redirects")) != NULL) {
SEPARATE_ZVAL(tmpzval); redirect_max = zval_get_long(tmpzval);
convert_to_long_ex(tmpzval);
redirect_max = Z_LVAL_P(tmpzval);
} }
if (context && (tmpzval = php_stream_context_get_option(context, "http", "method")) != NULL) { 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) { if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) {
SEPARATE_ZVAL(tmpzval); protocol_version_len = spprintf(&protocol_version, 0, "%.1F", zval_get_double(tmpzval));
convert_to_double_ex(tmpzval);
protocol_version_len = spprintf(&protocol_version, 0, "%.1F", Z_DVAL_P(tmpzval));
} }
if (!scratch) { if (!scratch) {
@ -373,15 +368,9 @@ finish:
} }
/* Should we send the entire path in the request line, default to no. */ /* Should we send the entire path in the request line, default to no. */
if (!request_fulluri && if (!request_fulluri && context &&
context &&
(tmpzval = php_stream_context_get_option(context, "http", "request_fulluri")) != NULL) { (tmpzval = php_stream_context_get_option(context, "http", "request_fulluri")) != NULL) {
zval ztmp; request_fulluri = zend_is_true(tmpzval TSRMLS_CC) ? 1 : 0;
ZVAL_DUP(&ztmp, tmpzval);
convert_to_boolean(&ztmp);
request_fulluri = Z_BVAL(ztmp) ? 1 : 0;
zval_dtor(&ztmp);
} }
if (request_fulluri) { if (request_fulluri) {
@ -736,9 +725,7 @@ finish:
if (!strncasecmp(http_header_line, "Location: ", 10)) { if (!strncasecmp(http_header_line, "Location: ", 10)) {
if (context && (tmpzval = php_stream_context_get_option(context, "http", "follow_location")) != NULL) { if (context && (tmpzval = php_stream_context_get_option(context, "http", "follow_location")) != NULL) {
SEPARATE_ZVAL(tmpzval); follow_location = zval_get_long(tmpzval);
convert_to_long_ex(tmpzval);
follow_location = Z_LVAL_P(tmpzval);
} else if (!((response_code >= 300 && response_code < 304) || 307 == response_code)) { } else if (!((response_code >= 300 && response_code < 304) || 307 == response_code)) {
/* we shouldn't redirect automatically /* we shouldn't redirect automatically
if follow_location isn't set and response_code not in (300, 301, 302, 303 and 307) 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; long decode = 1;
if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) { if (context && (tmpzval = php_stream_context_get_option(context, "http", "auto_decode")) != NULL) {
SEPARATE_ZVAL(tmpzval); decode = zend_is_true(tmpzval TSRMLS_CC);
convert_to_boolean(tmpzval);
decode = Z_LVAL_P( tmpzval);
} }
if (decode) { if (decode) {
transfer_encoding = php_stream_filter_create("dechunk", NULL, php_stream_is_persistent(stream) TSRMLS_CC); transfer_encoding = php_stream_filter_create("dechunk", NULL, php_stream_is_persistent(stream) TSRMLS_CC);

View file

@ -310,8 +310,7 @@ PHP_FUNCTION(ceil)
if (Z_TYPE_P(value) == IS_DOUBLE) { if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(ceil(Z_DVAL_P(value))); RETURN_DOUBLE(ceil(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) { } else if (Z_TYPE_P(value) == IS_LONG) {
convert_to_double_ex(value); RETURN_DOUBLE(zval_get_double(value));
RETURN_DOUBLE(Z_DVAL_P(value));
} }
RETURN_FALSE; RETURN_FALSE;
} }
@ -331,8 +330,7 @@ PHP_FUNCTION(floor)
if (Z_TYPE_P(value) == IS_DOUBLE) { if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(floor(Z_DVAL_P(value))); RETURN_DOUBLE(floor(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) { } else if (Z_TYPE_P(value) == IS_LONG) {
convert_to_double_ex(value); RETURN_DOUBLE(zval_get_double(value));
RETURN_DOUBLE(Z_DVAL_P(value));
} }
RETURN_FALSE; RETURN_FALSE;
} }

View file

@ -315,22 +315,21 @@ PHP_FUNCTION(pack)
for (i = 0; i < formatcount; i++) { for (i = 0; i < formatcount; i++) {
int code = (int) formatcodes[i]; int code = (int) formatcodes[i];
int arg = formatargs[i]; int arg = formatargs[i];
zval *val;
switch ((int) code) { switch ((int) code) {
case 'a': case 'a':
case 'A': case 'A':
case 'Z': { case 'Z': {
int arg_cp = (code != 'Z') ? arg : MAX(0, arg - 1); 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); memset(&output[outputpos], (code == 'a' || code == 'Z') ? '\0' : ' ', arg);
val = &argv[currentarg++]; memcpy(&output[outputpos], str->val,
if (Z_ISREF_P(val)) { (str->len < arg_cp) ? str->len : arg_cp);
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);
outputpos += arg; outputpos += arg;
STR_RELEASE(str);
break; break;
} }
@ -338,18 +337,14 @@ PHP_FUNCTION(pack)
case 'H': { case 'H': {
int nibbleshift = (code == 'h') ? 0 : 4; int nibbleshift = (code == 'h') ? 0 : 4;
int first = 1; int first = 1;
char *v;
val = &argv[currentarg++]; zend_string *str = zval_get_string(&argv[currentarg++]);
if (Z_ISREF_P(val)) { char *v = str->val;
SEPARATE_ZVAL(val);
}
convert_to_string_ex(val);
v = Z_STRVAL_P(val);
outputpos--; 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); 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) { while (arg-- > 0) {
@ -377,6 +372,7 @@ PHP_FUNCTION(pack)
} }
outputpos++; outputpos++;
STR_RELEASE(str);
break; break;
} }
@ -435,12 +431,8 @@ PHP_FUNCTION(pack)
} }
case 'f': { case 'f': {
float v;
while (arg-- > 0) { while (arg-- > 0) {
val = &argv[currentarg++]; float v = (float) zval_get_double(&argv[currentarg++]);
convert_to_double_ex(val);
v = (float) Z_DVAL_P(val);
memcpy(&output[outputpos], &v, sizeof(v)); memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v); outputpos += sizeof(v);
} }
@ -448,12 +440,8 @@ PHP_FUNCTION(pack)
} }
case 'd': { case 'd': {
double v;
while (arg-- > 0) { while (arg-- > 0) {
val = &argv[currentarg++]; double v = (double) zval_get_double(&argv[currentarg++]);
convert_to_double_ex(val);
v = (double) Z_DVAL_P(val);
memcpy(&output[outputpos], &v, sizeof(v)); memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v); outputpos += sizeof(v);
} }

View file

@ -2296,8 +2296,7 @@ PHP_FUNCTION(substr_replace)
if (argc > 3) { if (argc > 3) {
SEPARATE_ZVAL(len); SEPARATE_ZVAL(len);
if (Z_TYPE_P(len) != IS_ARRAY) { if (Z_TYPE_P(len) != IS_ARRAY) {
convert_to_long_ex(len); l = zval_get_long(len);
l = Z_LVAL_P(len);
} }
} else { } else {
if (Z_TYPE_P(str) != IS_ARRAY) { if (Z_TYPE_P(str) != IS_ARRAY) {
@ -2422,15 +2421,7 @@ PHP_FUNCTION(substr_replace)
if (Z_TYPE_P(from) == IS_ARRAY) { if (Z_TYPE_P(from) == IS_ARRAY) {
if (NULL != (tmp_from = zend_hash_get_current_data_ex(Z_ARRVAL_P(from), &pos_from))) { if (NULL != (tmp_from = zend_hash_get_current_data_ex(Z_ARRVAL_P(from), &pos_from))) {
if(Z_TYPE_P(tmp_from) != IS_LONG) { f = zval_get_long(tmp_from);
zval dummy;
ZVAL_DUP(&dummy, tmp_from);
convert_to_long(&dummy);
f = Z_LVAL(dummy);
} else {
f = Z_LVAL_P(tmp_from);
}
if (f < 0) { if (f < 0) {
f = Z_STRLEN_P(orig_str) + f; 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 (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 (NULL != (tmp_len = zend_hash_get_current_data_ex(Z_ARRVAL_P(len), &pos_len))) {
if(Z_TYPE_P(tmp_len) != IS_LONG) { l = zval_get_long(tmp_len);
zval dummy;
ZVAL_DUP(&dummy, tmp_len);
convert_to_long(&dummy);
l = Z_LVAL(dummy);
} else {
l = Z_LVAL_P(tmp_len);
}
zend_hash_move_forward_ex(Z_ARRVAL_P(len), &pos_len); zend_hash_move_forward_ex(Z_ARRVAL_P(len), &pos_len);
} else { } else {
l = Z_STRLEN_P(orig_str); l = Z_STRLEN_P(orig_str);