mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix for #334
This commit is contained in:
parent
e8b67e3e0b
commit
b4feee311f
3 changed files with 41 additions and 38 deletions
|
@ -2,6 +2,9 @@
|
|||
|
||||
* Source/NSFileManager.m: Fix issue #292
|
||||
* Tests/base/NSFileManager/general.m: test for enumerator at URL
|
||||
* Source/NSNotificationCenter.m: fix indentation/style errors
|
||||
* Headers/GNUstepBase/GSBlocks.h: Add new macros for calling blocks
|
||||
which return a value.
|
||||
|
||||
2023-11-14 Richard Frith-Macdonald <rfm@gnu.org> Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
|
|
|
@ -107,8 +107,11 @@ typedef retTy(^name)()
|
|||
|
||||
#endif /* __has_feature(blocks) */
|
||||
|
||||
#define CALL_BLOCK(block, args...) ((NULL != block) ? CALL_NON_NULL_BLOCK(block, args) : nil)
|
||||
#define CALL_BLOCK_NO_ARGS(block) ((NULL != block) ? CALL_NON_NULL_BLOCK_NO_ARGS(block) : nil)
|
||||
#define CALL_BLOCK(block, args...) ({if (NULL != block) CALL_NON_NULL_BLOCK(block, args);})
|
||||
#define CALL_BLOCK_RET(block, rettype, args...) ((NULL != block) ? (rettype)CALL_NON_NULL_BLOCK(block, args) : (rettype)0)
|
||||
|
||||
#define CALL_BLOCK_NO_ARGS(block) ({if (NULL != block) CALL_NON_NULL_BLOCK_NO_ARGS(block);})
|
||||
#define CALL_BLOCK_RET_NO_ARGS(block, rettype) ((NULL != block) ? (rettype)CALL_NON_NULL_BLOCK_NO_ARGS(block) : (rettype)0)
|
||||
|
||||
#if __has_include(<objc/blocks_runtime.h>)
|
||||
# include <objc/blocks_runtime.h>
|
||||
|
|
|
@ -543,8 +543,8 @@ purgeMapNode(GSIMapTable map, GSIMapNode node, id observer)
|
|||
|
||||
@interface GSNotificationBlockOperation : NSOperation
|
||||
{
|
||||
NSNotification *_notification;
|
||||
GSNotificationBlock _block;
|
||||
NSNotification *_notification;
|
||||
GSNotificationBlock _block;
|
||||
}
|
||||
|
||||
- (id) initWithNotification: (NSNotification *)notif
|
||||
|
@ -557,34 +557,32 @@ purgeMapNode(GSIMapTable map, GSIMapNode node, id observer)
|
|||
- (id) initWithNotification: (NSNotification *)notif
|
||||
block: (GSNotificationBlock)block
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil)
|
||||
return nil;
|
||||
|
||||
ASSIGN(_notification, notif);
|
||||
_block = Block_copy(block);
|
||||
return self;
|
||||
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
ASSIGN(_notification, notif);
|
||||
_block = Block_copy(block);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_notification);
|
||||
Block_release(_block);
|
||||
[super dealloc];
|
||||
DESTROY(_notification);
|
||||
Block_release(_block);
|
||||
DEALLOC
|
||||
}
|
||||
|
||||
- (void) main
|
||||
{
|
||||
CALL_BLOCK(_block, _notification);
|
||||
CALL_BLOCK(_block, _notification);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface GSNotificationObserver : NSObject
|
||||
{
|
||||
NSOperationQueue *_queue;
|
||||
GSNotificationBlock _block;
|
||||
NSOperationQueue *_queue;
|
||||
GSNotificationBlock _block;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -594,35 +592,34 @@ purgeMapNode(GSIMapTable map, GSIMapNode node, id observer)
|
|||
- (id) initWithQueue: (NSOperationQueue *)queue
|
||||
block: (GSNotificationBlock)block
|
||||
{
|
||||
self = [super init];
|
||||
if (self == nil)
|
||||
return nil;
|
||||
|
||||
ASSIGN(_queue, queue);
|
||||
_block = Block_copy(block);
|
||||
return self;
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
ASSIGN(_queue, queue);
|
||||
_block = Block_copy(block);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_queue);
|
||||
Block_release(_block);
|
||||
[super dealloc];
|
||||
DESTROY(_queue);
|
||||
Block_release(_block);
|
||||
DEALLOC
|
||||
}
|
||||
|
||||
- (void) didReceiveNotification: (NSNotification *)notif
|
||||
{
|
||||
if (_queue != nil)
|
||||
{
|
||||
GSNotificationBlockOperation *op = [[GSNotificationBlockOperation alloc]
|
||||
initWithNotification: notif block: _block];
|
||||
if (_queue != nil)
|
||||
{
|
||||
GSNotificationBlockOperation *op = [[GSNotificationBlockOperation alloc]
|
||||
initWithNotification: notif block: _block];
|
||||
|
||||
[_queue addOperation: op];
|
||||
}
|
||||
else
|
||||
{
|
||||
CALL_BLOCK(_block, notif);
|
||||
}
|
||||
[_queue addOperation: op];
|
||||
}
|
||||
else
|
||||
{
|
||||
CALL_BLOCK(_block, notif);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue