From ff0f0220601f448169de6cda01f3a39f04bae808 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Wed, 19 May 1999 20:27:11 +0000 Subject: [PATCH] Change naming to match newer mLib conventions. Organization: Straylight/Edgeware From: mdw --- exc.c | 19 +++++++------ sub.c | 27 ++++++++++-------- trace.c | 45 ++++++++++++++++-------------- track.c | 85 +++++++++++++++++++++++++++++---------------------------- 4 files changed, 94 insertions(+), 82 deletions(-) diff --git a/exc.c b/exc.c index 7ef3812..0b5cf3e 100644 --- a/exc.c +++ b/exc.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: exc.c,v 1.4 1999/05/17 20:35:30 mdw Exp $ + * $Id: exc.c,v 1.5 1999/05/19 20:27:11 mdw Exp $ * * Structured exception handling in C * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: exc.c,v $ + * Revision 1.5 1999/05/19 20:27:11 mdw + * Change naming to match newer mLib conventions. + * * Revision 1.4 1999/05/17 20:35:30 mdw * Output uncaught exception types in hex, because they're easier to * translate that way. @@ -57,7 +60,7 @@ __exc_hnd *__exc_list = 0; /*----- Functions ---------------------------------------------------------*/ -/* --- @exc__duff@ --- * +/* --- @duff@ --- * * * Arguments: @exc_extype type@ = type of duff exception * @exc_exval val@ = extra data supplied @@ -67,18 +70,18 @@ __exc_hnd *__exc_list = 0; * Use: Default handler when everything goes wrong. */ -static void exc__duff(exc_extype type, exc_exval val) +static void duff(exc_extype type, exc_exval val) { fprintf(stderr, "fatal error: uncaught exception (type = %lx)\n", type); abort(); } -/* --- @exc__duffproc@ --- * +/* --- @duffproc@ --- * * * Current handler when there are no more exceptions left. */ -static exc__uncaught exc__duffproc = exc__duff; +static exc__uncaught duffproc = duff; /* --- @exc_uncaught@ --- * * @@ -91,9 +94,9 @@ static exc__uncaught exc__duffproc = exc__duff; exc__uncaught exc_uncaught(exc__uncaught proc) { - exc__uncaught p = exc__duffproc; + exc__uncaught p = duffproc; if (proc) - exc__duffproc = proc; + duffproc = proc; return (p); } @@ -146,7 +149,7 @@ void __exc_rethrow(exc_extype type, exc_exval val) { __exc_hnd *p = __exc_list; if (!p) - exc__duffproc(type, val); + duffproc(type, val); p->type = type; p->val = val; __exc_list = p->next; diff --git a/sub.c b/sub.c index bb264a2..57ee194 100644 --- a/sub.c +++ b/sub.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sub.c,v 1.4 1999/05/13 22:48:55 mdw Exp $ + * $Id: sub.c,v 1.5 1999/05/19 20:27:11 mdw Exp $ * * Allocation of known-size blocks * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: sub.c,v $ + * Revision 1.5 1999/05/19 20:27:11 mdw + * Change naming to match newer mLib conventions. + * * Revision 1.4 1999/05/13 22:48:55 mdw * Change `-ise' to `-ize' throughout. * @@ -134,8 +137,8 @@ /*----- Static variables --------------------------------------------------*/ -static void *sub__bins[SUB_BINS]; -static size_t sub__sizes[SUB_BINS]; +static void *bins[SUB_BINS]; +static size_t sizes[SUB_BINS]; /*----- Main code ---------------------------------------------------------*/ @@ -161,11 +164,11 @@ void *sub_alloc(size_t s) /* --- If the bin is empty, find some memory --- */ - if (!sub__bins[bin]) { + if (!bins[bin]) { char *p, *q; - p = xmalloc(sub__sizes[bin]); - q = p + sub__sizes[bin]; + p = xmalloc(sizes[bin]); + q = p + sizes[bin]; s = SUB_BINSZ(bin); @@ -177,13 +180,13 @@ void *sub_alloc(size_t s) *(void **)q = q + s; } - sub__bins[bin] = p; + bins[bin] = p; } /* --- Extract the first block in the list --- */ - p = sub__bins[bin]; - sub__bins[bin] = *(void **)p; + p = bins[bin]; + bins[bin] = *(void **)p; return (p); } @@ -204,8 +207,8 @@ void sub_free(void *p, size_t s) if (bin >= SUB_BINS) free(p); else { - *(void **)p = sub__bins[bin]; - sub__bins[bin] = p; + *(void **)p = bins[bin]; + bins[bin] = p; } } @@ -225,7 +228,7 @@ void sub_init(void) /* --- Initialize the sizes bins --- */ for (i = 1; i < SUB_BINS; i++) { - sub__sizes[i] = ((SUB_CHUNK + SUB_BINSZ(i) - 1) / + sizes[i] = ((SUB_CHUNK + SUB_BINSZ(i) - 1) / SUB_BINSZ(i) * SUB_BINSZ(i)); } } diff --git a/trace.c b/trace.c index d5bdcb7..c1688ef 100644 --- a/trace.c +++ b/trace.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: trace.c,v 1.3 1999/05/06 19:51:35 mdw Exp $ + * $Id: trace.c,v 1.4 1999/05/19 20:27:11 mdw Exp $ * * Tracing functions for debugging * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: trace.c,v $ + * Revision 1.4 1999/05/19 20:27:11 mdw + * Change naming to match newer mLib conventions. + * * Revision 1.3 1999/05/06 19:51:35 mdw * Reformatted the LGPL notice a little bit. * @@ -58,8 +61,8 @@ /*----- Private state information -----------------------------------------*/ -static FILE *trace__fp = 0; /* Where does debugging go? */ -static unsigned int trace__lvl = 0; /* How much tracing gets done? */ +static FILE *tracefp = 0; /* Where does debugging go? */ +static unsigned int tracelvl = 0; /* How much tracing gets done? */ /*----- Functions provided ------------------------------------------------*/ @@ -80,11 +83,11 @@ void trace(unsigned int l, const char *f, ...) if ((l & tracing()) == 0) return; va_start(ap, f); - fprintf(trace__fp, "*** %s: ", QUIS); - vfprintf(trace__fp, f, ap); + fprintf(tracefp, "*** %s: ", QUIS); + vfprintf(tracefp, f, ap); va_end(ap); - putc('\n', trace__fp); - fflush(trace__fp); + putc('\n', tracefp); + fflush(tracefp); } /* --- @trace_block@ --- * @@ -113,28 +116,28 @@ void trace_block(unsigned int l, const char *s, const void *b, size_t sz) /* --- Now start work --- */ - fprintf(trace__fp, "*** %s: %s\n", QUIS, s); + fprintf(tracefp, "*** %s: %s\n", QUIS, s); while (sz) { - fprintf(trace__fp, "*** %s: %08lx : ", QUIS, o); + fprintf(tracefp, "*** %s: %08lx : ", QUIS, o); for (i = 0; i < 8; i++) { if (i < sz) - fprintf(trace__fp, "%02x ", p[i]); + fprintf(tracefp, "%02x ", p[i]); else - fputs("** ", trace__fp); + fputs("** ", tracefp); } - fputs(": ", trace__fp); + fputs(": ", tracefp); for (i = 0; i < 8; i++) { if (i < sz) - fputc(isprint(p[i]) ? p[i] : '.', trace__fp); + fputc(isprint(p[i]) ? p[i] : '.', tracefp); else - fputc('*', trace__fp); + fputc('*', tracefp); } - fputc('\n', trace__fp); + fputc('\n', tracefp); c = (sz >= 8) ? 8 : sz; sz -= c, p += c, o += c; } - fflush(trace__fp); + fflush(tracefp); } /* --- @trace_on@ --- * @@ -149,9 +152,9 @@ void trace_block(unsigned int l, const char *s, const void *b, size_t sz) void trace_on(FILE *fp, unsigned int l) { - trace__fp = fp; - if (!trace__lvl) - trace__lvl = l; + tracefp = fp; + if (!tracelvl) + tracelvl = l; } /* --- @trace_setLevel@ --- * @@ -165,7 +168,7 @@ void trace_on(FILE *fp, unsigned int l) void trace_setLevel(unsigned int l) { - trace__lvl = l; + tracelvl = l; } /* --- @tracing@ --- * @@ -179,7 +182,7 @@ void trace_setLevel(unsigned int l) unsigned int tracing(void) { - return (trace__fp ? trace__lvl : 0u); + return (tracefp ? tracelvl : 0u); } /*----- That's all, folks -------------------------------------------------*/ diff --git a/track.c b/track.c index 52e800d..10da09b 100644 --- a/track.c +++ b/track.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: track.c,v 1.3 1999/05/06 19:51:36 mdw Exp $ + * $Id: track.c,v 1.4 1999/05/19 20:27:11 mdw Exp $ * * Tracing functions for debugging * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: track.c,v $ + * Revision 1.4 1999/05/19 20:27:11 mdw + * Change naming to match newer mLib conventions. + * * Revision 1.3 1999/05/06 19:51:36 mdw * Reformatted the LGPL notice a little bit. * @@ -63,35 +66,35 @@ * This gets prefixed to every block I manage. */ -typedef union track__block { +typedef union block { struct { - union track__block *next; /* Link to previous block */ - union track__block *prev; /* Link to next block */ + union block *next; /* Link to previous block */ + union block *prev; /* Link to next block */ size_t sz; /* Size of the block */ const char *ctx; /* Pointer to allocating context */ } x; /* Main data area */ long double _ld; /* Long double for alignment */ void *_p; /* Void pointer for alignment */ -} track__block; +} block; /*----- Private state -----------------------------------------------------*/ /* --- Tracking memory usage --- */ -static unsigned int track__used = 0; /* Count of bytes occupied */ -static track__block *track__list; /* List of allocated blocks */ +static unsigned int used = 0; /* Count of bytes occupied */ +static block *list; /* List of allocated blocks */ /* --- Trace level for verbose messages --- */ -static unsigned int track__vLevel = 0; +static unsigned int vLevel = 0; /* --- Context tracking --- */ -static track_ctx track__baseContext = { +static track_ctx baseContext = { 0, "[unknown context]" }; -static track_ctx *track__context = &track__baseContext; +static track_ctx *context = &baseContext; /*----- Functions provided ------------------------------------------------*/ @@ -106,7 +109,7 @@ static track_ctx *track__context = &track__baseContext; void track_setLevel(unsigned int l) { - track__vLevel = l; + vLevel = l; } /* --- @track_pushContext@ --- * @@ -120,8 +123,8 @@ void track_setLevel(unsigned int l) void track_pushContext(track_ctx *ctx) { - ctx->next = track__context; - track__context = ctx; + ctx->next = context; + context = ctx; } /* --- @track_popContext@ --- * @@ -135,7 +138,7 @@ void track_pushContext(track_ctx *ctx) void track_popContext(track_ctx *ctx) { - track__context = ctx->next; + context = ctx->next; } /* --- @track_malloc@ --- * @@ -149,20 +152,20 @@ void track_popContext(track_ctx *ctx) void *track_malloc(size_t sz) { - track__block *q = (malloc)(sz + sizeof(track__block)); + block *q = (malloc)(sz + sizeof(block)); if (q) { - track__used += sz; - if (track__vLevel) { - trace(track__vLevel, "(track) allocated %lu at %p in %s", - (unsigned long)sz, (void *)(q + 1), track__context->s); + used += sz; + if (vLevel) { + trace(vLevel, "(track) allocated %lu at %p in %s", + (unsigned long)sz, (void *)(q + 1), context->s); } q->x.sz = sz; - q->x.next = track__list; + q->x.next = list; q->x.prev = 0; - q->x.ctx = track__context->s; + q->x.ctx = context->s; if (q->x.next) q->x.next->x.prev = q; - track__list = q; + list = q; return (q + 1); } return (0); @@ -179,23 +182,23 @@ void *track_malloc(size_t sz) void track_free(void *p) { - track__block *q; + block *q; if (!p) return; - q = (track__block *)p - 1; - if (track__vLevel) { - trace(track__vLevel, "(track) freed %lu at %p for %s in %s", + q = (block *)p - 1; + if (vLevel) { + trace(vLevel, "(track) freed %lu at %p for %s in %s", (unsigned long)q->x.sz, (void *)(q + 1), - q->x.ctx, track__context->s); + q->x.ctx, context->s); } if (q->x.next) q->x.next->x.prev = q->x.prev; if (q->x.prev) q->x.prev->x.next = q->x.next; else - track__list = q->x.next; - track__used -= q->x.sz; + list = q->x.next; + used -= q->x.sz; (free)(q); } @@ -213,36 +216,36 @@ void track_free(void *p) void *track_realloc(void *p, size_t sz) { size_t osz; - track__block *q, *qq; + block *q, *qq; if (p) { - q = (track__block *)p - 1; + q = (block *)p - 1; osz = q->x.sz; if (q->x.next) q->x.next->x.prev = q->x.prev; if (q->x.prev) q->x.prev->x.next = q->x.next; else - track__list = q->x.next; + list = q->x.next; } else { q = 0; osz = 0; } - qq = (realloc)(q, sz + sizeof(track__block)); + qq = (realloc)(q, sz + sizeof(block)); if (qq) { - if (track__vLevel) { - trace(track__vLevel, + if (vLevel) { + trace(vLevel, "(track) reallocated %lu at %p to %lu for %s in %s", (unsigned long)osz, (void *)(q + 1), (unsigned long)sz, (void *)(qq + 1), - qq->x.ctx, track__context->s); + qq->x.ctx, context->s); } qq->x.sz = sz; - qq->x.next = track__list; + qq->x.next = list; qq->x.prev = 0; if (qq->x.next) qq->x.next->x.prev = qq; - track__list = qq; - track__used += sz - osz; + list = qq; + used += sz - osz; qq->x.sz = sz; return (qq + 1); } @@ -261,7 +264,7 @@ void *track_realloc(void *p, size_t sz) unsigned long track_used(void) { - return (track__used); + return (used); } /* --- @track_list@ --- * @@ -279,7 +282,7 @@ unsigned long track_used(void) void track_list(unsigned int l) { - track__block *q = track__list; + block *q = list; if (!(tracing() & l)) return; -- [mdw]