com php-src: Remove unnecessary readobj==writeobj checks : Zend/zend_object_handlers.c Zend/zend_object_ handlers.h ext/simplexml/simplexml.c
ext/spl/spl_dire ctory.c
| From: | Nikita Popov | Date: | Mon, 25 Dec 2017 20:19:45 +0000 |
| Subject: | com php-src: Remove unnecessary readobj==writeobj checks : Zend/zend_object_handlers.c Zend/zend_object_ handlers.h ext/simplexml/simplexml.c ext/spl/spl_dire ctory.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100691@lists.php.net to get a copy of this message | ||
Commit: 2667ddc46d7cf2ca268ecb5d1599ad4afaf19c89
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 25 Dec 2017 21:19:45 +0100
Parents: 688b9136abcbfe28ca5c0fe6aae6143c4da58f73
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2667ddc46d7cf2ca268ecb5d1599ad4afaf19c89
Log:
Remove unnecessary readobj==writeobj checks
This can no longer be the case since PHP 7. The writeobj must
always point to a different zval.
Changed paths:
M Zend/zend_object_handlers.c
M Zend/zend_object_handlers.h
M ext/simplexml/simplexml.c
M ext/spl/spl_directory.c
Diff:
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 51ec123..86d812d 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 29494d9..465f6a4 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 f30d1fd..66ac14a 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 a58d5b3..4a012d7 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;
}