cvs: ZendEngine2 / zend_operators.c

From: Date: Sun, 05 Feb 2006 13:12:20 +0000
Subject: cvs: ZendEngine2 / zend_operators.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-4555@lists.php.net to get a copy of this message
helly Sun Feb 5 13:12:20 2006 UTC Modified files: /ZendEngine2 zend_operators.c Log: - Fix comparision where one argument is an object http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_operators.c?r1=1.226&r2=1.227&diff_format=u Index: ZendEngine2/zend_operators.c diff -u ZendEngine2/zend_operators.c:1.226 ZendEngine2/zend_operators.c:1.227 --- ZendEngine2/zend_operators.c:1.226 Tue Jan 17 12:18:52 2006 +++ ZendEngine2/zend_operators.c Sun Feb 5 13:12:20 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.c,v 1.226 2006/01/17 12:18:52 dmitry Exp $ */ +/* $Id: zend_operators.c,v 1.227 2006/02/05 13:12:20 helly Exp $ */ #include <ctype.h> @@ -1474,7 +1474,7 @@ op2 = &op2_copy; } - result->value.lval = ucol_strcoll(col, op1->value.str.val, op1->value.str.len, op2->value.str.val, op2->value.str.len); + result->value.lval = ucol_strcoll(col, (void*)op1->value.str.val, op1->value.str.len, (void*)op2->value.str.val, op2->value.str.len); result->type = IS_LONG; if (use_copy1) { @@ -1509,9 +1509,9 @@ } -static inline void zend_free_obj_get_result(zval *op, int free_op) +static inline void zend_free_obj_get_result(zval *op) { - if (free_op) { + if (op) { if (op->refcount == 0) { zval_dtor(op); FREE_ZVAL(op); @@ -1522,26 +1522,49 @@ } #define COMPARE_RETURN_AND_FREE(retval) \ - zend_free_obj_get_result(op1_orig, free_op1); \ - zend_free_obj_get_result(op2_orig, free_op2); \ + zend_free_obj_get_result(op1_free); \ + zend_free_obj_get_result(op2_free); \ return retval; ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) { zval op1_copy, op2_copy; - zend_bool free_op1 = 0, free_op2 = 0; - zval *op1_orig, *op2_orig; - - if (op1->type == IS_OBJECT && Z_OBJ_HT_P(op1)->get) { - op1 = Z_OBJ_HT_P(op1)->get(op1 TSRMLS_CC); - free_op1 = 1; - } - op1_orig = op1; - if (op2->type == IS_OBJECT && Z_OBJ_HT_P(op2)->get) { - op2 = Z_OBJ_HT_P(op2)->get(op2 TSRMLS_CC); - free_op2 = 1; + zval *op1_free, *op2_free; + int op1_obj = op1->type == IS_OBJECT; + int op2_obj = op2->type == IS_OBJECT; + + if (op1_obj) { + if (Z_OBJ_HT_P(op1)->get) { + op1 = op1_free = Z_OBJ_HT_P(op1)->get(op1 TSRMLS_CC); + } else if (!op2_obj && Z_OBJ_HT_P(op1)->cast_object) { + ALLOC_INIT_ZVAL(op1_free); + if (Z_OBJ_HT_P(op1)->cast_object(op1, op1_free, Z_TYPE_P(op2) TSRMLS_CC) == FAILURE) { + ZVAL_BOOL(result, 0); + COMPARE_RETURN_AND_FREE(FAILURE); + } + op1 = op1_free; + } else { + op1_free = NULL; + } + } else { + op1_free = NULL; + } + if (op2_obj) { + if (Z_OBJ_HT_P(op2)->get) { + op2 = op2_free = Z_OBJ_HT_P(op2)->get(op2 TSRMLS_CC); + } else if (!op1_obj && Z_OBJ_HT_P(op2)->cast_object) { + ALLOC_INIT_ZVAL(op2_free); + if (Z_OBJ_HT_P(op2)->cast_object(op2, op2_free, Z_TYPE_P(op1) TSRMLS_CC) == FAILURE) { + ZVAL_BOOL(result, 0); + COMPARE_RETURN_AND_FREE(FAILURE); + } + op2 = op2_free; + } else { + op2_free = NULL; + } + } else { + op2_free = NULL; } - op2_orig = op2; if ((op1->type == IS_NULL && op2->type == IS_STRING) || (op2->type == IS_NULL && op1->type == IS_STRING)) {

« previous php.zend-engine.cvs (#4555) next »