summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2012-07-18 17:29:13 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2012-07-18 17:29:13 -0400
commitdb71493ffd90e2668259efbb549f7a781c2530db (patch)
treeeda48e786ad2690ca0f2dc994a44290d74302129 /src/c/urweb.c
parente2b9068b56e352d5e3680fe5e4e0849169c5f419 (diff)
Support fancy expressions in module-level 'val' declarations
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 802a1620..d0b6987c 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -465,6 +465,8 @@ struct uw_context {
unsigned nextId;
+ int amInitializing;
+
char error_message[ERROR_BUF_LEN];
};
@@ -536,6 +538,8 @@ uw_context uw_init(int id, void *logger_data, uw_logger log_debug) {
ctx->nextId = 0;
+ ctx->amInitializing = 0;
+
return ctx;
}
@@ -613,6 +617,7 @@ void uw_reset_keep_error_message(uw_context ctx) {
ctx->script_header = "";
ctx->queryString = NULL;
ctx->nextId = 0;
+ ctx->amInitializing = 0;
}
void uw_reset_keep_request(uw_context ctx) {
@@ -1204,14 +1209,31 @@ void uw_set_heap_front(uw_context ctx, char *fr) {
ctx->heap.front = fr;
}
+void uw_begin_initializing(uw_context ctx) {
+ ctx->amInitializing = 1;
+}
+
+void uw_end_initializing(uw_context ctx) {
+ ctx->amInitializing = 0;
+}
+
void *uw_malloc(uw_context ctx, size_t len) {
void *result;
- uw_check_heap(ctx, len);
+ if (ctx->amInitializing) {
+ result = malloc(len);
- result = ctx->heap.front;
- ctx->heap.front += len;
- return result;
+ if (result)
+ return result;
+ else
+ uw_error(ctx, FATAL, "uw_malloc: malloc() returns 0");
+ } else {
+ uw_check_heap(ctx, len);
+
+ result = ctx->heap.front;
+ ctx->heap.front += len;
+ return result;
+ }
}
void uw_begin_region(uw_context ctx) {