From: Nikita Popov Date: Mon, 25 Dec 2017 20:19:45 +0000 (+0100) Subject: Remove unnecessary readobj==writeobj checks X-Git-Tag: php-7.3.0alpha1~740 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2667ddc46d7cf2ca268ecb5d1599ad4afaf19c89;p=php Remove unnecessary readobj==writeobj checks This can no longer be the case since PHP 7. The writeobj must always point to a different zval. --- diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 51ec12352f..86d812dbea 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1675,16 +1675,10 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty return FAILURE; } if (EXPECTED(Z_TYPE(retval) == IS_STRING)) { - if (readobj == writeobj) { - zval_ptr_dtor(readobj); - } ZVAL_COPY_VALUE(writeobj, &retval); return SUCCESS; } else { zval_ptr_dtor(&retval); - if (readobj == writeobj) { - zval_ptr_dtor(readobj); - } ZVAL_EMPTY_STRING(writeobj); zend_error(E_RECOVERABLE_ERROR, "Method %s::__toString() must return a string value", ZSTR_VAL(ce->name)); return SUCCESS; @@ -1692,22 +1686,16 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty } return FAILURE; case _IS_BOOL: - ZVAL_BOOL(writeobj, 1); + ZVAL_TRUE(writeobj); return SUCCESS; case IS_LONG: ce = Z_OBJCE_P(readobj); zend_error(E_NOTICE, "Object of class %s could not be converted to int", ZSTR_VAL(ce->name)); - if (readobj == writeobj) { - zval_dtor(readobj); - } ZVAL_LONG(writeobj, 1); return SUCCESS; case IS_DOUBLE: ce = Z_OBJCE_P(readobj); zend_error(E_NOTICE, "Object of class %s could not be converted to float", ZSTR_VAL(ce->name)); - if (readobj == writeobj) { - zval_dtor(readobj); - } ZVAL_DOUBLE(writeobj, 1); return SUCCESS; default: diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h index 29494d9006..465f6a426c 100644 --- a/Zend/zend_object_handlers.h +++ b/Zend/zend_object_handlers.h @@ -115,7 +115,8 @@ typedef zend_string *(*zend_object_get_class_name_t)(const zend_object *object); typedef int (*zend_object_compare_t)(zval *object1, zval *object2); typedef int (*zend_object_compare_zvals_t)(zval *resul, zval *op1, zval *op2); -/* Cast an object to some other type +/* Cast an object to some other type. + * readobj and retval must point to distinct zvals. */ typedef int (*zend_object_cast_t)(zval *readobj, zval *retval, int type); diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index f30d1fd041..66ac14ad88 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1904,10 +1904,6 @@ static int sxe_object_cast_ex(zval *readobj, zval *writeobj, int type) } } - if (readobj == writeobj) { - zval_ptr_dtor(readobj); - } - rv = cast_object(writeobj, type, (char *)contents); if (contents) { diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index a58d5b3cdf..4a012d74ea 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -1863,37 +1863,16 @@ static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type) switch (intern->type) { case SPL_FS_INFO: case SPL_FS_FILE: - if (readobj == writeobj) { - zval retval; - zval *retval_ptr = &retval; - - ZVAL_STRINGL(retval_ptr, intern->file_name, intern->file_name_len); - zval_ptr_dtor(readobj); - ZVAL_NEW_STR(writeobj, Z_STR_P(retval_ptr)); - } else { - ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len); - } + ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len); return SUCCESS; case SPL_FS_DIR: - if (readobj == writeobj) { - zval retval; - zval *retval_ptr = &retval; - - ZVAL_STRING(retval_ptr, intern->u.dir.entry.d_name); - zval_ptr_dtor(readobj); - ZVAL_NEW_STR(writeobj, Z_STR_P(retval_ptr)); - } else { - ZVAL_STRING(writeobj, intern->u.dir.entry.d_name); - } + ZVAL_STRING(writeobj, intern->u.dir.entry.d_name); return SUCCESS; } } else if (type == _IS_BOOL) { ZVAL_TRUE(writeobj); return SUCCESS; } - if (readobj == writeobj) { - zval_ptr_dtor(readobj); - } ZVAL_NULL(writeobj); return FAILURE; }