Add a ZEND_UNCOMPARABLE value

To explicitly indicate that objects are uncomparable. For now
this has no functional difference from the usual 1 return value,
but makes intent clearer.
This commit is contained in:
Nikita Popov 2020-03-31 12:36:48 +02:00
parent bef4b2e4e9
commit fb5bfcb75b
9 changed files with 17 additions and 14 deletions

View File

@ -1617,7 +1617,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
return ret;
}
}
return 1;
return ZEND_UNCOMPARABLE;
}
zobj1 = Z_OBJ_P(o1);
@ -1627,7 +1627,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
return 0; /* the same object */
}
if (zobj1->ce != zobj2->ce) {
return 1; /* different classes */
return ZEND_UNCOMPARABLE; /* different classes */
}
if (!zobj1->properties && !zobj2->properties) {
zend_property_info *info;

View File

@ -401,6 +401,12 @@ again:
return result;
}
/* Indicate that two values cannot be compared. This value should be returned for both orderings
* of the operands. This implies that all of ==, <, <= and >, >= will return false, because we
* canonicalize >/>= to </<= with swapped operands. */
// TODO: Use a different value to allow an actual distinction here.
#define ZEND_UNCOMPARABLE 1
ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2);
ZEND_API int ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2);

View File

@ -1903,7 +1903,7 @@ static int date_object_compare_date(zval *d1, zval *d2) /* {{{ */
if (!o1->time || !o2->time) {
php_error_docref(NULL, E_WARNING, "Trying to compare an incomplete DateTime or DateTimeImmutable object");
return 1;
return ZEND_UNCOMPARABLE;
}
if (!o1->time->sse_uptodate) {
timelib_update_ts(o1->time, o1->time->tz_info);
@ -2040,7 +2040,7 @@ static int date_object_compare_timezone(zval *tz1, zval *tz2) /* {{{ */
if (o1->type != o2->type) {
php_error_docref(NULL, E_WARNING, "Trying to compare different kinds of DateTimeZone objects");
return 1;
return ZEND_UNCOMPARABLE;
}
switch (o1->type) {
@ -3901,7 +3901,7 @@ static int date_interval_compare_objects(zval *o1, zval *o2) {
* smaller, equal or greater depending on the point in time at which the interval starts. As
* such, we treat DateInterval objects are non-comparable and emit a warning. */
zend_error(E_WARNING, "Cannot compare DateInterval objects");
return 1;
return ZEND_UNCOMPARABLE;
}
/* {{{ date_interval_read_property */

View File

@ -84,9 +84,6 @@ static int BreakIterator_compare_objects(zval *object1,
*bio2;
ZEND_COMPARE_OBJECTS_FALLBACK(object1, object2);
if (Z_TYPE_P(object1) != Z_TYPE_P(object2)) {
return 1; /* object and non-object */
}
bio1 = Z_INTL_BREAKITERATOR_P(object1);
bio2 = Z_INTL_BREAKITERATOR_P(object2);

View File

@ -285,7 +285,7 @@ static int TimeZone_compare_objects(zval *object1, zval *object2)
}
}
return 1;
return ZEND_UNCOMPARABLE;
}
/* }}} */

View File

@ -1298,7 +1298,7 @@ out:
static int dbh_compare(zval *object1, zval *object2)
{
return -1;
return ZEND_UNCOMPARABLE;
}
static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)

View File

@ -2165,7 +2165,7 @@ out:
static int dbstmt_compare(zval *object1, zval *object2)
{
return -1;
return ZEND_UNCOMPARABLE;
}
zend_object_handlers pdo_dbstmt_object_handlers;
@ -2585,7 +2585,7 @@ static zend_string *row_get_classname(const zend_object *object)
static int row_compare(zval *object1, zval *object2)
{
return -1;
return ZEND_UNCOMPARABLE;
}
void pdo_row_free_storage(zend_object *std)

View File

@ -1297,10 +1297,10 @@ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
} else if (sxe1->document->ptr == sxe2->document->ptr) {
return 0;
}
return 1;
} else {
return !(sxe1->node == sxe2->node);
}
return 1;
}
/* }}} */

View File

@ -345,7 +345,7 @@ static int spl_object_storage_compare_objects(zval *o1, zval *o2) /* {{{ */
zo2 = (zend_object *)Z_OBJ_P(o2);
if (zo1->ce != spl_ce_SplObjectStorage || zo2->ce != spl_ce_SplObjectStorage) {
return 1;
return ZEND_UNCOMPARABLE;
}
return zend_hash_compare(&(Z_SPLOBJSTORAGE_P(o1))->storage, &(Z_SPLOBJSTORAGE_P(o2))->storage, (compare_func_t)spl_object_storage_compare_info, 0);