Fix value comparison and sorting semantics
Build / AerScript (push) Successful in 31s

This commit is contained in:
2026-11-05 22:26:00 +01:00
parent 3c3c15281a
commit d98f6a8e91
10 changed files with 1956 additions and 681 deletions
+21 -2
View File
@@ -61,6 +61,15 @@ PH7_PRIVATE void SyZero(void *pSrc, sxu32 nSize) {
zSrc++;
}
}
/*
* Byte comparison contract: SyMemcmp() returns the RAW delta of the first
* differing byte pair [unsigned bytes], in [-255,255], or 0 when the whole
* region is equal. It is NOT a 3-way ordering result: a delta such as
* 'a' - '{' = -26 collides with the engine error sentinels [SXERR_NOMATCH
* is -26, SXERR_ABORT is -10, ...]. Callers that need an ordering must
* reduce the delta to its sign [-1, 0, +1] before exposing it; see
* MemObjCmpString() in memobj.c and HashmapKeyBlobCmp() in hashmap.c.
*/
PH7_PRIVATE sxi32 SyMemcmp(const void *pB1, const void *pB2, sxu32 nSize) {
sxi32 rc;
if(nSize <= 0) {
@@ -712,6 +721,16 @@ PH7_PRIVATE sxi32 SyBlobDup(SyBlob *pSrc, SyBlob *pDest) {
}
return rc;
}
/*
* Blob ordering as implemented here: LENGTH BEFORE CONTENT. When the two
* lengths differ the shorter blob sorts first whatever the bytes hold (so
* "b" < "aa" is TRUE); the memcmp() pass only breaks equal-length ties.
* This is NOT a lexicographic 3-way contract — do not document or reuse it
* as one. Both verdicts are reduced to their sign [-1, 0, +1]: the raw
* SyMemcmp() delta can be any value in [-255, +255] and a delta such as
* -26 would collide with SXERR_NOMATCH, so this helper never hands out a
* raw delta.
*/
PH7_PRIVATE sxi32 SyBlobCmp(SyBlob *pLeft, SyBlob *pRight) {
sxi32 rc;
if(pLeft == 0 || pRight == 0) {
@@ -719,14 +738,14 @@ PH7_PRIVATE sxi32 SyBlobCmp(SyBlob *pLeft, SyBlob *pRight) {
}
if(pLeft->nByte != pRight->nByte) {
/* Length differ */
return pLeft->nByte - pRight->nByte;
return pLeft->nByte < pRight->nByte ? -1 : 1;
}
if(pLeft->nByte == 0) {
return 0;
}
/* Perform a standard memcmp() operation */
rc = SyMemcmp(pLeft->pBlob, pRight->pBlob, pLeft->nByte);
return rc;
return rc < 0 ? -1 : (rc > 0 ? 1 : 0);
}
PH7_PRIVATE sxi32 SyBlobReset(SyBlob *pBlob) {
pBlob->nByte = 0;