mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
parent
6681a3da47
commit
c981920679
6 changed files with 21 additions and 111 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,13 +1,3 @@
|
||||||
2024-11-11 Richard Frith-Macdonald <rfm@gnu.org>
|
|
||||||
|
|
||||||
* Source/NSConcreteHashTable.m:
|
|
||||||
* Source/NSConcreteMapTable.m:
|
|
||||||
* Source/NSConcretePointerFunctions.h:
|
|
||||||
* Tests/base/NSHashTable/general.m:
|
|
||||||
* Tests/base/NSMapTable/general.m:
|
|
||||||
Fix for strong memory hash/map table retain count with some simple
|
|
||||||
testcases. Arising from Larry Campbell's comments.
|
|
||||||
|
|
||||||
2024-11-09 Richard Frith-Macdonald <rfm@gnu.org>
|
2024-11-09 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSNotificationCenter.m:
|
* Source/NSNotificationCenter.m:
|
||||||
|
@ -20,7 +10,7 @@
|
||||||
* Headers/Foundation/NSFileHandle.h:
|
* Headers/Foundation/NSFileHandle.h:
|
||||||
* Source/GSFileHandle.m:
|
* Source/GSFileHandle.m:
|
||||||
* Source/NSFileHandle.m:
|
* Source/NSFileHandle.m:
|
||||||
Add OSX 10.15 file offset methods (issue #325, pull #446 and more)
|
Add OSX 10.15 file offset methods (issue 325, pull 446 and more)
|
||||||
|
|
||||||
2024-11-03 Richard Frith-Macdonald <rfm@gnu.org>
|
2024-11-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
|
|
@ -87,16 +87,18 @@ typedef GSIMapNode_t *GSIMapNode;
|
||||||
(M->legacy ? M->cb.old.release(M, X.ptr) \
|
(M->legacy ? M->cb.old.release(M, X.ptr) \
|
||||||
: IS_WEAK(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf, &X.ptr))
|
: IS_WEAK(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf, &X.ptr))
|
||||||
#define GSI_MAP_RETAIN_KEY(M, X)\
|
#define GSI_MAP_RETAIN_KEY(M, X)\
|
||||||
(M->legacy ? M->cb.old.retain(M, X.ptr) : (IS_WEAK(M) ? nil : X.ptr))
|
(M->legacy ? M->cb.old.retain(M, X.ptr) \
|
||||||
|
: IS_WEAK(M) ? nil : pointerFunctionsAssign(\
|
||||||
|
&M->cb.pf, &X.ptr, pointerFunctionsAcquire(&M->cb.pf, X.ptr)))
|
||||||
#define GSI_MAP_ZEROED(M)\
|
#define GSI_MAP_ZEROED(M)\
|
||||||
(M->legacy ? 0 \
|
(M->legacy ? 0 \
|
||||||
: (IS_WEAK(M) ? YES : NO))
|
: (IS_WEAK(M) ? YES : NO))
|
||||||
|
|
||||||
#define GSI_MAP_WRITE_KEY(M, addr, x) \
|
#define GSI_MAP_WRITE_KEY(M, addr, x) \
|
||||||
if (M->legacy) \
|
if (M->legacy) \
|
||||||
*(addr) = x;\
|
*(addr) = x;\
|
||||||
else\
|
else\
|
||||||
pointerFunctionsReplace(&M->cb.pf, (void**)addr, (x).obj);
|
pointerFunctionsAssign(&M->cb.pf, (void**)addr, (x).obj);
|
||||||
#define GSI_MAP_READ_KEY(M,addr) \
|
#define GSI_MAP_READ_KEY(M,addr) \
|
||||||
(M->legacy ? *(addr) :\
|
(M->legacy ? *(addr) :\
|
||||||
(__typeof__(*addr))pointerFunctionsRead(&M->cb.pf, (void**)addr))
|
(__typeof__(*addr))pointerFunctionsRead(&M->cb.pf, (void**)addr))
|
||||||
|
|
|
@ -94,12 +94,16 @@ typedef GSIMapNode_t *GSIMapNode;
|
||||||
(M->legacy ? M->cb.old.k.release(M, X.ptr) \
|
(M->legacy ? M->cb.old.k.release(M, X.ptr) \
|
||||||
: IS_WEAK_KEY(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.k, &X.ptr))
|
: IS_WEAK_KEY(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.k, &X.ptr))
|
||||||
#define GSI_MAP_RETAIN_KEY(M, X)\
|
#define GSI_MAP_RETAIN_KEY(M, X)\
|
||||||
(M->legacy ? M->cb.old.k.retain(M, X.ptr) : (IS_WEAK_KEY(M) ? nil : X.ptr))
|
(M->legacy ? M->cb.old.k.retain(M, X.ptr) \
|
||||||
|
: IS_WEAK_KEY(M) ? nil : pointerFunctionsAssign(&M->cb.pf.k, &X.ptr,\
|
||||||
|
pointerFunctionsAcquire(&M->cb.pf.k, X.ptr)))
|
||||||
#define GSI_MAP_RELEASE_VAL(M, X)\
|
#define GSI_MAP_RELEASE_VAL(M, X)\
|
||||||
(M->legacy ? M->cb.old.v.release(M, X.ptr) \
|
(M->legacy ? M->cb.old.v.release(M, X.ptr) \
|
||||||
: IS_WEAK_VALUE(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.v, &X.ptr))
|
: IS_WEAK_VALUE(M) ? nil : pointerFunctionsRelinquish(&M->cb.pf.v, &X.ptr))
|
||||||
#define GSI_MAP_RETAIN_VAL(M, X)\
|
#define GSI_MAP_RETAIN_VAL(M, X)\
|
||||||
(M->legacy ? M->cb.old.v.retain(M, X.ptr) : (IS_WEAK_VALUE(M) ? nil : &X.ptr))
|
(M->legacy ? M->cb.old.v.retain(M, X.ptr) \
|
||||||
|
: IS_WEAK_VALUE(M) ? nil : pointerFunctionsAssign(&M->cb.pf.v, &X.ptr,\
|
||||||
|
pointerFunctionsAcquire(&M->cb.pf.v, X.ptr)))
|
||||||
|
|
||||||
/* The GSI_MAP_WRITE_KEY() and GSI_MAP_WRITE_VAL() macros are expectd to
|
/* The GSI_MAP_WRITE_KEY() and GSI_MAP_WRITE_VAL() macros are expectd to
|
||||||
* write without retain (GSI_MAP RETAIN macros are executed separately)
|
* write without retain (GSI_MAP RETAIN macros are executed separately)
|
||||||
|
@ -110,12 +114,14 @@ typedef GSIMapNode_t *GSIMapNode;
|
||||||
if (M->legacy) \
|
if (M->legacy) \
|
||||||
*(addr) = x;\
|
*(addr) = x;\
|
||||||
else\
|
else\
|
||||||
pointerFunctionsReplace(&M->cb.pf.k, (void**)addr, (x).obj);
|
(IS_WEAK_KEY(M) ? pointerFunctionsAssign(&M->cb.pf.k, (void**)addr,\
|
||||||
|
(x).obj) : (*(id*)(addr) = (x).obj));
|
||||||
#define GSI_MAP_WRITE_VAL(M, addr, x) \
|
#define GSI_MAP_WRITE_VAL(M, addr, x) \
|
||||||
if (M->legacy) \
|
if (M->legacy) \
|
||||||
*(addr) = x;\
|
*(addr) = x;\
|
||||||
else\
|
else\
|
||||||
pointerFunctionsReplace(&M->cb.pf.v, (void**)addr, (x).obj);
|
(IS_WEAK_VALUE(M) ? pointerFunctionsAssign(&M->cb.pf.v, (void**)addr,\
|
||||||
|
(x).obj) : (*(id*)(addr) = (x).obj));
|
||||||
#define GSI_MAP_READ_KEY(M,addr) \
|
#define GSI_MAP_READ_KEY(M,addr) \
|
||||||
(M->legacy ? *(addr)\
|
(M->legacy ? *(addr)\
|
||||||
: (__typeof__(*addr))pointerFunctionsRead(&M->cb.pf.k, (void**)addr))
|
: (__typeof__(*addr))pointerFunctionsRead(&M->cb.pf.k, (void**)addr))
|
||||||
|
|
|
@ -187,8 +187,6 @@ pointerFunctionsRelinquish(PFInfo *PF, void **itemptr)
|
||||||
(*PF->relinquishFunction)(*itemptr, PF->sizeFunction);
|
(*PF->relinquishFunction)(*itemptr, PF->sizeFunction);
|
||||||
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
|
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
|
||||||
WEAK_WRITE(itemptr, 0);
|
WEAK_WRITE(itemptr, 0);
|
||||||
else if (memoryType(PF->options, NSPointerFunctionsStrongMemory))
|
|
||||||
STRONG_WRITE(itemptr, 0);
|
|
||||||
else
|
else
|
||||||
*itemptr = 0;
|
*itemptr = 0;
|
||||||
}
|
}
|
||||||
|
@ -205,7 +203,7 @@ pointerFunctionsReplace(PFInfo *PF, void **dst, void *src)
|
||||||
if (PF->relinquishFunction != 0)
|
if (PF->relinquishFunction != 0)
|
||||||
(*PF->relinquishFunction)(*dst, PF->sizeFunction);
|
(*PF->relinquishFunction)(*dst, PF->sizeFunction);
|
||||||
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
|
if (memoryType(PF->options, NSPointerFunctionsWeakMemory))
|
||||||
WEAK_WRITE(dst, src);
|
WEAK_WRITE(dst, 0);
|
||||||
else
|
else
|
||||||
*dst = src;
|
*dst = src;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +1,9 @@
|
||||||
#import <Foundation/NSAutoreleasePool.h>
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
#import <Foundation/NSHashTable.h>
|
|
||||||
#import "ObjectTesting.h"
|
#import "ObjectTesting.h"
|
||||||
|
|
||||||
@interface MyClass: NSObject
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation MyClass
|
|
||||||
#if 0
|
|
||||||
- (oneway void) release
|
|
||||||
{
|
|
||||||
NSLog(@"releasing %u", (unsigned)[self retainCount]);
|
|
||||||
[super release];
|
|
||||||
}
|
|
||||||
- (id) retain
|
|
||||||
{
|
|
||||||
id result = [super retain];
|
|
||||||
|
|
||||||
NSLog(@"retained %u", (unsigned)[self retainCount]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@end
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSHashTable *t;
|
|
||||||
MyClass *o;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
t = [[NSHashTable alloc] initWithOptions: NSHashTableObjectPointerPersonality
|
|
||||||
capacity: 10];
|
|
||||||
|
|
||||||
o = [MyClass new];
|
|
||||||
c = [o retainCount];
|
|
||||||
PASS(c == 1, "initial retain count is one")
|
|
||||||
|
|
||||||
[t addObject: @"a"];
|
|
||||||
[t addObject: o];
|
|
||||||
PASS([o retainCount] == c + 1, "add to hash table increments retain count")
|
|
||||||
|
|
||||||
// PASS(NSHashGet(t, o) == o, "object found in table")
|
|
||||||
|
|
||||||
[t removeObject: o];
|
|
||||||
PASS([o retainCount] == c, "remove from hash table decrements retain count")
|
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release]; arp = nil;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,55 +1,9 @@
|
||||||
#import <Foundation/NSAutoreleasePool.h>
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
#import "ObjectTesting.h"
|
#import "ObjectTesting.h"
|
||||||
#import <Foundation/NSMapTable.h>
|
|
||||||
|
|
||||||
@interface MyClass: NSObject
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation MyClass
|
|
||||||
#if 1
|
|
||||||
- (oneway void) release
|
|
||||||
{
|
|
||||||
NSLog(@"releasing %u", (unsigned)[self retainCount]);
|
|
||||||
[super release];
|
|
||||||
}
|
|
||||||
- (id) retain
|
|
||||||
{
|
|
||||||
id result = [super retain];
|
|
||||||
|
|
||||||
NSLog(@"retained %u", (unsigned)[self retainCount]);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@end
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSMapTable *t;
|
|
||||||
MyClass *o;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
t = [[NSMapTable alloc] initWithKeyOptions: NSMapTableObjectPointerPersonality
|
|
||||||
valueOptions: NSMapTableObjectPointerPersonality
|
|
||||||
capacity: 10];
|
|
||||||
|
|
||||||
o = [MyClass new];
|
|
||||||
c = [o retainCount];
|
|
||||||
PASS(c == 1, "initial retain count is one")
|
|
||||||
|
|
||||||
[t setObject: @"a" forKey: o];
|
|
||||||
PASS([o retainCount] == c + 1, "add map table key increments retain count")
|
|
||||||
|
|
||||||
// PASS(NSHashGet(t, o) == o, "object found in table")
|
|
||||||
|
|
||||||
[t removeObjectForKey: o];
|
|
||||||
PASS([o retainCount] == c, "remove map table key decrements retain count")
|
|
||||||
|
|
||||||
[t setObject: o forKey: @"a"];
|
|
||||||
PASS([o retainCount] == c + 1, "add map table val increments retain count")
|
|
||||||
|
|
||||||
[t removeObjectForKey: @"a"];
|
|
||||||
PASS([o retainCount] == c, "remove map table val decrements retain count")
|
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release]; arp = nil;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue