Skip to content

Bring -compare: implementations inline with macos#508

Closed
ERobsham wants to merge 1 commit into
gnustep:masterfrom
ERobsham:dev/match-macos-compare
Closed

Bring -compare: implementations inline with macos#508
ERobsham wants to merge 1 commit into
gnustep:masterfrom
ERobsham:dev/match-macos-compare

Conversation

@ERobsham

Copy link
Copy Markdown
Contributor

updates the implementation of -compare: vs a nil argument to return the same results as the same code running on macos (output from a sample program on macos):

NSString 'compare:' nil arg: NSOrderedDescending
NSDate   'compare:' nil arg: NSOrderedSame
NSNumber 'compare:' nil arg: exceptions `-[__NSCFNumber compare:]: nil argument`

Related issue: #507

updates the implementation of `-compare:` vs a `nil` argument to return
the same results as the same code running on macos (output from a sample program on macos):
```
NSString 'compare:' nil arg: NSOrderedDescending
NSDate   'compare:' nil arg: NSOrderedSame
NSNumber 'compare:' nil arg: exceptions `-[__NSCFNumber compare:]: nil argument`
```
@ERobsham ERobsham requested a review from rfm as a code owner May 30, 2025 17:21

@rfm rfm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While removing the code to raise NSInvalidArgumentException for invalid arguments is not OK, modifying it to behave differently depending on the compatibility requested by the GSMacOSXCompatible user default would be great.

Traditionally that would have meant calling the -boolForKey: method to see whether runtime compatibility with undocumented/undefined/bad OSX behaviors had been requested. However, you can now also use the new GSMacOSXVersion() function to get the value of the default in the same format as the OSX version constants defined in GSVersionMacxros.h in order to match the undefined behaviors in particular versions of OSX.

This would allow you to set the GSMacOSXCompatible user default to make GNUstep behave as your framework expects until that framework is updated so that it's no longer needed.

@rfm rfm added enhancement Label issues that propose improvements to existing features. help wanted Mark issues that are open for contributions with this tag. macOS Use this tag for issues specifically pertaining to the macOS operating system. labels Jul 23, 2025
@rfm

rfm commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

Closing since the patch emulates an officially undefined behavior specific to a particular implementation/version (indeed, Apple documentation says that you must not pass nil to these methods) and the existing code in the base library is more rational and intuitive.

@rfm rfm closed this Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Label issues that propose improvements to existing features. help wanted Mark issues that are open for contributions with this tag. macOS Use this tag for issues specifically pertaining to the macOS operating system.

Development

Successfully merging this pull request may close these issues.

3 participants