[Patch] iosxwstr WideCompareStr failure

Summary

WideCompareStr with iosxwstr returns unexpected results - tests fail

System Information

  • Operating system: macOS Ventura 13.6.1
  • Processor architecture: x86-64
  • Compiler version: trunk

Steps to reproduce

On macOS, run fpc tests. tunistr7.pp and twide7.pp will fail with exit code 2.

What is the current bug behavior?

WideCompareStr("afcde", "aécde") returns -1. The tests expect it to be positive, like on other platforms (verified on linux x86_64).

What is the expected (correct) behavior?

WideCompareStr("afcde", "aécde") returns 1.

Relevant logs and/or screenshots

The following Objective C output shows that a normal NSString :compare actually equals to calling CFCompareString with kCFCompareNonliteral and that the explicit option NSLiteralSearch equals to calling CFCompareString with 0:

//
//  main.m
//  TestCFStringCompare
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSString* w1 = @"afcde";
        NSString* w2 = @"aécde";
        NSComparisonResult cr = [w1 compare:w2];
        NSLog(@"NSString compare: result is %ld", (long)cr);

        cr = [w1 compare:w2 options:NSLiteralSearch];
        NSLog(@"NSString compare: with NSLiteralSearch result is %ld", (long)cr);

        CFStringRef cfw1 = (__bridge CFStringRef)w1;
        CFStringRef cfw2 = (__bridge CFStringRef)w2;

        NSLog(@"CFStringCompare result is %ld", (long)CFStringCompare(cfw1, cfw2, 0l));

        NSLog(@"CFStringCompare Nonliteral result is %ld", (long)CFStringCompare(cfw1, cfw2, kCFCompareNonliteral));
    }
    return 0;
}

outputs

2023-11-08 13:06:28.680697+0100 TestCFStringCompare[56288:2328514] NSString compare: result is 1
2023-11-08 13:06:28.681317+0100 TestCFStringCompare[56288:2328514] NSString compare: with NSLiteralSearch result is -1
2023-11-08 13:06:28.681601+0100 TestCFStringCompare[56288:2328514] CFStringCompare result is -1
2023-11-08 13:06:28.681662+0100 TestCFStringCompare[56288:2328514] CFStringCompare Nonliteral result is 1
Program ended with exit code: 0

Possible fixes

CFCompareString should be called with kCFCompareNonliteral.

See iosxwstr.patch