diff options
author | 2009-12-24 15:49:52 -0500 | |
---|---|---|
committer | 2009-12-24 15:49:52 -0500 | |
commit | ce53cbc1fc2edb02c00331efed51221880a3129e (patch) | |
tree | a85cf2491794d4c0615efc0411e96bfe01159bb2 /src/c/urweb.c | |
parent | a180472c337acf02d6b89b4ddd11c415f5092187 (diff) |
Convenience libifying; allow more NULLs with globals
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r-- | src/c/urweb.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c index 1f8271d5..4a0306e0 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -468,7 +468,8 @@ void uw_free(uw_context ctx) { buf_free(&ctx->deltas[i].msgs); for (i = 0; i < ctx->n_globals; ++i) - ctx->globals[i].free(ctx->globals[i].data); + if (ctx->globals[i].free) + ctx->globals[i].free(ctx->globals[i].data); free(ctx); } @@ -3177,17 +3178,15 @@ void *uw_get_global(uw_context ctx, char *name) { void uw_set_global(uw_context ctx, char *name, void *data, void (*free)(void*)) { int i; - if (data == NULL) uw_error(ctx, FATAL, "NULL data value for global '%s'", name); - for (i = 0; i < ctx->n_globals; ++i) if (!strcmp(name, ctx->globals[i].name)) { - if (ctx->globals[i].data) + if (ctx->globals[i].free) ctx->globals[i].free(ctx->globals[i].data); ctx->globals[i].data = data; ctx->globals[i].free = free; return; } - + ++ctx->n_globals; ctx->globals = realloc(ctx->globals, ctx->n_globals * sizeof(global)); ctx->globals[ctx->n_globals-1].name = name; |