summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c385
1 files changed, 98 insertions, 287 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 656316cc4e..a1f3024d4e 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -138,18 +138,11 @@ ZEND_API zend_long ZEND_FASTCALL zend_atol(const char *str, size_t str_len) /* {
#define convert_object_to_type(op, dst, ctype, conv_func) \
ZVAL_UNDEF(dst); \
if (Z_OBJ_HT_P(op)->cast_object) { \
- if (Z_OBJ_HT_P(op)->cast_object(op, dst, ctype) == FAILURE) { \
+ if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), dst, ctype) == FAILURE) { \
zend_error(E_RECOVERABLE_ERROR, \
"Object of class %s could not be converted to %s", ZSTR_VAL(Z_OBJCE_P(op)->name),\
zend_get_type_by_const(ctype)); \
} \
- } else if (Z_OBJ_HT_P(op)->get) { \
- zval *newop = Z_OBJ_HT_P(op)->get(op, dst); \
- if (Z_TYPE_P(newop) != IS_OBJECT) { \
- /* for safety - avoid loop */ \
- ZVAL_COPY_VALUE(dst, newop); \
- conv_func(dst); \
- } \
}
/* }}} */
@@ -566,7 +559,7 @@ try_again:
break;
}
case IS_ARRAY:
- zend_error(E_NOTICE, "Array to string conversion");
+ zend_error(E_WARNING, "Array to string conversion");
zval_ptr_dtor(op);
ZVAL_INTERNED_STR(op, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED));
break;
@@ -574,21 +567,11 @@ try_again:
zval tmp;
if (Z_OBJ_HT_P(op)->cast_object) {
- if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING) == SUCCESS) {
+ if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) {
zval_ptr_dtor(op);
ZVAL_COPY_VALUE(op, &tmp);
return;
}
- } else if (Z_OBJ_HT_P(op)->get) {
- zval *z = Z_OBJ_HT_P(op)->get(op, &tmp);
- if (Z_TYPE_P(z) != IS_OBJECT) {
- zend_string *str = zval_get_string(z);
- zval_ptr_dtor(z);
- zval_ptr_dtor(op);
- ZVAL_STR(op, str);
- return;
- }
- zval_ptr_dtor(z);
}
if (!EG(exception)) {
zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name));
@@ -886,23 +869,15 @@ try_again:
return zend_strpprintf(0, "%.*G", (int) EG(precision), Z_DVAL_P(op));
}
case IS_ARRAY:
- zend_error(E_NOTICE, "Array to string conversion");
+ zend_error(E_WARNING, "Array to string conversion");
return (try && UNEXPECTED(EG(exception))) ?
NULL : ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED);
case IS_OBJECT: {
zval tmp;
if (Z_OBJ_HT_P(op)->cast_object) {
- if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, IS_STRING) == SUCCESS) {
+ if (Z_OBJ_HT_P(op)->cast_object(Z_OBJ_P(op), &tmp, IS_STRING) == SUCCESS) {
return Z_STR(tmp);
}
- } else if (Z_OBJ_HT_P(op)->get) {
- zval *z = Z_OBJ_HT_P(op)->get(op, &tmp);
- if (Z_TYPE_P(z) != IS_OBJECT) {
- zend_string *str = try ? zval_try_get_string(z) : zval_get_string(z);
- zval_ptr_dtor(z);
- return str;
- }
- zval_ptr_dtor(z);
}
if (!EG(exception)) {
zend_throw_error(NULL, "Object of class %s could not be converted to string", ZSTR_VAL(Z_OBJCE_P(op)->name));
@@ -1222,37 +1197,22 @@ ZEND_API int ZEND_FASTCALL pow_function(zval *result, zval *op1, zval *op2) /* {
} else if (!converted) {
ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_POW, pow_function);
- if (EXPECTED(op1 != op2)) {
- if (Z_TYPE_P(op1) == IS_ARRAY) {
- if (op1 == result) {
- zval_ptr_dtor(result);
- }
- ZVAL_LONG(result, 0);
- return SUCCESS;
- } else {
- op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
- }
- if (Z_TYPE_P(op2) == IS_ARRAY) {
- if (op1 == result) {
- zval_ptr_dtor(result);
- }
- ZVAL_LONG(result, 1L);
- return SUCCESS;
- } else {
- op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
+ if (Z_TYPE_P(op1) == IS_ARRAY || Z_TYPE_P(op2) == IS_ARRAY) {
+ if (result != op1) {
+ ZVAL_UNDEF(result);
}
+ zend_throw_error(NULL, "Unsupported operand types");
+ return FAILURE;
+ }
+
+ if (EXPECTED(op1 != op2)) {
+ op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
+ op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 0);
} else {
- if (Z_TYPE_P(op1) == IS_ARRAY) {
- if (op1 == result) {
- zval_ptr_dtor(result);
- }
- ZVAL_LONG(result, 0);
- return SUCCESS;
- } else {
- op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
- }
+ op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 0);
op2 = op1;
}
+
if (EG(exception)) {
if (result != op1) {
ZVAL_UNDEF(result);
@@ -2002,98 +1962,69 @@ ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2) /* {{{
}
/* }}} */
-static zend_always_inline void zend_free_obj_get_result(zval *op) /* {{{ */
-{
- ZEND_ASSERT(!Z_REFCOUNTED_P(op) || Z_REFCOUNT_P(op) != 0);
- zval_ptr_dtor(op);
-}
-/* }}} */
-
-static void ZEND_FASTCALL convert_compare_result_to_long(zval *result) /* {{{ */
+ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
- if (Z_TYPE_P(result) == IS_DOUBLE) {
- ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
- } else {
- convert_to_long(result);
- }
+ ZVAL_LONG(result, zend_compare(op1, op2));
+ return SUCCESS;
}
/* }}} */
-ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
+ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2) /* {{{ */
{
- int ret;
int converted = 0;
zval op1_copy, op2_copy;
- zval *op_free, tmp_free;
while (1) {
switch (TYPE_PAIR(Z_TYPE_P(op1), Z_TYPE_P(op2))) {
case TYPE_PAIR(IS_LONG, IS_LONG):
- ZVAL_LONG(result, Z_LVAL_P(op1)>Z_LVAL_P(op2)?1:(Z_LVAL_P(op1)<Z_LVAL_P(op2)?-1:0));
- return SUCCESS;
+ return Z_LVAL_P(op1)>Z_LVAL_P(op2)?1:(Z_LVAL_P(op1)<Z_LVAL_P(op2)?-1:0);
case TYPE_PAIR(IS_DOUBLE, IS_LONG):
- Z_DVAL_P(result) = Z_DVAL_P(op1) - (double)Z_LVAL_P(op2);
- ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
- return SUCCESS;
+ return ZEND_NORMALIZE_BOOL(Z_DVAL_P(op1) - (double)Z_LVAL_P(op2));
case TYPE_PAIR(IS_LONG, IS_DOUBLE):
- Z_DVAL_P(result) = (double)Z_LVAL_P(op1) - Z_DVAL_P(op2);
- ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
- return SUCCESS;
+ return ZEND_NORMALIZE_BOOL((double)Z_LVAL_P(op1) - Z_DVAL_P(op2));
case TYPE_PAIR(IS_DOUBLE, IS_DOUBLE):
if (Z_DVAL_P(op1) == Z_DVAL_P(op2)) {
- ZVAL_LONG(result, 0);
+ return 0;
} else {
- Z_DVAL_P(result) = Z_DVAL_P(op1) - Z_DVAL_P(op2);
- ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)));
+ return ZEND_NORMALIZE_BOOL(Z_DVAL_P(op1) - Z_DVAL_P(op2));
}
- return SUCCESS;
case TYPE_PAIR(IS_ARRAY, IS_ARRAY):
- ZVAL_LONG(result, zend_compare_arrays(op1, op2));
- return SUCCESS;
+ return zend_compare_arrays(op1, op2);
case TYPE_PAIR(IS_NULL, IS_NULL):
case TYPE_PAIR(IS_NULL, IS_FALSE):
case TYPE_PAIR(IS_FALSE, IS_NULL):
case TYPE_PAIR(IS_FALSE, IS_FALSE):
case TYPE_PAIR(IS_TRUE, IS_TRUE):
- ZVAL_LONG(result, 0);
- return SUCCESS;
+ return 0;
case TYPE_PAIR(IS_NULL, IS_TRUE):
- ZVAL_LONG(result, -1);
- return SUCCESS;
+ return -1;
case TYPE_PAIR(IS_TRUE, IS_NULL):
- ZVAL_LONG(result, 1);
- return SUCCESS;
+ return 1;
case TYPE_PAIR(IS_STRING, IS_STRING):
if (Z_STR_P(op1) == Z_STR_P(op2)) {
- ZVAL_LONG(result, 0);
- return SUCCESS;
+ return 0;
}
- ZVAL_LONG(result, zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2)));
- return SUCCESS;
+ return zendi_smart_strcmp(Z_STR_P(op1), Z_STR_P(op2));
case TYPE_PAIR(IS_NULL, IS_STRING):
- ZVAL_LONG(result, Z_STRLEN_P(op2) == 0 ? 0 : -1);
- return SUCCESS;
+ return Z_STRLEN_P(op2) == 0 ? 0 : -1;
case TYPE_PAIR(IS_STRING, IS_NULL):
- ZVAL_LONG(result, Z_STRLEN_P(op1) == 0 ? 0 : 1);
- return SUCCESS;
+ return Z_STRLEN_P(op1) == 0 ? 0 : 1;
case TYPE_PAIR(IS_OBJECT, IS_NULL):
- ZVAL_LONG(result, 1);
- return SUCCESS;
+ return 1;
case TYPE_PAIR(IS_NULL, IS_OBJECT):
- ZVAL_LONG(result, -1);
- return SUCCESS;
+ return -1;
default:
if (Z_ISREF_P(op1)) {
@@ -2104,109 +2035,41 @@ ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2)
continue;
}
- if (Z_TYPE_P(op1) == IS_OBJECT && Z_OBJ_HANDLER_P(op1, compare)) {
- ret = Z_OBJ_HANDLER_P(op1, compare)(result, op1, op2);
- if (UNEXPECTED(Z_TYPE_P(result) != IS_LONG)) {
- convert_compare_result_to_long(result);
- }
- return ret;
- } else if (Z_TYPE_P(op2) == IS_OBJECT && Z_OBJ_HANDLER_P(op2, compare)) {
- ret = Z_OBJ_HANDLER_P(op2, compare)(result, op1, op2);
- if (UNEXPECTED(Z_TYPE_P(result) != IS_LONG)) {
- convert_compare_result_to_long(result);
- }
- return ret;
+ if (Z_TYPE_P(op1) == IS_OBJECT
+ && Z_TYPE_P(op2) == IS_OBJECT
+ && Z_OBJ_P(op1) == Z_OBJ_P(op2)) {
+ return 0;
+ } else if (Z_TYPE_P(op1) == IS_OBJECT) {
+ return Z_OBJ_HANDLER_P(op1, compare)(op1, op2);
+ } else if (Z_TYPE_P(op2) == IS_OBJECT) {
+ return Z_OBJ_HANDLER_P(op2, compare)(op1, op2);
}
- if (Z_TYPE_P(op1) == IS_OBJECT && Z_TYPE_P(op2) == IS_OBJECT) {
- if (Z_OBJ_P(op1) == Z_OBJ_P(op2)) {
- /* object handles are identical, apparently this is the same object */
- ZVAL_LONG(result, 0);
- return SUCCESS;
- }
- if (Z_OBJ_HANDLER_P(op1, compare_objects) == Z_OBJ_HANDLER_P(op2, compare_objects)) {
- ZVAL_LONG(result, Z_OBJ_HANDLER_P(op1, compare_objects)(op1, op2));
- return SUCCESS;
- }
- }
- if (Z_TYPE_P(op1) == IS_OBJECT) {
- if (Z_OBJ_HT_P(op1)->get) {
- zval rv;
- op_free = Z_OBJ_HT_P(op1)->get(op1, &rv);
- ret = compare_function(result, op_free, op2);
- zend_free_obj_get_result(op_free);
- return ret;
- } else if (Z_TYPE_P(op2) != IS_OBJECT && Z_OBJ_HT_P(op1)->cast_object) {
- ZVAL_UNDEF(&tmp_free);
- if (Z_OBJ_HT_P(op1)->cast_object(op1, &tmp_free, ((Z_TYPE_P(op2) == IS_FALSE || Z_TYPE_P(op2) == IS_TRUE) ? _IS_BOOL : Z_TYPE_P(op2))) == FAILURE) {
- ZVAL_LONG(result, 1);
- zend_free_obj_get_result(&tmp_free);
- return SUCCESS;
- }
- ret = compare_function(result, &tmp_free, op2);
- zend_free_obj_get_result(&tmp_free);
- return ret;
- }
- }
- if (Z_TYPE_P(op2) == IS_OBJECT) {
- if (Z_OBJ_HT_P(op2)->get) {
- zval rv;
- op_free = Z_OBJ_HT_P(op2)->get(op2, &rv);
- ret = compare_function(result, op1, op_free);
- zend_free_obj_get_result(op_free);
- return ret;
- } else if (Z_TYPE_P(op1) != IS_OBJECT && Z_OBJ_HT_P(op2)->cast_object) {
- ZVAL_UNDEF(&tmp_free);
- if (Z_OBJ_HT_P(op2)->cast_object(op2, &tmp_free, ((Z_TYPE_P(op1) == IS_FALSE || Z_TYPE_P(op1) == IS_TRUE) ? _IS_BOOL : Z_TYPE_P(op1))) == FAILURE) {
- ZVAL_LONG(result, -1);
- zend_free_obj_get_result(&tmp_free);
- return SUCCESS;
- }
- ret = compare_function(result, op1, &tmp_free);
- zend_free_obj_get_result(&tmp_free);
- return ret;
- } else if (Z_TYPE_P(op1) == IS_OBJECT) {
- ZVAL_LONG(result, 1);
- return SUCCESS;
- }
- }
if (!converted) {
if (Z_TYPE_P(op1) < IS_TRUE) {
- ZVAL_LONG(result, zval_is_true(op2) ? -1 : 0);
- return SUCCESS;
+ return zval_is_true(op2) ? -1 : 0;
} else if (Z_TYPE_P(op1) == IS_TRUE) {
- ZVAL_LONG(result, zval_is_true(op2) ? 0 : 1);
- return SUCCESS;
+ return zval_is_true(op2) ? 0 : 1;
} else if (Z_TYPE_P(op2) < IS_TRUE) {
- ZVAL_LONG(result, zval_is_true(op1) ? 1 : 0);
- return SUCCESS;
+ return zval_is_true(op1) ? 1 : 0;
} else if (Z_TYPE_P(op2) == IS_TRUE) {
- ZVAL_LONG(result, zval_is_true(op1) ? 0 : -1);
- return SUCCESS;
+ return zval_is_true(op1) ? 0 : -1;
} else {
- op1 = zendi_convert_scalar_to_number(op1, &op1_copy, result, 1);
- op2 = zendi_convert_scalar_to_number(op2, &op2_copy, result, 1);
+ op1 = _zendi_convert_scalar_to_number(op1, &op1_copy);
+ op2 = _zendi_convert_scalar_to_number(op2, &op2_copy);
if (EG(exception)) {
- if (result != op1) {
- ZVAL_UNDEF(result);
- }
- return FAILURE;
+ return 1; /* to stop comparison of arrays */
}
converted = 1;
}
} else if (Z_TYPE_P(op1)==IS_ARRAY) {
- ZVAL_LONG(result, 1);
- return SUCCESS;
+ return 1;
} else if (Z_TYPE_P(op2)==IS_ARRAY) {
- ZVAL_LONG(result, -1);
- return SUCCESS;
+ return -1;
} else {
ZEND_ASSERT(0);
zend_throw_error(NULL, "Unsupported operand types");
- if (result != op1) {
- ZVAL_UNDEF(result);
- }
- return FAILURE;
+ return 1;
}
}
}
@@ -2271,91 +2134,75 @@ ZEND_API int ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zv
ZEND_API int ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
- if (compare_function(result, op1, op2) == FAILURE) {
- return FAILURE;
- }
- ZVAL_BOOL(result, (Z_LVAL_P(result) == 0));
+ ZVAL_BOOL(result, zend_compare(op1, op2) == 0);
return SUCCESS;
}
/* }}} */
ZEND_API int ZEND_FASTCALL is_not_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
- if (compare_function(result, op1, op2) == FAILURE) {
- return FAILURE;
- }
- ZVAL_BOOL(result, (Z_LVAL_P(result) != 0));
+ ZVAL_BOOL(result, (zend_compare(op1, op2) != 0));
return SUCCESS;
}
/* }}} */
ZEND_API int ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
- if (compare_function(result, op1, op2) == FAILURE) {
- return FAILURE;
- }
- ZVAL_BOOL(result, (Z_LVAL_P(result) < 0));
+ ZVAL_BOOL(result, (zend_compare(op1, op2) < 0));
return SUCCESS;
}
/* }}} */
ZEND_API int ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
- if (compare_function(result, op1, op2) == FAILURE) {
- return FAILURE;
- }
- ZVAL_BOOL(result, (Z_LVAL_P(result) <= 0));
+ ZVAL_BOOL(result, (zend_compare(op1, op2) <= 0));
return SUCCESS;
}
/* }}} */
-static zend_always_inline zend_bool instanceof_class(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
-{
- do {
- if (instance_ce == ce) {
- return 1;
- }
- instance_ce = instance_ce->parent;
- } while (instance_ce);
- return 0;
-}
-/* }}} */
-
-static zend_bool ZEND_FASTCALL instanceof_interface(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
+ZEND_API zend_bool ZEND_FASTCALL zend_class_implements_interface(const zend_class_entry *class_ce, const zend_class_entry *interface_ce) /* {{{ */
{
uint32_t i;
+ ZEND_ASSERT(!(class_ce->ce_flags & ZEND_ACC_INTERFACE));
+ ZEND_ASSERT(interface_ce->ce_flags & ZEND_ACC_INTERFACE);
- if (instance_ce->num_interfaces) {
- ZEND_ASSERT(instance_ce->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
- for (i = 0; i < instance_ce->num_interfaces; i++) {
- if (instance_ce->interfaces[i] == ce) {
+ if (class_ce->num_interfaces) {
+ ZEND_ASSERT(class_ce->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
+ for (i = 0; i < class_ce->num_interfaces; i++) {
+ if (class_ce->interfaces[i] == interface_ce) {
return 1;
}
}
}
- return instance_ce == ce;
-}
-/* }}} */
-
-// TODO: It would make more sense to expose instanceof_class + instanceof_interface instead
-ZEND_API zend_bool ZEND_FASTCALL instanceof_function_ex(const zend_class_entry *instance_ce, const zend_class_entry *ce, zend_bool is_interface) /* {{{ */
-{
- if (is_interface) {
- ZEND_ASSERT(ce->ce_flags & ZEND_ACC_INTERFACE);
- return instanceof_interface(instance_ce, ce);
- } else {
- ZEND_ASSERT(!(ce->ce_flags & ZEND_ACC_INTERFACE));
- return instanceof_class(instance_ce, ce);
- }
+ return 0;
}
/* }}} */
-ZEND_API zend_bool ZEND_FASTCALL instanceof_function(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
+ZEND_API zend_bool ZEND_FASTCALL instanceof_function_slow(const zend_class_entry *instance_ce, const zend_class_entry *ce) /* {{{ */
{
+ ZEND_ASSERT(instance_ce != ce && "Should have been checked already");
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
- return instanceof_interface(instance_ce, ce);
+ uint32_t i;
+
+ if (instance_ce->num_interfaces) {
+ ZEND_ASSERT(instance_ce->ce_flags & ZEND_ACC_RESOLVED_INTERFACES);
+ for (i = 0; i < instance_ce->num_interfaces; i++) {
+ if (instance_ce->interfaces[i] == ce) {
+ return 1;
+ }
+ }
+ }
+ return 0;
} else {
- return instanceof_class(instance_ce, ce);
+ while (1) {
+ instance_ce = instance_ce->parent;
+ if (instance_ce == ce) {
+ return 1;
+ }
+ if (instance_ce == NULL) {
+ return 0;
+ }
+ }
}
}
/* }}} */
@@ -2489,18 +2336,7 @@ try_again:
}
break;
case IS_OBJECT:
- if (Z_OBJ_HANDLER_P(op1, get)
- && Z_OBJ_HANDLER_P(op1, set)) {
- /* proxy object */
- zval rv;
- zval *val;
-
- val = Z_OBJ_HANDLER_P(op1, get)(op1, &rv);
- Z_TRY_ADDREF_P(val);
- increment_function(val);
- Z_OBJ_HANDLER_P(op1, set)(op1, val);
- zval_ptr_dtor(val);
- } else if (Z_OBJ_HANDLER_P(op1, do_operation)) {
+ if (Z_OBJ_HANDLER_P(op1, do_operation)) {
zval op2;
int res;
@@ -2556,18 +2392,7 @@ try_again:
}
break;
case IS_OBJECT:
- if (Z_OBJ_HANDLER_P(op1, get)
- && Z_OBJ_HANDLER_P(op1, set)) {
- /* proxy object */
- zval rv;
- zval *val;
-
- val = Z_OBJ_HANDLER_P(op1, get)(op1, &rv);
- Z_TRY_ADDREF_P(val);
- decrement_function(val);
- Z_OBJ_HANDLER_P(op1, set)(op1, val);
- zval_ptr_dtor(val);
- } else if (Z_OBJ_HANDLER_P(op1, do_operation)) {
+ if (Z_OBJ_HANDLER_P(op1, do_operation)) {
zval op2;
int res;
@@ -2596,23 +2421,14 @@ ZEND_API int ZEND_FASTCALL zend_is_true(zval *op) /* {{{ */
ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op) /* {{{ */
{
- if (Z_OBJ_HT_P(op)->cast_object) {
+ zend_object *zobj = Z_OBJ_P(op);
+
+ if (zobj->handlers->cast_object) {
zval tmp;
- if (Z_OBJ_HT_P(op)->cast_object(op, &tmp, _IS_BOOL) == SUCCESS) {
+ if (zobj->handlers->cast_object(zobj, &tmp, _IS_BOOL) == SUCCESS) {
return Z_TYPE(tmp) == IS_TRUE;
}
- zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(Z_OBJ_P(op)->ce->name));
- } else if (Z_OBJ_HT_P(op)->get) {
- int result;
- zval rv;
- zval *tmp = Z_OBJ_HT_P(op)->get(op, &rv);
-
- if (Z_TYPE_P(tmp) != IS_OBJECT) {
- /* for safety - avoid loop */
- result = i_zend_is_true(tmp);
- zval_ptr_dtor(tmp);
- return result;
- }
+ zend_error(E_RECOVERABLE_ERROR, "Object of class %s could not be converted to bool", ZSTR_VAL(zobj->ce->name));
}
return 1;
}
@@ -2958,12 +2774,7 @@ string_cmp:
static int hash_zval_compare_function(zval *z1, zval *z2) /* {{{ */
{
- zval result;
-
- if (compare_function(&result, z1, z2)==FAILURE) {
- return 1;
- }
- return Z_LVAL(result);
+ return zend_compare(z1, z2);
}
/* }}} */
@@ -2985,10 +2796,10 @@ ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2) /* {{{ */
return 0;
}
- if (Z_OBJ_HT_P(o1)->compare_objects == NULL) {
+ if (Z_OBJ_HT_P(o1)->compare == NULL) {
return 1;
} else {
- return Z_OBJ_HT_P(o1)->compare_objects(o1, o2);
+ return Z_OBJ_HT_P(o1)->compare(o1, o2);
}
}
/* }}} */