mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 17:51:01 +00:00
Add support to NSObject for automatically zeroing __weak references when using ARC.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33408 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e3694a2266
commit
57aca2c837
1 changed files with 22 additions and 0 deletions
|
@ -72,6 +72,15 @@
|
||||||
#define IN_NSOBJECT_M 1
|
#define IN_NSOBJECT_M 1
|
||||||
#import "GSPrivate.h"
|
#import "GSPrivate.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __GNUSTEP_RUNTIME__
|
||||||
|
#include <objc/capabilities.h>
|
||||||
|
#include <objc/hooks.h>
|
||||||
|
#ifdef OBJC_CAP_ARC
|
||||||
|
#include <objc/objc-arc.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* When this is `YES', every call to release/autorelease, checks to
|
/* When this is `YES', every call to release/autorelease, checks to
|
||||||
make sure isn't being set up to release itself too many times.
|
make sure isn't being set up to release itself too many times.
|
||||||
This does not need mutex protection. */
|
This does not need mutex protection. */
|
||||||
|
@ -993,8 +1002,18 @@ GSGarbageCollectorLog(char *msg, GC_word arg)
|
||||||
extern BOOL
|
extern BOOL
|
||||||
objc_create_block_classes_as_subclasses_of(Class super);
|
objc_create_block_classes_as_subclasses_of(Class super);
|
||||||
|
|
||||||
|
#ifdef OBJC_CAP_ARC
|
||||||
|
static id gs_weak_load(id obj)
|
||||||
|
{
|
||||||
|
return (NSExtraRefCount(obj) + 1) > 0 ? obj : nil;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
+ (void) load
|
+ (void) load
|
||||||
{
|
{
|
||||||
|
#ifdef OBJC_CAP_ARC
|
||||||
|
_objc_weak_load = gs_weak_load;
|
||||||
|
#endif
|
||||||
objc_create_block_classes_as_subclasses_of(self);
|
objc_create_block_classes_as_subclasses_of(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2029,6 +2048,9 @@ objc_create_block_classes_as_subclasses_of(Class super);
|
||||||
#if (GS_WITH_GC == 0)
|
#if (GS_WITH_GC == 0)
|
||||||
if (NSDecrementExtraRefCountWasZero(self))
|
if (NSDecrementExtraRefCountWasZero(self))
|
||||||
{
|
{
|
||||||
|
# ifdef OBJC_CAP_ARC
|
||||||
|
objc_delete_weak_refs(self);
|
||||||
|
# endif
|
||||||
[self dealloc];
|
[self dealloc];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue