mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Add testcases and corrected code to check for GSMacOSXCompatibility mode
when unlocking fails. Also put more detail in the warning message
This commit is contained in:
parent
05dd8a4c2a
commit
65163ebf48
2 changed files with 31 additions and 4 deletions
|
@ -63,7 +63,6 @@ static Class untracedLockClass = Nil;
|
|||
static Class untracedRecursiveLockClass = Nil;
|
||||
|
||||
static BOOL traceLocks = NO;
|
||||
static BOOL compatible = NO;
|
||||
|
||||
@implementation NSObject (GSTraceLocks)
|
||||
|
||||
|
@ -250,10 +249,15 @@ static BOOL compatible = NO;
|
|||
{\
|
||||
if (0 != GS_MUTEX_UNLOCK(_mutex))\
|
||||
{\
|
||||
if (compatible)\
|
||||
if (GSPrivateDefaultsFlag(GSMacOSXCompatible))\
|
||||
{\
|
||||
NSLog(@"Failed to unlock mutex %@ at %@",\
|
||||
self, [NSThread callStackSymbols]);\
|
||||
}\
|
||||
else \
|
||||
{\
|
||||
[NSException raise: NSLockException\
|
||||
format: @"failed to unlock mutex"];\
|
||||
format: @"failed to unlock mutex %@", self];\
|
||||
}\
|
||||
}\
|
||||
CHK(Drop) \
|
||||
|
@ -349,7 +353,6 @@ NSString *NSLockException = @"NSLockException";
|
|||
untracedConditionLockClass = [GSUntracedConditionLock class];
|
||||
untracedLockClass = [GSUntracedLock class];
|
||||
untracedRecursiveLockClass = [GSUntracedRecursiveLock class];
|
||||
compatible = (strcmp(getenv("NSLOCK_COMPATIBLE"), "YES") == 0) ? YES : NO;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
24
Tests/base/NSLock/unbalancedUnlock.m
Normal file
24
Tests/base/NSLock/unbalancedUnlock.m
Normal file
|
@ -0,0 +1,24 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "Testing.h"
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
START_SET("Unbalanced unlocking")
|
||||
|
||||
NSLock *lock;
|
||||
|
||||
lock = [NSLock new];
|
||||
|
||||
PASS_EXCEPTION([lock unlock], @"NSLockException",
|
||||
"unlocking an unlocked lock raises NSLockException")
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setBool: YES
|
||||
forKey: @"GSMacOSXCompatible"];
|
||||
|
||||
PASS_RUNS([lock unlock],
|
||||
"unlocking an unlocked lock does not raise in MacOSX compatibility mode")
|
||||
|
||||
END_SET("Unbalanced unlocking")
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue