Author: rfm
Date: Tue Jun 21 17:34:42 2016
New Revision: 39895
URL: http://svn.gna.org/viewcvs/gnustep?rev=39895&view=rev
Log:
fixes to ensure that we don't return a client to a pool while it has
notification observers.
Modified:
libs/sqlclient/trunk/ChangeLog
libs/sqlclient/trunk/SQLClient.h
libs/sqlclient/trunk/SQLClient.m
libs/sqlclient/trunk/SQLClientPool.m
Modified: libs/sqlclient/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=39895&r1=39894&r2=39895&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog (original)
+++ libs/sqlclient/trunk/ChangeLog Tue Jun 21 17:34:42 2016
@@ -1,3 +1,11 @@
+2016-06-21 Richard Frith-Macdonald <[email protected]>
+
+ * SQLClient.h:
+ * SQLClient.m:
+ * SQLClientPool.m:
+ Allow easy removal of all database notification observers.
+ Remove all observers when a client is returned to a pool.
+
2016-05-06 Richard Frith-Macdonald <[email protected]>
* SQLClient.m: Fix bug in initialisation ordering.
Modified: libs/sqlclient/trunk/SQLClient.h
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=39895&r1=39894&r2=39895&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h (original)
+++ libs/sqlclient/trunk/SQLClient.h Tue Jun 21 17:34:42 2016
@@ -1305,8 +1305,13 @@
- (void) postNotificationName: (NSString*)name payload: (NSString*)more;
/** Removes anObserver as an observer for asynchronous notifications from
- * the database server. If name is omitted, the observer will be removed
- * for all names.
+ * the database server. Each removal matches one earlier addition, and the
+ * observer is not actually removed until all additions are balanced.<br />
+ * If name is omitted, the observer will be removed for all names and for
+ * all additions (ie complete removal is forced).<br />
+ * If anObserver is nil, the removal will be performed for all current
+ * observers (and if both name and anObserver are nil, then all observations
+ * are removed).
*/
- (void) removeObserver: (id)anObserver name: (NSString*)name;
@end
Modified: libs/sqlclient/trunk/SQLClient.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=39895&r1=39894&r2=39895&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m (original)
+++ libs/sqlclient/trunk/SQLClient.m Tue Jun 21 17:34:42 2016
@@ -3861,6 +3861,11 @@
{
NSMutableSet *set;
+ if (nil == anObserver)
+ {
+ [NSException raise: NSInvalidArgumentException
+ format: @"Attempt to add nil observer to SQL client"];
+ }
name = validName(name);
[lock lock];
NS_DURING
@@ -3940,41 +3945,58 @@
if (_observers != nil)
{
NSNotificationCenter *nc;
- NSMutableSet *set;
- NSEnumerator *e;
+ NSEnumerator *oe = nil;
nc = [NSNotificationCenter defaultCenter];
- set = (NSMutableSet*)NSMapGet(_observers, (void*)anObserver);
- if (nil == name)
+ if (nil == anObserver)
{
- e = [[set allObjects] objectEnumerator];
- name = [e nextObject];
+ oe = [NSAllMapTableKeys(_observers) objectEnumerator];
+ anObserver = [oe nextObject];
}
- else
+ while (anObserver != nil)
{
- e = nil;
- name = [[name retain] autorelease];
- }
- while (nil != name)
- {
- if (nil != [set member: name])
+ NSMutableSet *set;
+ NSEnumerator *se = nil;
+
+ set = (NSMutableSet*)NSMapGet(_observers, (void*)anObserver);
+ if (nil == name)
{
- [nc removeObserver: anObserver
- name: name
- object: self];
- [[name retain] autorelease];
- [set removeObject: name];
- [_names removeObject: name];
- if (0 == [_names countForObject: name])
+ se = [[set allObjects] objectEnumerator];
+ name = [se nextObject];
+ }
+ else
+ {
+ name = [[name retain] autorelease];
+ }
+ while (nil != name)
+ {
+ if (nil != [set member: name])
{
- [self backendUnlisten: name];
+ [nc removeObserver: anObserver
+ name: name
+ object: self];
+ [[name retain] autorelease];
+ [set removeObject: name];
+ if (nil != se)
+ {
+ while (nil != [set member: name])
+ {
+ [set removeObject: name];
+ }
+ }
+ [_names removeObject: name];
+ if (0 == [_names countForObject: name])
+ {
+ [self backendUnlisten: name];
+ }
}
+ name = [se nextObject];
}
- name = [e nextObject];
- }
- if ([set count] == 0)
- {
- NSMapRemove(_observers, (void*)anObserver);
+ if ([set count] == 0)
+ {
+ NSMapRemove(_observers, (void*)anObserver);
+ }
+ anObserver = [oe nextObject];
}
}
}
Modified: libs/sqlclient/trunk/SQLClientPool.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=39895&r1=39894&r2=39895&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m (original)
+++ libs/sqlclient/trunk/SQLClientPool.m Tue Jun 21 17:34:42 2016
@@ -841,7 +841,9 @@
@" was in progress: %@", client];
}
}
-
+ /* The client must not have any observers if it's in a pool.
+ */
+ [client removeObserver: nil name: nil];
[self _lock];
for (index = 0; index < _max && NO == found; index++)
{
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs