mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Changes by wacko@power1.snu.ac.kr (Yoo C. Chung). See ChangeLog Jan 20
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2202 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
af908b993e
commit
c07f920c70
7 changed files with 103 additions and 42 deletions
38
ChangeLog
38
ChangeLog
|
@ -3,6 +3,44 @@ Mon Mar 3 14:41:01 1997 Andrew McCallum <mccallum@jprc.com>
|
|||
* src/NSHost.m, src/include/NSHost.h: New files from Luke Howard
|
||||
<lukeh@xedoc.com.au>.
|
||||
|
||||
Fri Jan 17 20:08:00 1997 Yoo C. Chung <wacko@power1.snu.ac.kr>
|
||||
|
||||
* src/o_x_bas.m.in (o_@XX@_zone): Use NSZoneFromPointer().
|
||||
(_o_@XX@_alloc_with_zone): Remove unnecessary assignment.
|
||||
|
||||
* src/o_array.m (o_array_alloc): Use NSDefaultMallocZone().
|
||||
* src/o_hash.m (o_hash_alloc): Likewise.
|
||||
(o_hash_copy): Likewise.
|
||||
* src/o_list.m (o_list_alloc): Likewise.
|
||||
(o_list_copy): Likewise.
|
||||
|
||||
* src/include/o_array.h (_o_array): Remove zone. It's just a
|
||||
waste of space when we have a very fast NSZoneFromPointer().
|
||||
* src/include/o_hash.h (_o_hash): Likewise.
|
||||
* src/include/o_list.h (_o_list): Likewise.
|
||||
* src/include/o_map.h (_o_map): Likewise.
|
||||
|
||||
* src/include/NSZone.h: New implementation.
|
||||
|
||||
* src/include/NSPage.h: New file.
|
||||
|
||||
* src/include/NSException.h (NS_HANDLER): Separate declaration and
|
||||
assignment of localException. This is to shut up gcc when we
|
||||
don't use localException.
|
||||
|
||||
* src/StdioStream.m ([StdioStream -dealloc]): Removed call to
|
||||
fclose().
|
||||
|
||||
* src/NSZone.m: New implementation.
|
||||
|
||||
* src/NSDeallocateObject.m: Simplified.
|
||||
|
||||
* src/NSAutoreleasePool.m:
|
||||
Included NSZone.h.
|
||||
([NSAutoreleasePool -dealloc]): Use NSZoneMemInUse().
|
||||
|
||||
* src/Makefile.in (GNUSTEP_HEADERS): Added NSPage.h.
|
||||
|
||||
Sun Jan 12 13:46:38 1997 Andrew McCallum <mccallum@cs.cmu.edu>
|
||||
|
||||
* Version (SUBMINOR_VERSION): Version 0.2.12. There seems to be
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
# Documentation makefile for Objective-C Class Library
|
||||
# Copyright (C) 1995, 1996 Free Software Foundation, Inc.
|
||||
# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
||||
#
|
||||
|
@ -40,6 +40,7 @@ include $(srcdir)/../Makeconf
|
|||
include $(srcdir)/../Version
|
||||
|
||||
TEXI_FILES = \
|
||||
NSZone.texi \
|
||||
announce.texi \
|
||||
base-desc.texi \
|
||||
install.texi \
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
#include <gnustep/base/preface.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
#include <string.h> /* For memset(). */
|
||||
|
||||
NSObject *NSAllocateObject (Class aClass, unsigned extraBytes, NSZone *zone)
|
||||
|
|
|
@ -247,6 +247,7 @@ static Class NSMutableData_concrete_class;
|
|||
char *dest;
|
||||
int length = [self length];
|
||||
int i,j;
|
||||
id ret;
|
||||
|
||||
#define num2char(num) ((num) < 0xa ? ((num)+'0') : ((num)+0x57))
|
||||
|
||||
|
@ -263,7 +264,9 @@ static Class NSMutableData_concrete_class;
|
|||
}
|
||||
dest[j++] = '>';
|
||||
dest[j] = '\0';
|
||||
return [NSString stringWithCString: dest];
|
||||
ret = [NSString stringWithCString: dest];
|
||||
free(dest);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (void)getBytes: (void*)buffer
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <gnustep/base/o_map.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSZone.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
|
@ -61,10 +62,8 @@ static BOOL double_release_check_enabled = NO;
|
|||
BOOL
|
||||
NSShouldRetainWithZone (NSObject *anObject, NSZone *requestedZone)
|
||||
{
|
||||
if (!requestedZone || [anObject zone] == requestedZone)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
return (!requestedZone || requestedZone == NSDefaultMallocZone()
|
||||
|| [anObject zone] == requestedZone);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -101,10 +101,13 @@ NSAllocateMemoryPages (unsigned bytes)
|
|||
#if __mach__
|
||||
kern_return_t r;
|
||||
r = vm_allocate (mach_task_self(), &where, (vm_size_t) bytes, 1);
|
||||
NSParameterAssert (r == KERN_SUCCESS);
|
||||
if (r != KERN_SUCCESS)
|
||||
return NULL;
|
||||
return where;
|
||||
#else
|
||||
where = valloc (bytes);
|
||||
if (where == NULL)
|
||||
return NULL;
|
||||
memset (where, 0, bytes);
|
||||
return where;
|
||||
#endif
|
||||
|
|
|
@ -108,8 +108,8 @@
|
|||
typedef struct _ffree_free_link ff_link;
|
||||
typedef struct _nfree_block_struct nf_block;
|
||||
typedef struct _ffree_block_struct ff_block;
|
||||
typedef struct _ffree_NSZone_struct ffree_NSZone;
|
||||
typedef struct _nfree_NSZone_struct nfree_NSZone;
|
||||
typedef struct _ffree_zone_struct ffree_zone;
|
||||
typedef struct _nfree_zone_struct nfree_zone;
|
||||
|
||||
|
||||
/* Links for free lists. */
|
||||
|
@ -134,7 +134,7 @@ struct _ffree_block_struct
|
|||
};
|
||||
|
||||
/* NSZone structure for freeable zones. */
|
||||
struct _ffree_NSZone_struct
|
||||
struct _ffree_zone_struct
|
||||
{
|
||||
NSZone common;
|
||||
ff_block *blocks; // Linked list of blocks
|
||||
|
@ -146,7 +146,7 @@ struct _ffree_NSZone_struct
|
|||
};
|
||||
|
||||
/* NSZone structure for nonfreeable zones. */
|
||||
struct _nfree_NSZone_struct
|
||||
struct _nfree_zone_struct
|
||||
{
|
||||
NSZone common;
|
||||
/* Linked list of blocks in decreasing order of free space,
|
||||
|
@ -162,7 +162,7 @@ static void become_threaded (void);
|
|||
static inline size_t roundupto (size_t n, size_t base);
|
||||
|
||||
/* Dummy lock, unlock function. */
|
||||
static void dummy_lock (objc_mutex_t mutex);
|
||||
static int dummy_lock (objc_mutex_t mutex);
|
||||
|
||||
/* Memory management functions for freeable zones. */
|
||||
static void* fmalloc (NSZone *zone, size_t size);
|
||||
|
@ -171,11 +171,11 @@ static void ffree (NSZone *zone, void *ptr);
|
|||
static void frecycle (NSZone *zone);
|
||||
|
||||
static inline size_t segindex (size_t size);
|
||||
static void* get_chunk (ffree_NSZone *zone, size_t size);
|
||||
static void take_chunk (ffree_NSZone *zone, size_t *chunk);
|
||||
static void put_chunk (ffree_NSZone *zone, size_t *chunk);
|
||||
static inline void add_buf (ffree_NSZone *zone, size_t *chunk);
|
||||
static void flush_buf (ffree_NSZone *zone);
|
||||
static void* get_chunk (ffree_zone *zone, size_t size);
|
||||
static void take_chunk (ffree_zone *zone, size_t *chunk);
|
||||
static void put_chunk (ffree_zone *zone, size_t *chunk);
|
||||
static inline void add_buf (ffree_zone *zone, size_t *chunk);
|
||||
static void flush_buf (ffree_zone *zone);
|
||||
|
||||
/* Memory management functions for nonfreeable zones. */
|
||||
static void* nmalloc (NSZone *zone, size_t size);
|
||||
|
@ -185,13 +185,13 @@ static void nrecycle (NSZone *zone);
|
|||
static objc_thread_callback thread_callback;
|
||||
|
||||
/* Mutex function pointers. */
|
||||
static void (*lock)(objc_mutex_t mutex) = dummy_lock;
|
||||
static void (*unlock)(objc_mutex_t mutex) = dummy_lock;
|
||||
static int (*lock)(objc_mutex_t mutex) = dummy_lock;
|
||||
static int (*unlock)(objc_mutex_t mutex) = dummy_lock;
|
||||
|
||||
/* Error message. */
|
||||
static NSString *outmemstr = @"Out of memory";
|
||||
|
||||
static ffree_NSZone default_zone =
|
||||
static ffree_zone default_zone =
|
||||
{
|
||||
{ fmalloc, frealloc, ffree, NULL, DEFBLOCK, (objc_mutex_t)0, nil },
|
||||
NULL,
|
||||
|
@ -229,6 +229,8 @@ become_threaded (void)
|
|||
{
|
||||
if (thread_callback != NULL)
|
||||
thread_callback();
|
||||
lock = objc_mutex_lock;
|
||||
unlock = objc_mutex_unlock;
|
||||
default_zone.common.lock = objc_mutex_allocate();
|
||||
}
|
||||
|
||||
|
@ -240,10 +242,10 @@ roundupto (size_t n, size_t base)
|
|||
return (n-a)? (a+base): n;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
dummy_lock (objc_mutex_t mutex)
|
||||
{
|
||||
// Do nothing.
|
||||
return 0; // Do nothing.
|
||||
}
|
||||
|
||||
/* Search the buffer to see if there is any memory chunks large enough
|
||||
|
@ -259,7 +261,7 @@ fmalloc (NSZone *zone, size_t size)
|
|||
{
|
||||
size_t i = 0;
|
||||
size_t chunksize = roundupto(size+SZSZ+ZPTRSZ, MINCHUNK);
|
||||
ffree_NSZone *zptr = (ffree_NSZone*)zone;
|
||||
ffree_zone *zptr = (ffree_zone*)zone;
|
||||
size_t bufsize;
|
||||
size_t *size_buf = zptr->size_buf;
|
||||
size_t **ptr_buf = zptr->ptr_buf;
|
||||
|
@ -334,7 +336,7 @@ frealloc (NSZone *zone, void *ptr, size_t size)
|
|||
{
|
||||
size_t realsize;
|
||||
size_t chunksize = roundupto(size+SZSZ+ZPTRSZ, MINCHUNK);
|
||||
ffree_NSZone *zptr = (ffree_NSZone*)zone;
|
||||
ffree_zone *zptr = (ffree_zone*)zone;
|
||||
size_t *chunkhead, *slack;
|
||||
NSZone **zoneptr; // Zone pointer preceding memory chunk.
|
||||
|
||||
|
@ -416,7 +418,7 @@ static void
|
|||
ffree (NSZone *zone, void *ptr)
|
||||
{
|
||||
lock(zone->lock);
|
||||
add_buf((ffree_NSZone*)zone, ptr-(SZSZ+ZPTRSZ));
|
||||
add_buf((ffree_zone*)zone, ptr-(SZSZ+ZPTRSZ));
|
||||
unlock(zone->lock);
|
||||
}
|
||||
|
||||
|
@ -432,7 +434,7 @@ ffree (NSZone *zone, void *ptr)
|
|||
static void
|
||||
frecycle (NSZone *zone)
|
||||
{
|
||||
ffree_NSZone *zptr = (ffree_NSZone*)zone;
|
||||
ffree_zone *zptr = (ffree_zone*)zone;
|
||||
ff_block *block = zptr->blocks;
|
||||
ff_block *nextblock;
|
||||
|
||||
|
@ -480,7 +482,7 @@ segindex (size_t size)
|
|||
/* Look through the segregated list with first fit to find a memory
|
||||
chunk. If one is not found, get more memory. */
|
||||
static void*
|
||||
get_chunk (ffree_NSZone *zone, size_t size)
|
||||
get_chunk (ffree_zone *zone, size_t size)
|
||||
{
|
||||
size_t class = segindex(size);
|
||||
size_t *chunk = zone->segheadlist[class];
|
||||
|
@ -591,7 +593,7 @@ get_chunk (ffree_NSZone *zone, size_t size)
|
|||
|
||||
/* Take the given chunk out of the free list. No headers are set. */
|
||||
static void
|
||||
take_chunk (ffree_NSZone *zone, size_t *chunk)
|
||||
take_chunk (ffree_zone *zone, size_t *chunk)
|
||||
{
|
||||
size_t size = *chunk & ~SIZE_BITS;
|
||||
size_t class = segindex(size);
|
||||
|
@ -621,7 +623,7 @@ take_chunk (ffree_NSZone *zone, size_t *chunk)
|
|||
/* Add the given chunk to the segregated list. The header to the
|
||||
chunk must be set appropriately, but the tailer is set here. */
|
||||
static void
|
||||
put_chunk (ffree_NSZone *zone, size_t *chunk)
|
||||
put_chunk (ffree_zone *zone, size_t *chunk)
|
||||
{
|
||||
size_t size = *chunk & ~SIZE_BITS;
|
||||
size_t class = segindex(size);
|
||||
|
@ -657,7 +659,7 @@ put_chunk (ffree_NSZone *zone, size_t *chunk)
|
|||
flush it. The given pointer must always be one that points to used
|
||||
memory. */
|
||||
static inline void
|
||||
add_buf (ffree_NSZone *zone, size_t *chunk)
|
||||
add_buf (ffree_zone *zone, size_t *chunk)
|
||||
{
|
||||
size_t bufsize = zone->bufsize;
|
||||
|
||||
|
@ -674,7 +676,7 @@ add_buf (ffree_NSZone *zone, size_t *chunk)
|
|||
|
||||
/* Flush buffers. All coalescing is done here. */
|
||||
static void
|
||||
flush_buf (ffree_NSZone *zone)
|
||||
flush_buf (ffree_zone *zone)
|
||||
{
|
||||
size_t i, size;
|
||||
size_t bufsize = zone->bufsize;
|
||||
|
@ -746,7 +748,7 @@ flush_buf (ffree_NSZone *zone)
|
|||
static void*
|
||||
nmalloc (NSZone *zone, size_t size)
|
||||
{
|
||||
nfree_NSZone *zptr = (nfree_NSZone*)zone;
|
||||
nfree_zone *zptr = (nfree_zone*)zone;
|
||||
size_t top;
|
||||
size_t chunksize = roundupto(size+ZPTRSZ, ALIGN);
|
||||
NSZone **chunkhead;
|
||||
|
@ -785,7 +787,6 @@ nmalloc (NSZone *zone, size_t size)
|
|||
/* Get new block. */
|
||||
{
|
||||
size_t blocksize = roundupto(size+NF_HEAD, zone->gran);
|
||||
nf_block *block;
|
||||
|
||||
/* Any clean way to make gcc shut up here? */
|
||||
NS_DURING
|
||||
|
@ -817,7 +818,7 @@ static void
|
|||
nrecycle (NSZone *zone)
|
||||
{
|
||||
nf_block *nextblock;
|
||||
nf_block *block = ((nfree_NSZone*)zone)->blocks;
|
||||
nf_block *block = ((nfree_zone*)zone)->blocks;
|
||||
|
||||
objc_mutex_deallocate(zone->lock);
|
||||
while (block != NULL)
|
||||
|
@ -847,11 +848,11 @@ NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
|||
if (canFree)
|
||||
{
|
||||
ff_block *block;
|
||||
ffree_NSZone *zone;
|
||||
ffree_zone *zone;
|
||||
size_t *header, *tailer;
|
||||
NSZone **zoneptr;
|
||||
|
||||
zone = fmalloc(NSDefaultMallocZone(), sizeof(ffree_NSZone));
|
||||
zone = fmalloc(NSDefaultMallocZone(), sizeof(ffree_zone));
|
||||
zone->common.malloc = fmalloc;
|
||||
zone->common.realloc = frealloc;
|
||||
zone->common.free = ffree;
|
||||
|
@ -866,12 +867,13 @@ NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
|||
}
|
||||
zone->bufsize = 0;
|
||||
NS_DURING
|
||||
zone->blocks = block = fmalloc(NSDefaultMallocZone(), startsize);
|
||||
zone->blocks = fmalloc(NSDefaultMallocZone(), startsize);
|
||||
NS_HANDLER
|
||||
objc_mutex_dealloc(zone->common.lock);
|
||||
objc_mutex_deallocate(zone->common.lock);
|
||||
ffree(NSDefaultMallocZone(), zone);
|
||||
[localException raise];
|
||||
NS_ENDHANDLER
|
||||
block = zone->blocks;
|
||||
block->next = NULL;
|
||||
block->size = startsize;
|
||||
header = (void*)block+FF_HEAD;
|
||||
|
@ -886,9 +888,9 @@ NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
|||
else
|
||||
{
|
||||
nf_block *block;
|
||||
nfree_NSZone *zone;
|
||||
nfree_zone *zone;
|
||||
|
||||
zone = fmalloc(NSDefaultMallocZone(), sizeof(nfree_NSZone));
|
||||
zone = fmalloc(NSDefaultMallocZone(), sizeof(nfree_zone));
|
||||
zone->common.malloc = nmalloc;
|
||||
zone->common.realloc = NULL;
|
||||
zone->common.free = NULL;
|
||||
|
@ -897,12 +899,13 @@ NSCreateZone (size_t start, size_t gran, BOOL canFree)
|
|||
zone->common.lock = objc_mutex_allocate();
|
||||
zone->common.name = nil;
|
||||
NS_DURING
|
||||
zone->blocks = block = fmalloc(NSDefaultMallocZone(), startsize);
|
||||
zone->blocks = fmalloc(NSDefaultMallocZone(), startsize);
|
||||
NS_HANDLER
|
||||
objc_mutex_deallocate(zone->common.lock);
|
||||
ffree(NSDefaultMallocZone(), zone);
|
||||
[localException raise];
|
||||
NS_ENDHANDLER
|
||||
block = zone->blocks;
|
||||
block->next = NULL;
|
||||
block->size = startsize;
|
||||
block->top = NF_HEAD;
|
||||
|
@ -971,8 +974,21 @@ NSZoneName (NSZone *zone)
|
|||
return zone->name;
|
||||
}
|
||||
|
||||
/* FIXME: not thread safe. */
|
||||
BOOL
|
||||
NSZoneMemInUse (void *ptr)
|
||||
{
|
||||
return (*(size_t*)(ptr-ZPTRSZ-SZSZ)) & INUSE;
|
||||
size_t *header = ptr-ZPTRSZ-SZSZ;
|
||||
|
||||
if (*header & INUSE)
|
||||
{
|
||||
size_t i;
|
||||
ffree_zone *zone = (ffree_zone*)NSZoneFromPointer(ptr);
|
||||
|
||||
for (i = 0; i < zone->bufsize; i++)
|
||||
if (zone->ptr_buf[i] == ptr)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue