Use zval_get_string in a few more places

This commit is contained in:
Nikita Popov 2014-04-21 17:51:15 +02:00
parent bda96e3c58
commit 0d43a277b8
8 changed files with 38 additions and 131 deletions

View file

@ -3289,12 +3289,7 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zend_object *object, uint
default:
if (callable_name) {
zval expr_copy;
int use_copy;
zend_make_printable_zval(callable, &expr_copy, &use_copy);
*callable_name = STR_COPY(Z_STR(expr_copy));
zval_dtor(&expr_copy);
*callable_name = zval_get_string(callable);
}
if (error) zend_spprintf(error, 0, "no array or string given");
return 0;

View file

@ -3478,8 +3478,7 @@ static char * zend_get_function_declaration(zend_function *fptr TSRMLS_DC) /* {{
}
}
if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) {
zval zv, zv_copy;
int use_copy;
zval zv;
ZVAL_DUP(&zv, precv->op2.zv);
zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC);
@ -3509,13 +3508,11 @@ static char * zend_get_function_declaration(zend_function *fptr TSRMLS_DC) /* {{
memcpy(offset, "Array", 5);
offset += 5;
} else {
zend_make_printable_zval(&zv, &zv_copy, &use_copy);
REALLOC_BUF_IF_EXCEED(buf, offset, length, Z_STRLEN(zv_copy));
memcpy(offset, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy));
offset += Z_STRLEN(zv_copy);
if (use_copy) {
zval_dtor(&zv_copy);
}
zend_string *str = zval_get_string(&zv);
REALLOC_BUF_IF_EXCEED(buf, offset, length, str->len);
memcpy(offset, str->val, str->len);
offset += str->len;
STR_RELEASE(str);
}
zval_ptr_dtor(&zv);
}

View file

@ -1557,35 +1557,17 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{
ZEND_API int string_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
int use_copy1 = 0, use_copy2 = 0;
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
}
if (use_copy1) {
op1 = &op1_copy;
}
if (use_copy2) {
op2 = &op2_copy;
}
zend_string *str1 = zval_get_string(op1 TSRMLS_CC),
*str2 = zval_get_string(op2 TSRMLS_CC);
if (case_insensitive) {
ZVAL_LONG(result, zend_binary_zval_strcasecmp(op1, op2));
ZVAL_LONG(result, zend_binary_strcasecmp_l(str1->val, str1->len, str2->val, str1->len));
} else {
ZVAL_LONG(result, zend_binary_zval_strcmp(op1, op2));
ZVAL_LONG(result, zend_binary_strcmp(str1->val, str1->len, str2->val, str2->len));
}
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
STR_RELEASE(str1);
STR_RELEASE(str2);
return SUCCESS;
}
/* }}} */
@ -1605,31 +1587,13 @@ ZEND_API int string_case_compare_function(zval *result, zval *op1, zval *op2 TSR
#if HAVE_STRCOLL
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
int use_copy1 = 0, use_copy2 = 0;
zend_string *str1 = zval_get_string(op1 TSRMLS_CC),
*str2 = zval_get_string(op2 TSRMLS_CC);
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
}
ZVAL_LONG(result, strcoll(str1->val, str2->val));
if (use_copy1) {
op1 = &op1_copy;
}
if (use_copy2) {
op2 = &op2_copy;
}
ZVAL_LONG(result, strcoll(Z_STRVAL_P(op1), Z_STRVAL_P(op2)));
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
STR_RELEASE(str1);
STR_RELEASE(str2);
return SUCCESS;
}
/* }}} */

View file

@ -370,6 +370,7 @@ ZEND_API int zend_binary_strcmp(const char *s1, uint len1, const char *s2, uint
ZEND_API int zend_binary_strncmp(const char *s1, uint len1, const char *s2, uint len2, uint length);
ZEND_API int zend_binary_strcasecmp(const char *s1, uint len1, const char *s2, uint len2);
ZEND_API int zend_binary_strncasecmp(const char *s1, uint len1, const char *s2, uint len2, uint length);
ZEND_API int zend_binary_strcasecmp_l(const char *s1, uint len1, const char *s2, uint len2);
ZEND_API int zend_binary_strncasecmp_l(const char *s1, uint len1, const char *s2, uint len2, uint length);
ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);

View file

@ -655,23 +655,13 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in
/* {{{ _const_string */
static void _const_string(string *str, char *name, zval *value, char *indent TSRMLS_DC)
{
char *type;
zval value_copy;
int use_copy;
type = zend_zval_type_name(value);
zend_make_printable_zval(value, &value_copy, &use_copy);
if (use_copy) {
value = &value_copy;
}
char *type = zend_zval_type_name(value);
zend_string *value_str = zval_get_string(value TSRMLS_CC);
string_printf(str, "%s Constant [ %s %s ] { %s }\n",
indent, type, name, Z_STRVAL_P(value));
indent, type, name, value_str->val);
if (use_copy) {
zval_dtor(value);
}
STR_RELEASE(value_str);
}
/* }}} */
@ -728,8 +718,7 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
if (fptr->type == ZEND_USER_FUNCTION && offset >= required) {
zend_op *precv = _get_recv_op((zend_op_array*)fptr, offset);
if (precv && precv->opcode == ZEND_RECV_INIT && precv->op2_type != IS_UNUSED) {
zval zv, zv_copy;
int use_copy;
zval zv;
string_write(str, " = ", sizeof(" = ")-1);
ZVAL_DUP(&zv, precv->op2.zv);
zval_update_constant_ex(&zv, (void*)1, fptr->common.scope TSRMLS_CC);
@ -751,11 +740,9 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
} else if (Z_TYPE(zv) == IS_ARRAY) {
string_write(str, "Array", sizeof("Array")-1);
} else {
zend_make_printable_zval(&zv, &zv_copy, &use_copy);
string_write(str, Z_STRVAL(zv_copy), Z_STRLEN(zv_copy));
if (use_copy) {
zval_dtor(&zv_copy);
}
zend_string *zv_str = zval_get_string(&zv);
string_write(str, zv_str->val, zv_str->len);
STR_RELEASE(zv_str);
}
zval_ptr_dtor(&zv);
}

View file

@ -559,24 +559,14 @@ php_formatted_print(int param_count, int use_array, int format_offset TSRMLS_DC)
switch (format[inpos]) {
case 's': {
zval *var, var_copy;
int use_copy;
zend_make_printable_zval(&tmp, &var_copy, &use_copy);
if (use_copy) {
var = &var_copy;
} else {
var = &tmp;
}
zend_string *str = zval_get_string(&tmp TSRMLS_CC);
php_sprintf_appendstring(&result, &outpos,
Z_STRVAL_P(var),
str->val,
width, precision, padding,
alignment,
Z_STRLEN_P(var),
str->len,
0, expprec, 0);
if (use_copy) {
zval_dtor(&var_copy);
}
STR_RELEASE(str);
break;
}

View file

@ -4956,31 +4956,13 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, zend_bool case_insensitive TSRMLS_DC) /* {{{ */
{
zval op1_copy, op2_copy;
int use_copy1 = 0, use_copy2 = 0;
zend_string *str1 = zval_get_string(op1 TSRMLS_CC),
*str2 = zval_get_string(op2 TSRMLS_CC);
if (Z_TYPE_P(op1) != IS_STRING) {
zend_make_printable_zval(op1, &op1_copy, &use_copy1);
}
if (Z_TYPE_P(op2) != IS_STRING) {
zend_make_printable_zval(op2, &op2_copy, &use_copy2);
}
ZVAL_LONG(result, strnatcmp_ex(str1->val, str1->len, str2->val, str2->len, case_insensitive));
if (use_copy1) {
op1 = &op1_copy;
}
if (use_copy2) {
op2 = &op2_copy;
}
ZVAL_LONG(result, strnatcmp_ex(Z_STRVAL_P(op1), Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2), case_insensitive));
if (use_copy1) {
zval_dtor(op1);
}
if (use_copy2) {
zval_dtor(op2);
}
STR_RELEASE(str1);
STR_RELEASE(str2);
return SUCCESS;
}
/* }}} */

View file

@ -195,21 +195,12 @@ PHP_FUNCTION(boolval)
Get the string value of a variable */
PHP_FUNCTION(strval)
{
zval *num, *tmp;
zval expr_copy;
int use_copy;
zval *num;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &num) == FAILURE) {
return;
}
zend_make_printable_zval(num, &expr_copy, &use_copy);
if (use_copy) {
tmp = &expr_copy;
RETVAL_ZVAL(tmp, 0, 0);
} else {
RETVAL_ZVAL(num, 1, 0);
}
RETVAL_STR(zval_get_string(num));
}
/* }}} */