Skip to content

Commit

Permalink
Weak pointer support fixes and use for notification observers.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Dec 27, 2024
1 parent 882ded1 commit 4a477aa
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 115 deletions.
24 changes: 24 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
2024-12-27 Richard Frith-Macdonald <rfm@gnu.org>

* Headers/GNUstepBase/GSIMap.h:
* Headers/GNUstepBase/GSObjCRuntime.h:
* Source/GSPrivate.h:
* Source/NSConcreteHashTable.m:
* Source/NSConcretePointerFunctions.h:
* Source/NSNotificationCenter.m:
* Source/NSObject.m:
* Source/ObjectiveC2/GNUmakefile:
* Source/ObjectiveC2/README:
* Source/ObjectiveC2/weak.m:
* Tests/base/Functions/runtime.m:
* Tests/base/NSHashTable/weakObjects.m:
* Tests/base/NSMapTable/weakObjects.m:
* Tests/base/NSNotification/general.m:
* Tests/base/NSPointerArray/weakObjects.m:
Implement weak objects API support for classic/gnu runtime.
Use it to implement weak reference support in NSPointerFunctions
(for NSMapTable, NSHashTable, NSP{ointerArray) and to implement
safe observer support for NSNotificationCenter (if an observer is
deallocated then it is removed from the notification center the
next time a notification woudl be posted to it).

2024-11-29 Richard Frith-Macdonald <rfm@gnu.org>

* Source/NSURLProtocol.m: fix leaks due to retain loops.
Expand Down
12 changes: 12 additions & 0 deletions Headers/GNUstepBase/GSObjCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
#endif
#endif

#if defined(OBJC_CAP_ARC)
# include <objc/objc-arc.h>
#else
GS_EXPORT void objc_copyWeak(id *dest, id *src);
GS_EXPORT void objc_destroyWeak(id *obj);
GS_EXPORT id objc_initWeak(id *addr, id obj);
GS_EXPORT id objc_loadWeak(id *object);
GS_EXPORT id objc_loadWeakRetained(id *addr);
GS_EXPORT void objc_moveWeak(id *dest, id *src);
GS_EXPORT id objc_storeWeak(id *addr, id obj);
#endif

/*
* Hack for older compiler versions that don't have all defines
* needed in objc-api.h
Expand Down
12 changes: 5 additions & 7 deletions Source/NSConcretePointerFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@
# include <objc/capabilities.h>
#endif

#import "GNUstepBase/GSObjCRuntime.h"

#define WEAK_READ(x) objc_loadWeak((id*)x)
#define WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)

#if defined(OBJC_CAP_ARC)
# include <objc/objc-arc.h>
# define WEAK_READ(x) objc_loadWeak((id*)x)
# define WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)
# define STRONG_WRITE(addr, x) objc_storeStrong((id*)addr, (id)x)
# define STRONG_ACQUIRE(x) objc_retain(x)
#else
extern id objc_loadWeak(id *object);
extern id objc_storeWeak(id *addr, id obj);
# define WEAK_READ(x) objc_loadWeak((id*)x)
# define WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)
# define STRONG_WRITE(addr, x) ASSIGN(*((id*)addr), ((id)x))
# define STRONG_ACQUIRE(x) RETAIN(((id)x))
#endif
Expand Down
Loading

0 comments on commit 4a477aa

Please sign in to comment.