More GC fixes. Most notably, mark the thread object as not collectable, since it's hidden away in TLS where the GC can't find it.

GC now works well enough for LanguageKit to run.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33123 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Chisnall 2011-05-26 13:24:13 +00:00
parent 8da9a5ecbb
commit de2fd8df6e
7 changed files with 29 additions and 7 deletions

View file

@ -65,7 +65,7 @@ extern "C" {
{
#if GS_EXPOSE(NSNotificationCenter)
@private
void *_table;
__strong void *_table;
#endif
}

View file

@ -72,11 +72,13 @@
locked = -1;
}
#ifdef __GS_WITH_GC__
- (void) finalize
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super finalize];
}
#endif
- (id) init
{
@ -214,11 +216,13 @@
counter = -1;
}
#ifdef __GS_WITH_GC__
- (void) finalize
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super finalize];
}
#endif
- (id) init
{

View file

@ -1928,7 +1928,7 @@ NSArray *GSObjCDirectSubclassesOfClass(Class cls)
void *
GSAutoreleasedBuffer(unsigned size)
{
#if GS_WITH_GC
#if GS_WITH_GC || __OBJC_GC__
return NSAllocateCollectable(size, NSScannedOption);
#else
#ifdef ALIGN

View file

@ -28,6 +28,7 @@
Boston, MA 02111 USA.
*/
#import "common.h"
#if !defined(NeXT_Foundation_LIBRARY)
#import "Foundation/NSArray.h"
@ -304,7 +305,7 @@ static void GSSetupEncodingTable(void)
}
}
}
encTable = NSZoneMalloc(NSDefaultMallocZone(),
encTable = malloc(
(encTableSize+1)*sizeof(struct _strenc_ *));
memset(encTable, 0, (encTableSize+1)*sizeof(struct _strenc_ *));
@ -331,13 +332,13 @@ static void GSSetupEncodingTable(void)
* See if we can do a lossy conversion.
*/
l = strlen(entry->iconv);
lossy = NSZoneMalloc(NSDefaultMallocZone(), l + 11);
lossy = malloc(l + 11);
strncpy(lossy, entry->iconv, l);
strncpy(lossy + l, "//TRANSLIT", 11);
c = iconv_open(UNICODE_ENC, entry->iconv);
if (c == (iconv_t)-1)
{
NSZoneFree(NSDefaultMallocZone(),lossy);
free(lossy);
}
else
{
@ -371,6 +372,7 @@ EntryForEncoding(NSStringEncoding enc)
while (i < sizeof(str_encoding_table) / sizeof(struct _strenc_))
{
NSLog(@"Checking encoding %s (%d == %d) %d", str_encoding_table[i].ename, str_encoding_table[i].enc, enc, str_encoding_table[i].supported);
if (str_encoding_table[i].enc == enc)
{
entry = &str_encoding_table[i];
@ -2520,7 +2522,7 @@ GSPrivateAvailableEncodings()
* This is also the place where we determine the name we use
* for iconv to support unicode.
*/
encodings = NSZoneMalloc(NSDefaultMallocZone(),sizeof(NSStringEncoding) * (encTableSize+1));
encodings = malloc(sizeof(NSStringEncoding) * (encTableSize+1));
pos = 0;
for (i = 0; i < encTableSize+1; i++)
{

View file

@ -477,7 +477,7 @@ fixBOM(unsigned char **bytes, NSUInteger*length, BOOL *owned,
*/
if (original == bytes)
{
#if GS_WITH_GC || __OBJC_GC__
#if GS_WITH_GC
chars = NSAllocateCollectable(length, 0);
#else
chars = NSZoneMalloc([self zone], length);

View file

@ -72,6 +72,7 @@
#import "Foundation/NSConnection.h"
#import "Foundation/NSInvocation.h"
#import "Foundation/NSUserDefaults.h"
#import "Foundation/NSGarbageCollector.h"
#import "GSPrivate.h"
#import "GSRunLoopCtxt.h"
@ -79,6 +80,9 @@
#if GS_WITH_GC
#include <gc/gc.h>
#endif
#if __OBJC_GC__
#include <objc/objc-auto.h>
#endif
// Some older BSD systems used a non-standard range of thread priorities.
// Use these if they exist, otherwise define standard ones.
@ -415,6 +419,7 @@ gnustep_base_thread_callback(void)
static void
setThreadForCurrentThread(NSThread *t)
{
[[NSGarbageCollector defaultCollector] disableCollectorForPointer: t];
pthread_setspecific(thread_object_key, t);
gnustep_base_thread_callback();
}
@ -443,6 +448,8 @@ unregisterActiveThread(NSThread *thread)
[(GSRunLoopThreadInfo*)thread->_runLoopInfo invalidate];
[thread release];
[[NSGarbageCollector defaultCollector] enableCollectorForPointer: thread];
pthread_setspecific(thread_object_key, nil);
}
}
@ -462,6 +469,7 @@ unregisterActiveThread(NSThread *thread)
{
t = [self new];
t->_active = YES;
[[NSGarbageCollector defaultCollector] disableCollectorForPointer: t];
pthread_setspecific(thread_object_key, t);
GS_CONSUMED(t);
return YES;
@ -748,6 +756,9 @@ static void *nsthreadLauncher(void* thread)
{
NSThread *t = (NSThread*)thread;
setThreadForCurrentThread(t);
#if __OBJC_GC__
objc_registerThreadWithCollector();
#endif
#if GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
{
struct GC_stack_base base;

View file

@ -250,6 +250,11 @@ NSReallocateCollectable(void *ptr, NSUInteger size, NSUInteger options)
((options & NSScannedOption) == NSScannedOption));
}
id NSMakeCollectable(id obj)
{
objc_gc_release(obj);
}
NSZone*
NSCreateZone (NSUInteger start, NSUInteger gran, BOOL canFree)
{