From 57c0ece2312b6d2129e33db106c48f45df7a5cf1 Mon Sep 17 00:00:00 2001 From: CaS Date: Sun, 2 Mar 2003 07:47:18 +0000 Subject: [PATCH] MInor tidyup. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16105 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 16 ++++++++++++ Headers/gnustep/base/GSObjCRuntime.h | 6 ++--- Source/Additions/GSObjCRuntime.m | 35 +++++++++++++++++++++++++ Source/Additions/Unicode.m | 4 +-- Source/GSFFIInvocation.m | 4 +-- Source/GSString.m | 6 ++--- Source/NSInvocation.m | 2 +- Source/NSObject.m | 39 ---------------------------- Source/NSPortCoder.m | 2 +- Source/NSUnarchiver.m | 2 +- 10 files changed, 64 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index eba4173b1..9e2a52f5c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2003-03-02 Richard Frith-Macdonald + + * Headers/gnustep/base/GSObjCRuntime.h: + * Source/GSFFIInvocation.m: + * Source/GSString.m: + * Source/NSInvocation.m: + * Source/NSObject.m: + * Source/NSPortCoder.m: + * Source/NSUnarchiver.m: + * Source/Additions/GSObjCRuntime.m: + * Source/Additions/Unicode.m: + Rename _fastMallocBuffer() to GSAutoreleasedBuffer() for clarity + and consistency. Moved implementation from NSObject.m to + GSObjCRuntime.m so this is available for use withing the Additions + library when built standalone. + 2003-02-19 Mirko Viviani * Headers/gnustep/base/NSArray.h: fixed declarations. diff --git a/Headers/gnustep/base/GSObjCRuntime.h b/Headers/gnustep/base/GSObjCRuntime.h index 1e70030a4..7f65210f4 100644 --- a/Headers/gnustep/base/GSObjCRuntime.h +++ b/Headers/gnustep/base/GSObjCRuntime.h @@ -311,10 +311,10 @@ GSObjCVersion(Class this) GS_EXPORT NSZone *GSObjCZone(NSObject *obj); -/* - * Quickly return autoreleased data. +/** + * Quickly return autoreleased data storage area. */ -void *_fastMallocBuffer(unsigned size); +GS_EXPORT void *GSAutoreleasedBuffer(unsigned size); /* Getting a system error message on a variety of systems */ GS_EXPORT const char *GSLastErrorStr(long error_id); diff --git a/Source/Additions/GSObjCRuntime.m b/Source/Additions/GSObjCRuntime.m index 648e689a0..dfc6ba86d 100644 --- a/Source/Additions/GSObjCRuntime.m +++ b/Source/Additions/GSObjCRuntime.m @@ -32,6 +32,7 @@ #include #ifndef NeXT_Foundation_LIBRARY #include +#include #include #include #include @@ -1280,6 +1281,40 @@ GSObjCSetValue(NSObject *self, NSString *key, id val, SEL sel, } } + +void * +GSAutoreleasedBuffer(unsigned size) +{ +#if GS_WITH_GC + return GC_malloc(size); +#else +#ifdef ALIGN +#undef ALIGN +#endif +#define ALIGN __alignof__(double) + + static Class nsobject_class = 0; + static Class autorelease_class; + static SEL autorelease_sel; + static IMP autorelease_imp; + static int offset; + NSObject *o; + + if (nsobject_class == 0) + { + nsobject_class = [NSObject class]; + offset = nsobject_class->instance_size % ALIGN; + autorelease_class = [NSAutoreleasePool class]; + autorelease_sel = @selector(addObject:); + autorelease_imp = [autorelease_class methodForSelector: autorelease_sel]; + } + o = (NSObject*)NSAllocateObject(nsobject_class, + size + offset, NSDefaultMallocZone()); + (*autorelease_imp)(autorelease_class, autorelease_sel, o); + return ((void*)&o[1]) + offset; +#endif +} + /* Getting a system error message on a variety of systems */ diff --git a/Source/Additions/Unicode.m b/Source/Additions/Unicode.m index 4b101441b..9eb392c7e 100644 --- a/Source/Additions/Unicode.m +++ b/Source/Additions/Unicode.m @@ -1313,7 +1313,7 @@ tables: /* * Temporary string was requested ... make one. */ - r = _fastMallocBuffer(bytes); + r = GSAutoreleasedBuffer(bytes); memcpy(r, ptr, bytes); if (ptr != buf && (dst == 0 || ptr != *dst)) { @@ -1913,7 +1913,7 @@ tables: /* * Temporary string was requested ... make one. */ - r = _fastMallocBuffer(bytes); + r = GSAutoreleasedBuffer(bytes); memcpy(r, ptr, bytes); if (ptr != buf && (dst == 0 || ptr != *dst)) { diff --git a/Source/GSFFIInvocation.m b/Source/GSFFIInvocation.m index 0667ea90f..416468f68 100644 --- a/Source/GSFFIInvocation.m +++ b/Source/GSFFIInvocation.m @@ -170,8 +170,8 @@ static IMP gs_objc_msg_forward (SEL sel) where it becomes owned by the callback invocation, so we don't have to worry about freeing it */ cframe = cifframe_from_info([sig methodInfo], [sig numberOfArguments], NULL); - /* Autorelease the closure through fastMallocBuffer */ - cclosure = (ffi_closure *)_fastMallocBuffer(sizeof(ffi_closure)); + /* Autorelease the closure through GSAutoreleasedBuffer */ + cclosure = (ffi_closure *)GSAutoreleasedBuffer(sizeof(ffi_closure)); if (cframe == NULL || cclosure == NULL) { [NSException raise: NSMallocException format: @"Allocating closure"]; diff --git a/Source/GSString.m b/Source/GSString.m index c557140ad..e09f62703 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -543,7 +543,7 @@ UTF8String_c(ivars self) { unsigned i = self->_count; - r = (unsigned char*)_fastMallocBuffer(self->_count+1); + r = (unsigned char*)GSAutoreleasedBuffer(self->_count+1); while (i-- > 0) { r[i] = self->_contents.c[i] & 0x7f; @@ -777,7 +777,7 @@ cString_c(ivars self) } if (defEnc == intEnc) { - r = (unsigned char*)_fastMallocBuffer(self->_count+1); + r = (unsigned char*)GSAutoreleasedBuffer(self->_count+1); if (self->_count > 0) { @@ -1350,7 +1350,7 @@ lossyCString_c(ivars self) } if (defEnc == intEnc) { - r = (char*)_fastMallocBuffer(self->_count+1); + r = (char*)GSAutoreleasedBuffer(self->_count+1); if (self->_count > 0) { diff --git a/Source/NSInvocation.m b/Source/NSInvocation.m index c0585768a..09969dc63 100644 --- a/Source/NSInvocation.m +++ b/Source/NSInvocation.m @@ -605,7 +605,7 @@ _arg_addr(NSInvocation *inv, int index) const char *t = _info[i].type; if (*t == _C_STRUCT_B || *t == _C_UNION_B || *t == _C_ARY_B) { - *(void**)datum = _fastMallocBuffer(_info[i].size); + *(void**)datum = GSAutoreleasedBuffer(_info[i].size); datum = *(void**)datum; } } diff --git a/Source/NSObject.m b/Source/NSObject.m index f95a39e5b..7dd7946f6 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -61,12 +61,6 @@ extern BOOL __objc_responds_to(id, SEL); #include #include -#else - -@class _FastMallocBuffer; -static Class fastMallocClass; -static unsigned fastMallocOffset; - #endif static Class NSConstantStringClass; @@ -812,12 +806,10 @@ static BOOL double_release_check_enabled = NO; autorelease_sel = @selector(addObject:); autorelease_imp = [autorelease_class methodForSelector: autorelease_sel]; #if GS_WITH_GC == 0 - fastMallocClass = [_FastMallocBuffer class]; #if !defined(REFCNT_LOCAL) GSIMapInitWithZoneAndCapacity(&retain_counts, NSDefaultMallocZone(), 1024); #endif - fastMallocOffset = fastMallocClass->instance_size % ALIGN; #endif NSConstantStringClass = [NSString constantStringClass]; GSBuildStrings(); @@ -2114,37 +2106,6 @@ static BOOL double_release_check_enabled = NO; @end -/* - * Stuff for temporary memory management. - */ -#if GS_WITH_GC == 0 -@interface _FastMallocBuffer : NSObject -@end - -@implementation _FastMallocBuffer -@end -#endif - -/* - * Function for giving us the fastest possible allocation of memory to - * be used for temporary storage. - */ -void * -_fastMallocBuffer(unsigned size) -{ -#if GS_WITH_GC - return GC_malloc(size); -#else - _FastMallocBuffer *o; - - o = (_FastMallocBuffer*)NSAllocateObject(fastMallocClass, - size + fastMallocOffset, NSDefaultMallocZone()); - (*autorelease_imp)(autorelease_class, autorelease_sel, o); - return ((void*)&o[1])+fastMallocOffset; -#endif -} - - /* * Stuff for compatibility with 'Object' derived classes. */ diff --git a/Source/NSPortCoder.m b/Source/NSPortCoder.m index 132aa209a..d7f1131f1 100644 --- a/Source/NSPortCoder.m +++ b/Source/NSPortCoder.m @@ -798,7 +798,7 @@ static IMP _xRefImp; /* Serialize a crossref. */ * add it to the crossref map. */ size = objc_sizeof_type(++type); - *(void**)address = _fastMallocBuffer(size); + *(void**)address = GSAutoreleasedBuffer(size); GSIArrayAddItem(_ptrAry, (GSIArrayItem)*(void**)address); /* diff --git a/Source/NSUnarchiver.m b/Source/NSUnarchiver.m index e41f23b23..0e43fc72d 100644 --- a/Source/NSUnarchiver.m +++ b/Source/NSUnarchiver.m @@ -808,7 +808,7 @@ static Class NSDataMallocClass; * add it to the crossref map. */ size = objc_sizeof_type(++type); - *(void**)address = _fastMallocBuffer(size); + *(void**)address = GSAutoreleasedBuffer(size); GSIArrayAddItem(ptrMap, (GSIArrayItem)*(void**)address); /*