MInor tidyup.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16105 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-03-02 07:47:18 +00:00
parent 650c648af6
commit 57c0ece231
10 changed files with 64 additions and 52 deletions

View file

@ -1,3 +1,19 @@
2003-03-02 Richard Frith-Macdonald <rfm@gnu.org>
* 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 <mirko.viviani@rccr.cremona.it> 2003-02-19 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* Headers/gnustep/base/NSArray.h: fixed declarations. * Headers/gnustep/base/NSArray.h: fixed declarations.

View file

@ -311,10 +311,10 @@ GSObjCVersion(Class this)
GS_EXPORT NSZone *GSObjCZone(NSObject *obj); 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 */ /* Getting a system error message on a variety of systems */
GS_EXPORT const char *GSLastErrorStr(long error_id); GS_EXPORT const char *GSLastErrorStr(long error_id);

View file

@ -32,6 +32,7 @@
#include <gnustep/base/preface.h> #include <gnustep/base/preface.h>
#ifndef NeXT_Foundation_LIBRARY #ifndef NeXT_Foundation_LIBRARY
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSEnumerator.h> #include <Foundation/NSEnumerator.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
@ -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 */ /* Getting a system error message on a variety of systems */

View file

@ -1313,7 +1313,7 @@ tables:
/* /*
* Temporary string was requested ... make one. * Temporary string was requested ... make one.
*/ */
r = _fastMallocBuffer(bytes); r = GSAutoreleasedBuffer(bytes);
memcpy(r, ptr, bytes); memcpy(r, ptr, bytes);
if (ptr != buf && (dst == 0 || ptr != *dst)) if (ptr != buf && (dst == 0 || ptr != *dst))
{ {
@ -1913,7 +1913,7 @@ tables:
/* /*
* Temporary string was requested ... make one. * Temporary string was requested ... make one.
*/ */
r = _fastMallocBuffer(bytes); r = GSAutoreleasedBuffer(bytes);
memcpy(r, ptr, bytes); memcpy(r, ptr, bytes);
if (ptr != buf && (dst == 0 || ptr != *dst)) if (ptr != buf && (dst == 0 || ptr != *dst))
{ {

View file

@ -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 where it becomes owned by the callback invocation, so we don't have to
worry about freeing it */ worry about freeing it */
cframe = cifframe_from_info([sig methodInfo], [sig numberOfArguments], NULL); cframe = cifframe_from_info([sig methodInfo], [sig numberOfArguments], NULL);
/* Autorelease the closure through fastMallocBuffer */ /* Autorelease the closure through GSAutoreleasedBuffer */
cclosure = (ffi_closure *)_fastMallocBuffer(sizeof(ffi_closure)); cclosure = (ffi_closure *)GSAutoreleasedBuffer(sizeof(ffi_closure));
if (cframe == NULL || cclosure == NULL) if (cframe == NULL || cclosure == NULL)
{ {
[NSException raise: NSMallocException format: @"Allocating closure"]; [NSException raise: NSMallocException format: @"Allocating closure"];

View file

@ -543,7 +543,7 @@ UTF8String_c(ivars self)
{ {
unsigned i = self->_count; unsigned i = self->_count;
r = (unsigned char*)_fastMallocBuffer(self->_count+1); r = (unsigned char*)GSAutoreleasedBuffer(self->_count+1);
while (i-- > 0) while (i-- > 0)
{ {
r[i] = self->_contents.c[i] & 0x7f; r[i] = self->_contents.c[i] & 0x7f;
@ -777,7 +777,7 @@ cString_c(ivars self)
} }
if (defEnc == intEnc) if (defEnc == intEnc)
{ {
r = (unsigned char*)_fastMallocBuffer(self->_count+1); r = (unsigned char*)GSAutoreleasedBuffer(self->_count+1);
if (self->_count > 0) if (self->_count > 0)
{ {
@ -1350,7 +1350,7 @@ lossyCString_c(ivars self)
} }
if (defEnc == intEnc) if (defEnc == intEnc)
{ {
r = (char*)_fastMallocBuffer(self->_count+1); r = (char*)GSAutoreleasedBuffer(self->_count+1);
if (self->_count > 0) if (self->_count > 0)
{ {

View file

@ -605,7 +605,7 @@ _arg_addr(NSInvocation *inv, int index)
const char *t = _info[i].type; const char *t = _info[i].type;
if (*t == _C_STRUCT_B || *t == _C_UNION_B || *t == _C_ARY_B) 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; datum = *(void**)datum;
} }
} }

View file

@ -61,12 +61,6 @@ extern BOOL __objc_responds_to(id, SEL);
#include <gc.h> #include <gc.h>
#include <gc_typed.h> #include <gc_typed.h>
#else
@class _FastMallocBuffer;
static Class fastMallocClass;
static unsigned fastMallocOffset;
#endif #endif
static Class NSConstantStringClass; static Class NSConstantStringClass;
@ -812,12 +806,10 @@ static BOOL double_release_check_enabled = NO;
autorelease_sel = @selector(addObject:); autorelease_sel = @selector(addObject:);
autorelease_imp = [autorelease_class methodForSelector: autorelease_sel]; autorelease_imp = [autorelease_class methodForSelector: autorelease_sel];
#if GS_WITH_GC == 0 #if GS_WITH_GC == 0
fastMallocClass = [_FastMallocBuffer class];
#if !defined(REFCNT_LOCAL) #if !defined(REFCNT_LOCAL)
GSIMapInitWithZoneAndCapacity(&retain_counts, GSIMapInitWithZoneAndCapacity(&retain_counts,
NSDefaultMallocZone(), 1024); NSDefaultMallocZone(), 1024);
#endif #endif
fastMallocOffset = fastMallocClass->instance_size % ALIGN;
#endif #endif
NSConstantStringClass = [NSString constantStringClass]; NSConstantStringClass = [NSString constantStringClass];
GSBuildStrings(); GSBuildStrings();
@ -2114,37 +2106,6 @@ static BOOL double_release_check_enabled = NO;
@end @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. * Stuff for compatibility with 'Object' derived classes.
*/ */

View file

@ -798,7 +798,7 @@ static IMP _xRefImp; /* Serialize a crossref. */
* add it to the crossref map. * add it to the crossref map.
*/ */
size = objc_sizeof_type(++type); size = objc_sizeof_type(++type);
*(void**)address = _fastMallocBuffer(size); *(void**)address = GSAutoreleasedBuffer(size);
GSIArrayAddItem(_ptrAry, (GSIArrayItem)*(void**)address); GSIArrayAddItem(_ptrAry, (GSIArrayItem)*(void**)address);
/* /*

View file

@ -808,7 +808,7 @@ static Class NSDataMallocClass;
* add it to the crossref map. * add it to the crossref map.
*/ */
size = objc_sizeof_type(++type); size = objc_sizeof_type(++type);
*(void**)address = _fastMallocBuffer(size); *(void**)address = GSAutoreleasedBuffer(size);
GSIArrayAddItem(ptrMap, (GSIArrayItem)*(void**)address); GSIArrayAddItem(ptrMap, (GSIArrayItem)*(void**)address);
/* /*