Skip to content

Commit

Permalink
Fix for #334
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Nov 14, 2023
1 parent e8b67e3 commit b4feee3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
7 changes: 5 additions & 2 deletions Headers/GNUstepBase/GSBlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
69 changes: 33 additions & 36 deletions Source/NSNotificationCenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ static void listFree(Observation *list)

@interface GSNotificationBlockOperation : NSOperation
{
NSNotification *_notification;
GSNotificationBlock _block;
NSNotification *_notification;
GSNotificationBlock _block;
}

- (id) initWithNotification: (NSNotification *)notif
Expand All @@ -557,34 +557,32 @@ @implementation GSNotificationBlockOperation
- (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
Expand All @@ -594,35 +592,34 @@ @implementation GSNotificationObserver
- (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
Expand Down

0 comments on commit b4feee3

Please sign in to comment.