From: Peep P. <so...@us...> - 2004-06-07 15:46:00
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9102 Modified Files: sys.c sys.h Log Message: Removed type_xmalloc, removed memory stats, added xrealloc Index: sys.h =================================================================== RCS file: /cvsroot/agd/server/src/sys.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- sys.h 1 Apr 2004 19:10:53 -0000 1.8 +++ sys.h 7 Jun 2004 15:45:51 -0000 1.9 @@ -2,10 +2,12 @@ #define _SYS_H /* memory allocation */ -#define type_xmalloc(type) (type *) xmalloc(sizeof(type)) +/*#define type_xmalloc(type) (type *) xmalloc(sizeof(type))*/ void *xmalloc(size_t bytes); +void *xrealloc(void *ptr, size_t bytes); void xfree(void *p); +#if 0 /* memory stats */ void mstats_summary(void); @@ -14,11 +16,14 @@ int free, free_on_null; int total_alloced; } mstats_t; +#endif /* configuration */ typedef struct { int port, heartbeat; +/* int exit_stats; +*/ char *lib_root, *error_log; char *master; int debuglevel; Index: sys.c =================================================================== RCS file: /cvsroot/agd/server/src/sys.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- sys.c 1 Apr 2004 19:10:53 -0000 1.13 +++ sys.c 7 Jun 2004 15:45:51 -0000 1.14 @@ -2,10 +2,10 @@ started in november 2003 by solicit changelog: + 4. June, 2004: wrote custom realloc() 2. December 2003: wrote custom malloc() */ -/* todo - custom realloc() */ #include "config.h" #include <stdlib.h> @@ -21,7 +21,9 @@ #include "compile_options.h" config_t conf; +/* static mstats_t mstats; +*/ #define CONFCHECK(x, y) if((x) == 0) { \ fprintf(stderr, "\""y": \" directive not found in config file.\n"); \ @@ -42,9 +44,10 @@ fprintf(stderr, "Can't open configuration file! (%s)\n", strerror(errno)); exit(5); } - +/* conf.exit_stats = 0; - +*/ + while(fscanf(f, "%s ", buf) != EOF) { line++; if(strncmp(buf, "port:", 5) == 0) { @@ -68,12 +71,12 @@ conf.error_log = stringdup(buf); continue; } - +/* if(strncmp(buf, "exitstats:", 11) == 0) { fscanf(f, "%d\n", &conf.exit_stats); continue; } - +*/ if(strncmp(buf, "master:", 8) == 0) { fscanf(f, "%s\n", buf); conf.master = stringdup(buf); @@ -98,6 +101,7 @@ CONFCHECK(conf.master, "master"); } +#if 0 char *bytes_string(int bytes) { static char buf[256]; @@ -141,29 +145,43 @@ printf(" Average bytes per call: %s\n", bytes_string(avg)); printf("----------------------------------------------------------\n"); } +#endif void *xmalloc(size_t bytes) { void *p; p = malloc(bytes); - mstats.alloc++; +/* mstats.alloc++;*/ if(!p) { fprintf(stderr, "Out of memory!\n"); - /* Call crash() ? */ + exit(1); /* Or crash()? */ + } + +/* mstats.total_alloced += bytes;*/ + return p; +} + +void *xrealloc(void *ptr, size_t bytes) +{ + void *p; + p = realloc(ptr, bytes); + + if(!p) { + fprintf(stderr, "Out of memory!\n"); + exit(1); } - mstats.total_alloced += bytes; return p; } #ifdef DEBUG void xfree(void *p) { - mstats.free++; +/* mstats.free++;*/ if(!p) { fprintf(stderr, "free() called on a nullpointer!\n"); - mstats.free_on_null++; +/* mstats.free_on_null++;*/ return; } |