X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f Date: Sun, 07 Sep 2003 13:04:50 +0100 From: "Richard Dawe" Sender: rich AT phekda DOT freeserve DOT co DOT uk To: djgpp-workers AT delorie DOT com X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6 Subject: nmalloc integration - diffs vs. stock distribution [PATCH] Message-Id: Reply-To: djgpp-workers AT delorie DOT com Hello. Below is a diff for the changes I made when starting to integrate nmalloc into DJGPP. The diff is against the stock sources downloaded from CBFalconer's site here: http://cbfalconer.home.att.net/download/nmalloc.zip This is just FYI. The 'root' -> 'node' changes are needed, because the use of 'root' as a function parameter was shadowing the global variable 'root'. Hopefully the other changes are self-explanatory. Bye, Rich =] --- c:/develop/djgpp.nmalloc/nmalloc-20030626/nmalloc.c 2003-06-26 22:19:16.000000000 +0000 +++ c:/develop/djgpp.nmalloc/src/libc/ansi/stdlib/nmalloc.c 2003-09-06 16:06:46.000000000 +0000 @@ -26,6 +26,8 @@ INT_MAX (system) controls maximum allocation quantum. */ +#include + /* To avoid unexpected problems, the default has been changed so we now require NEWMALLDBG to enable the original action */ @@ -74,7 +76,11 @@ typedef unsigned int ulong; #include /* raise, SIGABRT */ #include /* strlen, memmove, memcpy */ #include /* CHAR_BIT, INT_MAX */ + +/* TODO: FIXME: #if 0/#endif is wreakage from nmalloc integration. */ +#if 0 #include "sysquery.h" /* available debugger linkages */ +#endif /* system dependant magic. Only STDERR used */ enum {STDIN = 0, STDOUT, STDERR, STDAUX, STDPRN}; /* handles */ --- c:/develop/djgpp.nmalloc/nmalloc-20030626/malldbg.c 2003-06-11 05:52:08.000000000 +0000 +++ c:/develop/djgpp.nmalloc/src/libc/ansi/stdlib/nmalldbg.c 2003-09-06 13:49:02.000000000 +0000 @@ -12,7 +12,11 @@ #include #include #include /* raise, SIGABRT */ + +/* TODO: FIXME: #if 0/#endif is wreakage from nmalloc integration. */ +#if 0 #include "malldbg.h" /* and sysquery.h */ +#endif /* This is to be used in conjunction with a version of nmalloc.c compiled with: --- c:/develop/djgpp.nmalloc/nmalloc-20030626/evilalgo.c 2002-04-13 03:14:40.000000000 +0000 +++ c:/develop/djgpp.nmalloc/tests/libc/ansi/stdlib/evilalgo.c 2003-09-06 13:36:40.000000000 +0000 @@ -17,7 +17,16 @@ record **dt, *d; int main(int argc, char ** argv) { +#if 0 unsigned long n = 1000; /* was 200000L */ +#else + /* + * : 1000 was OK; 2000 showed + * pathological behaviour with the old malloc on my development box, + * which has 640MB of memory. + */ + unsigned long n = 2000; +#endif unsigned int count; void *v; --- c:/develop/djgpp.nmalloc/nmalloc-20030626/tnmalloc.c 2003-06-21 18:44:22.000000000 +0000 +++ c:/develop/djgpp.nmalloc/tests/libc/ansi/stdlib/tnmalloc/tnmalloc.c 2003-09-06 14:36:56.000000000 +0000 @@ -13,10 +13,17 @@ #include #include #include +#include /* write */ + #include "fakesbrk.h" #include "cokusMT.h" + +/* TODO: FIXME: #if 0/#endif is wreakage from nmalloc integration. */ +#if 0 #include "sysquery.h" -#include /* write */ +#endif + +#define NDEBUG /* NDEBUG allows this to be used for profiling malloc.o */ #ifndef NDEBUG @@ -29,6 +36,21 @@ # define INTERVAL 1000 /* for emitting free list dumps */ #endif +void test01(int n); +void test02(int n); +void test03(int n); +void test04(int n); +void test05(int n); +void test06(int n); +void test07(int n); +void test08(int n); +void test09(int n); +void showijk(int i, int j, int k); +void showsysquery(void); +void inject(int i); +double gaussrand(void); +double gausspos(void); + /* Magic 1500 below must be > MINSBRK in nmalloc.c */ enum {FAKESIZE = 1234567, HIFAKESZ = 1500, @@ -132,7 +154,7 @@ void showsysquery(void) /* m is the allocated ptr treated by MEMBLKp */ /* Fouls if sysinfo has not been initialized */ /* See main for sysinfo initialization sequence */ -static void xshowblock(void *m, char *id) +static void xshowblock(void *m, const char *id) { if (m) { printf(" %s %p", id, m); @@ -229,9 +251,9 @@ enum {STDIN = 0, STDOUT, STDERR, STDAUX, /* made to be compatible with nmalloc internal debugger */ void inject(int i) { +#ifndef NDEBUG char buf[20]; -#ifndef NDEBUG sprintf(buf, "%03d: ", i); write(STDOUT, buf, strlen(buf)); #endif @@ -306,9 +328,9 @@ void test04(int n) /* made to be compatible with nmalloc internal debugger */ void showijk(int i, int j, int k) { +#ifndef NDEBUG char buf[20]; -#ifndef NDEBUG sprintf(buf, "%03d:%d:%d ", i, j, k); write(STDOUT, buf, strlen(buf)); #endif @@ -455,8 +477,12 @@ double gaussrand(void) if (phase) Y = V2 * X; else { do { - U1 = (double)randomMT() / ranMTMAX; - U2 = (double)randomMT() / ranMTMAX; + /* + * Cast via long to work around a compiler bug. gcc falsely + * complains. See: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=6980 + */ + U1 = (double)(long)randomMT() / ranMTMAX; + U2 = (double)(long)randomMT() / ranMTMAX; V1 = 2 * U1 - 1; V2 = 2 * U2 - 1; --- c:/develop/djgpp.nmalloc/nmalloc-20030626/tmalldbg.c 2003-05-04 22:50:38.000000000 +0000 +++ c:/develop/djgpp.nmalloc/tests/libc/ansi/stdlib/tnmalloc/tnmaldbg.c 2003-09-06 14:47:32.000000000 +0000 @@ -11,8 +11,12 @@ #include #include #include + +/* TODO: FIXME: #if 0/#endif is wreakage from nmalloc integration. */ +#if 0 #include "malldbg.h" #include "sysquery.h" +#endif /*#include #include @@ -31,22 +35,34 @@ testnode *root; int notquiet; +void test01(unsigned long n); +void test02(unsigned long n); +void test03(unsigned long n); +void test04(unsigned long n); +void test05(unsigned long n); +void test06(unsigned long n); +void test07(unsigned long n); +void test08(unsigned long n); +void showsysquery(void); +void printinfo(struct mallinfo *info); +void foul2ndlast(testnode *node); + /* 1------------------1 */ /* Build something to display the structure of */ /* a linked list headed by the global var 'root' */ -static testnode *buildlist(int items, testnode *root) +static testnode *buildlist(int items, testnode *node) { testnode *this; while (items) { this = malloc(items + sizeof *this); - this->next = root; - root = this; + this->next = node; + node = this; sprintf(this->string, "item #%d", items); items--; } - return root; + return node; } /* buildlist */ /* 1------------------1 */ @@ -54,23 +70,23 @@ static testnode *buildlist(int items, te /* retains 1 in three of original list, Ex: a -> b -> c -> d ::= a -> d, b & c freed This allows exercizing the free list compaction */ -static void prunelist(testnode *root) +static void prunelist(testnode *node) { testnode *this, *keep; - while (root) { - keep = root; - this = root->next; - if ((root = this)) { - this = root->next; - free(root); - if ((root = this)) { - this = root->next; - free(root); - root = this; + while (node) { + keep = node; + this = node->next; + if ((node = this)) { + this = node->next; + free(node); + if ((node = this)) { + this = node->next; + free(node); + node = this; } } - keep->next = root; + keep->next = node; } } /* prunelist */ @@ -131,7 +147,7 @@ void showsysquery(void) /* m is the allocated ptr treated by MEMBLKp */ /* Fouls if sysinfo has not been initialized */ /* See main for sysinfo initialization sequence */ -static void xshowblock(void *m, char *id) +static void xshowblock(void *m, const char *id) { if (m) { printf(" %s %p", id, m); @@ -164,7 +180,7 @@ struct blkspace { /* 1------------------1 */ -struct blkspace freeblocks() +struct blkspace freeblocks(void) { struct blkspace blksp; int i; @@ -201,14 +217,14 @@ void printinfo(struct mallinfo *info) /* 1------------------1 */ -void foul2ndlast(testnode *root) +void foul2ndlast(testnode *node) { testnode *this, *prev; void *m; this = prev = NULL; - while (root) { - prev = this; this = root; root = root->next; + while (node) { + prev = this; this = node; node = node->next; } /* Now prev=>this=>NULL */ m = MEMBLKp(prev);