Another path fix

This commit is contained in:
rfm 2023-12-19 14:24:13 +00:00
parent cead13c823
commit c739ac81bd
4 changed files with 83 additions and 5 deletions

View file

@ -1,7 +1,17 @@
2023-12-09 Richard Frith-Macdonald <rfm@gnu.org>
* Source/objc-load.m:
* Source/GSPrivate.h:
In GSPrivateSymbolPath() check for dladdr returning argv[0] as the
file path, and map it to the path of the executable so bundle checks
for the location of the file containing the code can work consistently.
2023-12-06 Daniel Boyd <danieljboyd@icloud.com>
* Source/NSDecimal.m:
For compare, handle the case where one or both operands are zero.
* Tests/base/NSNumber/test03.m: add tests
2023-12-05 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -496,7 +496,8 @@ GSPrivateStrExternalize(GSStr s) GS_ATTRIB_PRIVATE;
* module. So it returns the full filesystem path for shared libraries
* and bundles (which is very nice), but unfortunately it returns
* argv[0] (which might be something as horrible as './obj/test')
* for classes in the main executable.
* for classes in the main executable. In this case we return the
* full path to the executable rather than the value from the linker.
*
* Currently, the function will return nil if any of the following
* conditions is satisfied:

View file

@ -277,11 +277,23 @@ NSString *GSPrivateSymbolPath(Class theClass)
*/
if (0 != dladdr((void*)theClass, &info))
{
NSString *s;
/* On some platforms, when the symbol is in the executable, the
* dladdr() function returns the value from argv[0] as the path.
* So we check for that and map it to the full path of the
* executable.
*/
if (strcmp(info.dli_fname, GSPrivateArgZero()) == 0)
{
return GSPrivateExecutablePath();
}
else
{
NSString *s;
s = [NSString stringWithUTF8String: info.dli_fname];
s = [s stringByResolvingSymlinksInPath];
return [s stringByStandardizingPath];
s = [NSString stringWithUTF8String: info.dli_fname];
s = [s stringByResolvingSymlinksInPath];
return [s stringByStandardizingPath];
}
}
#endif

View file

@ -0,0 +1,55 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDecimalNumber.h>
int main()
{
START_SET("GSDecimalCompare")
NSDecimalNumber *n1;
NSDecimalNumber *n2;
NSComparisonResult result;
// Test comparing positive numbers
n1 = [NSDecimalNumber decimalNumberWithString:@"0.05"];
n2 = [NSDecimalNumber decimalNumberWithString:@"0.10"];
result = [n1 compare:n2];
PASS(result == NSOrderedAscending, "0.05 < 0.10");
// Test comparing negative numbers
n1 = [NSDecimalNumber decimalNumberWithString:@"-0.10"];
n2 = [NSDecimalNumber decimalNumberWithString:@"-0.05"];
result = [n1 compare:n2];
PASS(result == NSOrderedAscending, "-0.10 < -0.05");
// Test comparing a positive and a negative number
n1 = [NSDecimalNumber decimalNumberWithString:@"-0.10"];
n2 = [NSDecimalNumber decimalNumberWithString:@"0.10"];
result = [n1 compare:n2];
PASS(result == NSOrderedAscending, "-0.10 < 0.10");
// Test comparing zeros
n1 = [NSDecimalNumber decimalNumberWithString:@"0.00"];
n2 = [NSDecimalNumber decimalNumberWithString:@"0.00"];
result = [n1 compare:n2];
PASS(result == NSOrderedSame, "0.00 == 0.00");
// Test comparing zero with a positive number
n1 = [NSDecimalNumber decimalNumberWithString:@"0.00"];
n2 = [NSDecimalNumber decimalNumberWithString:@"0.02"];
result = [n1 compare:n2];
PASS(result == NSOrderedAscending, "0.00 < 0.02");
// Test comparing zero with a negative number
n1 = [NSDecimalNumber decimalNumberWithString:@"-0.02"];
n2 = [NSDecimalNumber decimalNumberWithString:@"0.00"];
result = [n1 compare:n2];
PASS(result == NSOrderedAscending, "-0.02 < 0.00");
// Add more test cases as needed to cover edge cases and other scenarios
END_SET("GSDecimalCompare")
return 0;
}