changeset 1334:a1aa62b472cf

Change Basis.debug to use the protocol's debug function
author Adam Chlipala <adam@chlipala.net>
date Sun, 12 Dec 2010 10:35:04 -0500
parents dab85a49e0ab
children 79557535b843
files include/urweb.h src/c/request.c src/c/urweb.c tests/hog.ur
diffstat 4 files changed, 16 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Sat Dec 11 19:57:22 2010 -0500
+++ b/include/urweb.h	Sun Dec 12 10:35:04 2010 -0500
@@ -20,7 +20,7 @@
 void uw_prune_clients(uw_context);
 failure_kind uw_initialize(uw_context);
 
-uw_context uw_init(void);
+uw_context uw_init(void *logger_data, uw_logger log_debug);
 void uw_close(uw_context);
 int uw_set_app(uw_context, uw_app*);
 uw_app *uw_get_app(uw_context);
--- a/src/c/request.c	Sat Dec 11 19:57:22 2010 -0500
+++ b/src/c/request.c	Sun Dec 12 10:35:04 2010 -0500
@@ -35,7 +35,7 @@
 }
 
 uw_context uw_request_new_context(uw_app *app, void *logger_data, uw_logger log_error, uw_logger log_debug) {
-  uw_context ctx = uw_init();
+  uw_context ctx = uw_init(logger_data, log_debug);
   int retries_left = MAX_RETRIES;
   uw_set_app(ctx, app);
 
--- a/src/c/urweb.c	Sat Dec 11 19:57:22 2010 -0500
+++ b/src/c/urweb.c	Sun Dec 12 10:35:04 2010 -0500
@@ -442,6 +442,9 @@
 
   void *client_data;
 
+  void *logger_data;
+  uw_logger log_debug;
+
   char error_message[ERROR_BUF_LEN];
 };
 
@@ -450,7 +453,7 @@
 size_t uw_heap_max = SIZE_MAX;
 size_t uw_script_max = SIZE_MAX;
 
-uw_context uw_init() {
+uw_context uw_init(void *logger_data, uw_logger log_debug) {
   uw_context ctx = malloc(sizeof(struct uw_context));
 
   ctx->app = NULL;
@@ -501,6 +504,9 @@
 
   ctx->client_data = uw_init_client_data();
 
+  ctx->logger_data = logger_data;
+  ctx->log_debug = log_debug;
+
   return ctx;
 }
 
@@ -3441,8 +3447,10 @@
 size_t uw_database_max = SIZE_MAX;
 
 uw_Basis_unit uw_Basis_debug(uw_context ctx, uw_Basis_string s) {
-  fprintf(stderr, "%s\n", s);
-
+  if (ctx->log_debug)
+    ctx->log_debug(ctx->logger_data, "%s\n", s);
+  else
+    fprintf(stderr, "%s\n", s);
   return uw_unit_v;
 }
 
--- a/tests/hog.ur	Sat Dec 11 19:57:22 2010 -0500
+++ b/tests/hog.ur	Sun Dec 12 10:35:04 2010 -0500
@@ -4,4 +4,6 @@
     else
         more (n-1) ^ more (n-1)
 
-fun main n = return <xml>{[more n]}</xml>
+fun main n =
+    debug "Let's give this a try....";
+    return <xml>{[more n]}</xml>