mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
More tweaks for garbage collection mode, including making NSNotificationCenter use weak pointers (things are never removed if it uses strong pointers because they remove themselves in the -dealloc method, which is never called, and can't remove themselves in the -finalize method because the -finalize method would not be called until after they have been removed - this is consistent with Apple behaviour).
Gorm now works correctly when built with GC enabled. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33109 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a439972605
commit
b08b2d0f34
7 changed files with 20 additions and 26 deletions
|
@ -308,14 +308,14 @@ enum {
|
|||
* garbage collected itsself.<br />
|
||||
* In any case the memory returned is zero'ed.
|
||||
*/
|
||||
GS_EXPORT void *
|
||||
GS_EXPORT __strong void *
|
||||
NSAllocateCollectable(NSUInteger size, NSUInteger options);
|
||||
|
||||
/** Reallocate memory to be of a different size and/or to have different
|
||||
* options settings. The behavior of options is as for
|
||||
* the NSAllocateCollectable() function.
|
||||
*/
|
||||
GS_EXPORT void *
|
||||
GS_EXPORT __strong void *
|
||||
NSReallocateCollectable(void *ptr, NSUInteger size, NSUInteger options);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -390,11 +390,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
|||
len -= sizeof(unichar);
|
||||
memcpy(&u, from, sizeof(unichar));
|
||||
from += sizeof(unichar);
|
||||
#if GS_WITH_GC
|
||||
to = NSAllocateCollectable(len, 0);
|
||||
#else
|
||||
to = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
#endif
|
||||
if (u == 0xFEFF)
|
||||
{
|
||||
// Native byte order
|
||||
|
@ -443,11 +439,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
|||
// Got a byte order marker ... remove it.
|
||||
len -= 3;
|
||||
from += 3;
|
||||
#if GS_WITH_GC
|
||||
to = NSAllocateCollectable(len, 0);
|
||||
#else
|
||||
to = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
#endif
|
||||
memcpy(to, from, len);
|
||||
if (*owned == YES)
|
||||
{
|
||||
|
@ -485,7 +477,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
|
|||
*/
|
||||
if (original == bytes)
|
||||
{
|
||||
#if GS_WITH_GC
|
||||
#if GS_WITH_GC || __OBJC_GC__
|
||||
chars = NSAllocateCollectable(length, 0);
|
||||
#else
|
||||
chars = NSZoneMalloc([self zone], length);
|
||||
|
|
|
@ -575,11 +575,7 @@ failure:
|
|||
format: @"[%@-initWithBytes:length:] called with "
|
||||
@"length but null bytes", NSStringFromClass([self class])];
|
||||
}
|
||||
#if GS_WITH_GC
|
||||
ptr = NSAllocateCollectable(bufferSize, 0);
|
||||
#else
|
||||
ptr = NSZoneMalloc(NSDefaultMallocZone(), bufferSize);
|
||||
#endif
|
||||
if (ptr == 0)
|
||||
{
|
||||
DESTROY(self);
|
||||
|
|
|
@ -443,7 +443,7 @@ next_arg(const char *typePtr, NSArgumentInfo *info, char *outTypes)
|
|||
alen = ptr - args;
|
||||
rlen += sprintf(ret + rlen, "%d", (int)_argFrameLength);
|
||||
|
||||
_methodTypes = NSZoneMalloc(NSDefaultMallocZone(), alen + rlen + 1);
|
||||
_methodTypes = NSAllocateCollectable(alen + rlen + 1, 0);
|
||||
strncpy((char*)_methodTypes, ret, rlen);
|
||||
strncpy(((char*)_methodTypes) + rlen, args, alen);
|
||||
((char*)_methodTypes)[alen + rlen] = '\0';
|
||||
|
|
|
@ -142,7 +142,7 @@ struct NCTbl; /* Notification Center Table structure */
|
|||
*/
|
||||
|
||||
typedef struct Obs {
|
||||
id observer; /* Object to receive message. */
|
||||
__weak id observer; /* Object to receive message. */
|
||||
SEL selector; /* Method selector. */
|
||||
IMP method; /* Method implementation. */
|
||||
struct Obs *next; /* Next item in linked list. */
|
||||
|
|
|
@ -494,7 +494,7 @@ NSDecrementExtraRefCountWasZero(id anObject)
|
|||
inline NSUInteger
|
||||
NSExtraRefCount(id anObject)
|
||||
{
|
||||
#if GS_WITH_GC
|
||||
#if GS_WITH_GC || __OBJC_GC__
|
||||
return UINT_MAX - 1;
|
||||
#else /* GS_WITH_GC */
|
||||
return ((obj)anObject)[-1].retained;
|
||||
|
@ -1723,7 +1723,7 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
|||
*/
|
||||
- (id) autorelease
|
||||
{
|
||||
#if GS_WITH_GC == 0
|
||||
#if !GS_WITH_GC && !__OBJC_GC__
|
||||
if (double_release_check_enabled)
|
||||
{
|
||||
NSUInteger release_count;
|
||||
|
@ -1935,7 +1935,7 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
|||
*/
|
||||
- (oneway void) release
|
||||
{
|
||||
#if GS_WITH_GC == 0 && !__OBJC_GC__
|
||||
#if (GS_WITH_GC == 0) && !__OBJC_GC__
|
||||
if (NSDecrementExtraRefCountWasZero(self))
|
||||
{
|
||||
[self dealloc];
|
||||
|
@ -1985,7 +1985,7 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
|||
*/
|
||||
- (id) retain
|
||||
{
|
||||
#if GS_WITH_GC == 0 && !__OBJC_GC__
|
||||
#if (GS_WITH_GC == 0) && !__OBJC_GC__
|
||||
NSIncrementExtraRefCount(self);
|
||||
#endif
|
||||
return self;
|
||||
|
@ -2012,7 +2012,7 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
|||
*/
|
||||
- (NSUInteger) retainCount
|
||||
{
|
||||
#if GS_WITH_GC
|
||||
#if GS_WITH_GC || __OBJC_GC__
|
||||
return UINT_MAX;
|
||||
#else
|
||||
return NSExtraRefCount(self) + 1;
|
||||
|
@ -2042,7 +2042,7 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
|||
*/
|
||||
- (NSZone*) zone
|
||||
{
|
||||
#if GS_WITH_GC
|
||||
#if GS_WITH_GC || __OBJC_GC__
|
||||
/* MacOS-X 10.5 seems to return the default malloc zone if GC is enabled.
|
||||
*/
|
||||
return NSDefaultMallocZone();
|
||||
|
|
|
@ -230,14 +230,20 @@ NSZoneName (NSZone *zone)
|
|||
#if __OBJC_GC__
|
||||
|
||||
#include <objc/objc-auto.h>
|
||||
void *
|
||||
|
||||
__strong void *
|
||||
NSAllocateCollectable(NSUInteger size, NSUInteger options)
|
||||
{
|
||||
return objc_gc_allocate_collectable(size,
|
||||
id obj = objc_gc_allocate_collectable(size,
|
||||
((options & NSScannedOption) == NSScannedOption));
|
||||
if ((options & NSCollectorDisabledOption) == NSCollectorDisabledOption)
|
||||
{
|
||||
obj = objc_gc_retain(obj);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
void *
|
||||
__strong void *
|
||||
NSReallocateCollectable(void *ptr, NSUInteger size, NSUInteger options)
|
||||
{
|
||||
return objc_gc_reallocate_collectable(ptr, size,
|
||||
|
|
Loading…
Reference in a new issue