comparison src/c/urweb.c @ 1413:45bd58736bb2

Fix issues with empty page buffers for tasks
author Adam Chlipala <adam@chlipala.net>
date Sun, 23 Jan 2011 14:59:59 -0500
parents 55d0c8b01d18
children d0786ff9bb22
comparison
equal deleted inserted replaced
1412:5f4fee8a4dcd 1413:45bd58736bb2
460 ctx->app = NULL; 460 ctx->app = NULL;
461 461
462 ctx->get_header = NULL; 462 ctx->get_header = NULL;
463 ctx->get_header_data = NULL; 463 ctx->get_header_data = NULL;
464 464
465 uw_buffer_init(uw_headers_max, &ctx->outHeaders, 0); 465 uw_buffer_init(uw_headers_max, &ctx->outHeaders, 1);
466 uw_buffer_init(uw_page_max, &ctx->page, 0); 466 ctx->outHeaders.start[0] = 0;
467 uw_buffer_init(uw_page_max, &ctx->page, 1);
468 ctx->page.start[0] = 0;
467 ctx->returning_indirectly = 0; 469 ctx->returning_indirectly = 0;
468 uw_buffer_init(uw_heap_max, &ctx->heap, uw_min_heap); 470 uw_buffer_init(uw_heap_max, &ctx->heap, uw_min_heap);
469 uw_buffer_init(uw_script_max, &ctx->script, 1); 471 uw_buffer_init(uw_script_max, &ctx->script, 1);
470 ctx->script.start[0] = 0; 472 ctx->script.start[0] = 0;
471 473
1496 ctx_uw_buffer_check(ctx, "page", &ctx->page, extra); 1498 ctx_uw_buffer_check(ctx, "page", &ctx->page, extra);
1497 } 1499 }
1498 1500
1499 static void uw_writec_unsafe(uw_context ctx, char c) { 1501 static void uw_writec_unsafe(uw_context ctx, char c) {
1500 *(ctx->page.front)++ = c; 1502 *(ctx->page.front)++ = c;
1503 *ctx->page.front = 0;
1501 } 1504 }
1502 1505
1503 void uw_writec(uw_context ctx, char c) { 1506 void uw_writec(uw_context ctx, char c) {
1504 uw_check(ctx, 1); 1507 uw_check(ctx, 2);
1505 uw_writec_unsafe(ctx, c); 1508 uw_writec_unsafe(ctx, c);
1506 } 1509 }
1507 1510
1508 static void uw_write_unsafe(uw_context ctx, const char* s) { 1511 static void uw_write_unsafe(uw_context ctx, const char* s) {
1509 int len = strlen(s); 1512 int len = strlen(s);
3142 3145
3143 for (i = ctx->used_transactionals-1; i >= 0; --i) 3146 for (i = ctx->used_transactionals-1; i >= 0; --i)
3144 if (ctx->transactionals[i].free) 3147 if (ctx->transactionals[i].free)
3145 ctx->transactionals[i].free(ctx->transactionals[i].data, 0); 3148 ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
3146 3149
3150 if (*ctx->page.front)
3151 uw_writec(ctx, 0);
3152
3147 // Splice script data into appropriate part of page 3153 // Splice script data into appropriate part of page
3148 if (ctx->returning_indirectly || ctx->script_header[0] == 0) { 3154 if (ctx->returning_indirectly || ctx->script_header[0] == 0) {
3149 char *start = strstr(ctx->page.start, "<sc>"); 3155 char *start = strstr(ctx->page.start, "<sc>");
3150 if (start) { 3156 if (start) {
3151 memmove(start, start + 4, uw_buffer_used(&ctx->page) - (start - ctx->page.start) - 4); 3157 memmove(start, start + 4, uw_buffer_used(&ctx->page) - (start - ctx->page.start) - 4);