Index: src/OFNotificationCenter.h ================================================================== --- src/OFNotificationCenter.h +++ src/OFNotificationCenter.h @@ -119,8 +119,29 @@ * @brief Posts the specified notification. * * @param notification The notification to post */ - (void)postNotification: (OFNotification *)notification; + +/** + * @brief Posts a notification with the specified name and object. + * + * @param name The name for the notification + * @param object The object for the notification + */ +- (void)postNotificationName: (OFNotificationName)name + object: (nullable id)object; + +/** + * @brief Posts a notification with the specified name, object and additional + * information. + * + * @param name The name for the notification + * @param object The object for the notification + * @param userInfo Additional information for the notification + */ +- (void)postNotificationName: (OFNotificationName)name + object: (nullable id)object + userInfo: (nullable OFDictionary *)userInfo; @end OF_ASSUME_NONNULL_END Index: src/OFNotificationCenter.m ================================================================== --- src/OFNotificationCenter.m +++ src/OFNotificationCenter.m @@ -105,14 +105,14 @@ - (void)dealloc { [_name release]; [_observer release]; + [_object release]; #ifdef OF_HAVE_BLOCKS [_block release]; #endif - [_object release]; [super dealloc]; } - (bool)isEqual: (OFNotificationCenterHandle *)handle @@ -267,10 +267,12 @@ } #endif - (void)removeObserver: (OFNotificationCenterHandle *)handle { + void *pool = objc_autoreleasePoolPush(); + if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; #ifdef OF_HAVE_THREADS [_mutex lock]; @@ -286,10 +288,12 @@ #ifdef OF_HAVE_THREADS } @finally { [_mutex unlock]; } #endif + + objc_autoreleasePoolPop(pool); } - (void)removeObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name @@ -342,10 +346,30 @@ notification); #ifdef OF_HAVE_BLOCKS } #endif } + + objc_autoreleasePoolPop(pool); +} + +- (void)postNotificationName: (OFNotificationName)name + object: (nullable id)object +{ + [self postNotificationName: name object: object userInfo: nil]; +} + +- (void)postNotificationName: (OFNotificationName)name + object: (nullable id)object + userInfo: (nullable OFDictionary *)userInfo +{ + void *pool = objc_autoreleasePoolPush(); + + [self postNotification: + [OFNotification notificationWithName: name + object: object + userInfo: userInfo]]; objc_autoreleasePoolPop(pool); } @end Index: tests/OFNotificationCenterTests.m ================================================================== --- tests/OFNotificationCenterTests.m +++ tests/OFNotificationCenterTests.m @@ -121,11 +121,11 @@ received = true; }]) && R([center postNotification: notification]) && received && test1->_received == 2 && test2->_received == 4 && test3->_received == 0 && test4->_received == 0) - /* Act like the blocks test didn't happen. */ + /* Act like the block test didn't happen. */ [center removeObserver: handle]; test1->_received--; test2->_received--; #endif