]> granicus.if.org Git - php/commitdiff
Remove unnecessary readobj==writeobj checks
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 25 Dec 2017 20:19:45 +0000 (21:19 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 25 Dec 2017 20:19:45 +0000 (21:19 +0100)
This can no longer be the case since PHP 7. The writeobj must
always point to a different zval.

Zend/zend_object_handlers.c
Zend/zend_object_handlers.h
ext/simplexml/simplexml.c
ext/spl/spl_directory.c

index 51ec12352f5185690195edf1fcaff056732ed941..86d812dbea2538c85d29973dfc6779fe6f122f38 100644 (file)
@@ -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:
index 29494d9006fe9750c46ddee4b9fbb2acfd91b3ea..465f6a426c1bf27dfd594a6119dee8b90e0c9a0f 100644 (file)
@@ -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);
 
index f30d1fd041567ac96abb8a15b9f0074bb229ffe9..66ac14ad8845a2e7ed6533bf3ea0da7d6d1a7a9d 100644 (file)
@@ -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) {
index a58d5b3cdf864e35ba63144fc29657ec1806d1a2..4a012d74ea699117dc728c1d9a36d2ee95cefe75 100644 (file)
@@ -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;
 }