diff --git a/ChangeLog b/ChangeLog index 49ffb78b4..a4f12c391 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,11 @@ Sat May 3 12:28:48 1997 Andrew McCallum Use NSBundle's pathForResource:ofType:inDirectory method properly. (Reported by Stevo Crvenkovski .) +Sat Mar 29 00:43:18 1997 Yoo C. Chung + + * src/NSZone.m: New e-mail address. Default default zone + alignment problems fixed. + Sun Mar 23 19:55:19 1997 Mark Kettenis * src/Makefile.in: Update config.h.in in $(srcdir)/src/include. diff --git a/Headers/gnustep/base/NSZone.h b/Headers/gnustep/base/NSZone.h index 8bd4a1c43..e98edb295 100644 --- a/Headers/gnustep/base/NSZone.h +++ b/Headers/gnustep/base/NSZone.h @@ -1,7 +1,7 @@ /* Zone memory management. -*- Mode: ObjC -*- Copyright (C) 1997 Free Software Foundation, Inc. - Written by: Yoo C. Chung + Written by: Yoo C. Chung Date: January 1997 This file is part of the GNUstep Base Library. diff --git a/Source/NSZone.m b/Source/NSZone.m index 87bda881a..ef0da4fe7 100644 --- a/Source/NSZone.m +++ b/Source/NSZone.m @@ -1,7 +1,7 @@ /* Zone memory management. -*- Mode: ObjC -*- Copyright (C) 1997 Free Software Foundation, Inc. - Written by: Yoo C. Chung + Written by: Yoo C. Chung Date: January 1997 This file is part of the GNUstep Base Library. @@ -39,7 +39,8 @@ - The default zone uses objc_malloc() and friends. We assume that they're thread safe and that they return NULL if we're out of memory (they currently don't, unfortunately, so this is a FIXME). - We also need to prepend a zone pointer. + We also need to prepend a zone pointer. And because of this, we + need to waste even more space to satisfy alignment requirements. - For freeable zones, a small linear buffer is used for deallocating and allocating. Anything that can't go into the @@ -232,32 +233,39 @@ roundupto (size_t n, size_t base) static void* default_malloc (NSZone *zone, size_t size) { - NSZone **mem; + void *mem; + NSZone **zoneptr; - mem = objc_malloc(ZPTRSZ+size); + mem = objc_malloc(ALIGN+size); if (mem == NULL) [NSException raise: NSMallocException format: @"Default zone has run out of memory"]; - *mem = zone; - return mem+1; + zoneptr = mem+(ALIGN-ZPTRSZ); + *zoneptr = zone; + return mem+ALIGN; } static void* default_realloc (NSZone *zone, void *ptr, size_t size) { - NSZone **mem = ptr-ZPTRSZ; + void **mem = ptr-ALIGN; - mem = objc_realloc(mem, size+ZPTRSZ); - if ((size != 0) && (mem == NULL)) + if (size == 0) + { + objc_free(mem); + return NULL; + } + mem = objc_realloc(mem, size+ALIGN); + if (mem == NULL) [NSException raise: NSMallocException format: @"Default zone has run out of memory"]; - return mem+1; + return mem+ALIGN; } static void default_free (NSZone *zone, void *ptr) { - objc_free(ptr-ZPTRSZ); + objc_free(ptr-ALIGN); } static void