diff src/c/urweb.c @ 1089:f1647f16097d

Convenience libifying; allow more NULLs with globals
author Adam Chlipala <adamc@hcoop.net>
date Thu, 24 Dec 2009 15:49:52 -0500
parents e81434513720
children db52c32dbe42
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Dec 24 10:59:35 2009 -0500
+++ b/src/c/urweb.c	Thu Dec 24 15:49:52 2009 -0500
@@ -468,7 +468,8 @@
     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_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;