-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
From documentation, only the sign of returned value is relevant
With recent glibc, memcmp sometime return a negative value instead of -1
- Loading branch information
1 parent
4bf1a11
commit b7e96f8
Showing
1 changed file
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b7e96f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that's the case, this should be enforced by the function.
b7e96f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikic I have think a lot about this... but as per doc, only sign is relevant, why should with force -1, and add some additional tests ? bad for perf ?
P.S. more: there is a single failed assertion in all the test suite... (other fixed for consistency)... so only happens in rare run condition...
b7e96f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only in the docs, then it's quite likely that someone, somewhere is still going to rely on specific return values. If we cannot guarantee those values, we should prevent it altogether. Additionally using a normalized result allows you to do things like switch() over the return value. (IIRC for
<=>
we guarantee that the result is normalized.)b7e96f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikic value is already not always -1 / 0 / 1
See https://github.com/php/php-src/blob/master/Zend/zend_operators.c#L2643
b7e96f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@remicollet Sorry, probably I wasn't clear on what I meant. I'm suggesting that we should enforce that substr_compare always returns only -1, 0 or 1. I know it's not the case right now.