]> granicus.if.org Git - php/commitdiff
Use zval_get_string in a few more places
authorNikita Popov <nikic@php.net>
Mon, 21 Apr 2014 15:51:15 +0000 (17:51 +0200)
committerNikita Popov <nikic@php.net>
Mon, 21 Apr 2014 15:55:58 +0000 (17:55 +0200)
Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_operators.c
Zend/zend_operators.h
ext/reflection/php_reflection.c
ext/standard/formatted_print.c
ext/standard/string.c
ext/standard/type.c

index 7d394bfe13998693e898ad002d394ea7b7d8c190..6cf6cb2157c4483a3efb93b49dc63502684cca9f 100644 (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;
index 14d937bb558d6e92d9e2a2f1a1e596929f525605..9f43adf85254708b925bcca8ae022b7f5591a765 100644 (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);
                                        }
index 93197a9b891d542de101a3116f864f9ddf49ccc3..f593e97ada9dcea483ff755d3f607c7861a364aa 100644 (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;
-
-       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);
 
-       ZVAL_LONG(result, strcoll(Z_STRVAL_P(op1), Z_STRVAL_P(op2)));
+       ZVAL_LONG(result, strcoll(str1->val, str2->val));
 
-       if (use_copy1) {
-               zval_dtor(op1);
-       }
-       if (use_copy2) {
-               zval_dtor(op2);
-       }
+       STR_RELEASE(str1);
+       STR_RELEASE(str2);
        return SUCCESS;
 }
 /* }}} */
index c062cd5e19ed4667c47302ce8173c59c09911118..9df4a68933f36a1b1f917ea81c8d4105515d9dd1 100644 (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);
index 86391115d06b4b72862c63d1cb6165078fb4fd6d..b78311868ae2b64e71cac2216c72ead794769e60 100644 (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);
                }
index 622fbfbb3fcc3c0ab2550d0eac35108721bdd3d5..b08b06fac5d41642b9ceee0e9e7d771872c7fd00 100644 (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;
                                }
 
index 6f699e22c4395d617fe7425b3155a6c7cc5ed035..fe6d30f18a0d6297500beaae3cbaf76f103d9a90 100644 (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);
-       }
-
-       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));
+       ZVAL_LONG(result, strnatcmp_ex(str1->val, str1->len, str2->val, str2->len, case_insensitive));
 
-       if (use_copy1) {
-               zval_dtor(op1);
-       }
-       if (use_copy2) {
-               zval_dtor(op2);
-       }
+       STR_RELEASE(str1);
+       STR_RELEASE(str2);
        return SUCCESS;
 }
 /* }}} */
index c4fdbc87e3798fd664f87c678ae42483bcafd8c4..1e3572c22f8f3f309f0f73a82043c6315f933a9a 100644 (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));
 }
 /* }}} */