From 0aefa3e03709393e46d78c93377908dfab7eb105 Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Wed, 17 May 2000 18:55:22 +0000 Subject: [PATCH] - Add support for string_compare_function() and number_compare_function(). UNTESTED! --- Zend/zend_operators.c | 46 +++++++++++++++++++++++++++++++++++++++++++ Zend/zend_operators.h | 2 ++ 2 files changed, 48 insertions(+) diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index f8357a900d..8707f3f29b 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -948,6 +948,52 @@ ZEND_API int concat_function(zval *result, zval *op1, zval *op2) } +ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2) +{ + zval op1_copy, op2_copy; + int use_copy1, use_copy2; + + zend_make_printable_zval(op1, &op1_copy, &use_copy1); + zend_make_printable_zval(op2, &op2_copy, &use_copy2); + + if (use_copy1) { + op1 = &op1_copy; + } + if (use_copy2) { + op2 = &op2_copy; + } + + result->value.lval = zend_binary_zval_strcmp(op1, op2); + result->type = IS_LONG; + + if (use_copy1) { + zval_dtor(op1); + } + if (use_copy2) { + zval_dtor(op2); + } + return SUCCESS; +} + +ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2) +{ + zval op1_copy, op2_copy; + + op1_copy = *op1; + zval_copy_ctor(&op1_copy); + + op2_copy = *op2; + zval_copy_ctor(&op2_copy); + + convert_to_double(&op1_copy); + convert_to_double(&op2_copy); + + result->value.lval = NORMALIZE_BOOL(op2_copy.value.dval-op1_copy.value.dval); + result->type = IS_LONG; + + return SUCCESS; +} + ZEND_API int compare_function(zval *result, zval *op1, zval *op2) { zval op1_copy, op2_copy; diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 8a7e45bc39..9e1ced2c70 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -69,6 +69,8 @@ END_EXTERN_C() ZEND_API int zval_is_true(zval *op); ZEND_API int compare_function(zval *result, zval *op1, zval *op2); +ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2); +ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2); ZEND_API void zend_str_tolower(char *str, unsigned int length); ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2); -- 2.40.0