diff options
author | Christopher Faylor <me@cgf.cx> | 2003-01-18 06:26:07 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-01-18 06:26:07 +0300 |
commit | 4c6a3e500e88196170c1938bd174d4cdb97e7a6d (patch) | |
tree | 1d5cf60b961aefb87b4453babf941b5863162d56 /winsup/cygwin/cygheap.cc | |
parent | e9152439113f89322368774977e52f339d88f382 (diff) |
* cygheap.cc: Change most 'int's to 'unsigned's.
(_cmalloc): Only check for size of malloced region when calculating budget.
Add overhead when performing the sbrk. Previous change broke _crealloc.
Diffstat (limited to 'winsup/cygwin/cygheap.cc')
-rw-r--r-- | winsup/cygwin/cygheap.cc | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index e224ca825..7fdb87a3e 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -38,7 +38,7 @@ struct cygheap_entry #define NBUCKETS (sizeof (cygheap->buckets) / sizeof (cygheap->buckets[0])) #define N0 ((_cmalloc_entry *) NULL) -#define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (int) (N0->data))) +#define to_cmalloc(s) ((_cmalloc_entry *) (((char *) (s)) - (unsigned) (N0->data))) #define CFMAP_OPTIONS (SEC_RESERVE | PAGE_READWRITE) #define MVMAP_OPTIONS (FILE_MAP_WRITE) @@ -208,18 +208,17 @@ cygheap_init () /* Copyright (C) 1997, 2000 DJ Delorie */ -static void *_cmalloc (int size) __attribute ((regparm(1))); -static void *__stdcall _crealloc (void *ptr, int size) __attribute ((regparm(2))); +static void *_cmalloc (unsigned size) __attribute ((regparm(1))); +static void *__stdcall _crealloc (void *ptr, unsigned size) __attribute ((regparm(2))); static void *__stdcall -_cmalloc (int size) +_cmalloc (unsigned size) { _cmalloc_entry *rvc; unsigned b, sz; /* Calculate "bit bucket" and size as a power of two. */ - for (b = 3, sz = 8; sz && sz < (size + sizeof (_cmalloc_entry)); - b++, sz <<= 1) + for (b = 3, sz = 8; sz && sz < size; b++, sz <<= 1) continue; cygheap_protect->acquire (); @@ -231,7 +230,7 @@ _cmalloc (int size) } else { - rvc = (_cmalloc_entry *) _csbrk (sz); + rvc = (_cmalloc_entry *) _csbrk (sz + sizeof (_cmalloc_entry)); if (!rvc) { cygheap_protect->release (); @@ -257,16 +256,15 @@ _cfree (void *ptr) cygheap_protect->release (); } -static void *__stdcall _crealloc (void *ptr, int size) __attribute__((regparm(2))); static void *__stdcall -_crealloc (void *ptr, int size) +_crealloc (void *ptr, unsigned size) { void *newptr; if (ptr == NULL) newptr = _cmalloc (size); else { - int oldsize = 1 << to_cmalloc (ptr)->b; + unsigned oldsize = 1 << to_cmalloc (ptr)->b; if (size <= oldsize) return ptr; newptr = _cmalloc (size); @@ -284,7 +282,7 @@ _crealloc (void *ptr, int size) #define tocygheap(s) ((cygheap_entry *) (((char *) (s)) - (int) (N->data))) inline static void * -creturn (cygheap_types x, cygheap_entry * c, int len) +creturn (cygheap_types x, cygheap_entry * c, unsigned len) { if (!c) { |