Skip to content

Commit

Permalink
Another path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Dec 19, 2023
1 parent cead13c commit c739ac8
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
2023-12-09 Richard Frith-Macdonald <[email protected]>

* 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 <[email protected]>

* 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 <[email protected]>

Expand Down
3 changes: 2 additions & 1 deletion Source/GSPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 16 additions & 4 deletions Source/objc-load.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,23 @@
*/
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

Expand Down
55 changes: 55 additions & 0 deletions Tests/base/NSNumber/test03.m
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit c739ac8

Please sign in to comment.