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:
theraven 2011-05-26 13:24:13 +00:00
parent 957ee2b8ef
commit ba6f3867a8
7 changed files with 29 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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