/* -*-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
*
/*----- 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.
/*----- Functions ---------------------------------------------------------*/
-/* --- @exc__duff@ --- *
+/* --- @duff@ --- *
*
* Arguments: @exc_extype type@ = type of duff exception
* @exc_exval val@ = extra data supplied
* 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@ --- *
*
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);
}
{
__exc_hnd *p = __exc_list;
if (!p)
- exc__duffproc(type, val);
+ duffproc(type, val);
p->type = type;
p->val = val;
__exc_list = p->next;
/* -*-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
*
/*----- 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.
*
/*----- 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 ---------------------------------------------------------*/
/* --- 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);
*(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);
}
if (bin >= SUB_BINS)
free(p);
else {
- *(void **)p = sub__bins[bin];
- sub__bins[bin] = p;
+ *(void **)p = bins[bin];
+ bins[bin] = p;
}
}
/* --- 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));
}
}
/* -*-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
*
/*----- 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.
*
/*----- 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 ------------------------------------------------*/
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@ --- *
/* --- 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@ --- *
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@ --- *
void trace_setLevel(unsigned int l)
{
- trace__lvl = l;
+ tracelvl = l;
}
/* --- @tracing@ --- *
unsigned int tracing(void)
{
- return (trace__fp ? trace__lvl : 0u);
+ return (tracefp ? tracelvl : 0u);
}
/*----- That's all, folks -------------------------------------------------*/
/* -*-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
*
/*----- 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.
*
* 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 ------------------------------------------------*/
void track_setLevel(unsigned int l)
{
- track__vLevel = l;
+ vLevel = l;
}
/* --- @track_pushContext@ --- *
void track_pushContext(track_ctx *ctx)
{
- ctx->next = track__context;
- track__context = ctx;
+ ctx->next = context;
+ context = ctx;
}
/* --- @track_popContext@ --- *
void track_popContext(track_ctx *ctx)
{
- track__context = ctx->next;
+ context = ctx->next;
}
/* --- @track_malloc@ --- *
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);
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);
}
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);
}
unsigned long track_used(void)
{
- return (track__used);
+ return (used);
}
/* --- @track_list@ --- *
void track_list(unsigned int l)
{
- track__block *q = track__list;
+ block *q = list;
if (!(tracing() & l))
return;