fix weak pointer error

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28061 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-03-10 11:10:27 +00:00
parent 5297d5f557
commit 61b93f7a45
2 changed files with 15 additions and 12 deletions

View file

@ -1029,8 +1029,8 @@ static NSNotificationCenter *default_center = nil;
GSIArrayItem i[64];
GSIArray_t b;
GSIArray a = &b;
#if GS_WITH_GG
GSGarbageCollector *collector = [NSGarbageCollector defaultCollector];
#if GS_WITH_GC
NSGarbageCollector *collector = [NSGarbageCollector defaultCollector];
#endif
if (name == nil)
@ -1045,22 +1045,22 @@ static NSNotificationCenter *default_center = nil;
object = CHEATGC(object);
}
/*
* Initialise static array to store copies of observers.
*/
GSIArrayInitWithZoneAndStaticCapacity(a, _zone, 64, i);
/*
* Lock the table of observations while we traverse it.
*
* The table of observations contains weak pointers which are zeroed when
* the observers get garbage collected. So to avoid consistency problems
* we disable gc while we copy all the observations we are interested in.
* We use scanned memory in the array in the case where there are more
* than the 64 observers we allowed room for on the stack.
*/
lockNCTable(TABLE);
#if GS_WITH_GG
#if GS_WITH_GC
GSIArrayInitWithZoneAndStaticCapacity(a, (NSZone*)1, 64, i);
[collector disable];
#else
GSIArrayInitWithZoneAndStaticCapacity(a, _zone, 64, i);
#endif
lockNCTable(TABLE);
/*
* Find all the observers that specified neither NAME nor OBJECT.
@ -1142,10 +1142,10 @@ static NSNotificationCenter *default_center = nil;
* collection, safe in the knowledge that the observers we will be
* notifying won't get collected prematurely.
*/
#if GS_WITH_GG
unlockNCTable(TABLE);
#if GS_WITH_GC
[collector enable];
#endif
unlockNCTable(TABLE);
/*
* Now send all the notifications.

View file

@ -1924,7 +1924,10 @@ GSAssignZeroingWeakPointer(void **destination, void *source)
GC_unregister_disappearing_link(destination);
}
*destination = source;
GC_general_register_disappearing_link(destination, source);
if (source != 0)
{
GC_general_register_disappearing_link(destination, source);
}
return YES;
}