cvs: ZendEngine2 / zend_operators.c

From: Date: Fri, 04 May 2007 11:12:30 +0000
Subject: cvs: ZendEngine2 / zend_operators.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5773@lists.php.net to get a copy of this message
tony2001 Fri May 4 11:12:30 2007 UTC Modified files: /ZendEngine2 zend_operators.c Log: merge one more missing patch from 5_2 thank you for not doing MFB http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_operators.c?r1=1.272&r2=1.273&diff_format=u Index: ZendEngine2/zend_operators.c diff -u ZendEngine2/zend_operators.c:1.272 ZendEngine2/zend_operators.c:1.273 --- ZendEngine2/zend_operators.c:1.272 Mon Apr 30 15:59:12 2007 +++ ZendEngine2/zend_operators.c Fri May 4 11:12:30 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.c,v 1.272 2007/04/30 15:59:12 tony2001 Exp $ */ +/* $Id: zend_operators.c,v 1.273 2007/05/04 11:12:30 tony2001 Exp $ */ #include <ctype.h> @@ -2662,19 +2662,23 @@ (ret2=is_numeric_string(Z_STRVAL_P(s2), Z_STRLEN_P(s2), &lval2, &dval2, 0))) { if ((ret1==IS_DOUBLE) || (ret2==IS_DOUBLE)) { if (ret1!=IS_DOUBLE) { - dval1 = zend_strtod(Z_STRVAL_P(s1), NULL); + dval1 = (double) lval1; } else if (ret2!=IS_DOUBLE) { - dval2 = zend_strtod(Z_STRVAL_P(s2), NULL); - } - Z_DVAL_P(result) = dval1 - dval2; - Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)); - Z_TYPE_P(result) = IS_LONG; + dval2 = (double) lval2; + } else if (dval1 == dval2 && !zend_finite(dval1)) { + /* Both values overflowed and have the same sign, + * so a numeric comparison would be inaccurate */ + goto string_cmp; + } + result->value.dval = dval1 - dval2; + result->value.lval = ZEND_NORMALIZE_BOOL(result->value.dval); + result->type = IS_LONG; } else { /* they both have to be long's */ - Z_LVAL_P(result) = lval1 - lval2; - Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)); - Z_TYPE_P(result) = IS_LONG; + result->value.lval = lval1 > lval2 ? 1 : (lval1 < lval2 ? -1 : 0); + result->type = IS_LONG; } } else { +string_cmp: Z_LVAL_P(result) = zend_binary_zval_strcmp(s1, s2); Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)); Z_TYPE_P(result) = IS_LONG; @@ -2706,19 +2710,23 @@ (ret2=is_numeric_unicode(Z_USTRVAL_P(s2), Z_USTRLEN_P(s2), &lval2, &dval2, 0))) { if ((ret1==IS_DOUBLE) || (ret2==IS_DOUBLE)) { if (ret1!=IS_DOUBLE) { - dval1 = zend_u_strtod(Z_USTRVAL_P(s1), NULL); + dval1 = (double) lval1; } else if (ret2!=IS_DOUBLE) { - dval2 = zend_u_strtod(Z_USTRVAL_P(s2), NULL); - } - Z_DVAL_P(result) = dval1 - dval2; - Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_DVAL_P(result)); - Z_TYPE_P(result) = IS_LONG; + dval2 = (double) lval2; + } else if (dval1 == dval2 && !zend_finite(dval1)) { + /* Both values overflowed and have the same sign, + * so a numeric comparison would be inaccurate */ + goto string_cmp; + } + result->value.dval = dval1 - dval2; + result->value.lval = ZEND_NORMALIZE_BOOL(result->value.dval); + result->type = IS_LONG; } else { /* they both have to be long's */ - Z_LVAL_P(result) = lval1 - lval2; - Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)); - Z_TYPE_P(result) = IS_LONG; + result->value.lval = lval1 > lval2 ? 1 : (lval1 < lval2 ? -1 : 0); + result->type = IS_LONG; } } else { +string_cmp: Z_LVAL_P(result) = zend_u_binary_zval_strcmp(s1, s2); Z_LVAL_P(result) = ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)); Z_TYPE_P(result) = IS_LONG;

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