diff src/c/urweb.c @ 1360:02fc16faecf3

[De]serialization of times in JavaScript; proper integer division in JavaScript; Basis.crypt; Top.mkRead'; more aggressive Mono-level inlining, for values of function-y types
author Adam Chlipala <adam@chlipala.net>
date Thu, 23 Dec 2010 17:46:40 -0500
parents e525ad571e15
children 7dd8a6704265
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Dec 23 11:23:31 2010 -0500
+++ b/src/c/urweb.c	Thu Dec 23 17:46:40 2010 -0500
@@ -13,6 +13,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <crypt.h>
 
 #include <pthread.h>
 
@@ -2006,6 +2007,27 @@
   return uw_unit_v;
 }
 
+char *uw_Basis_jsifyTime(uw_context ctx, uw_Basis_time n) {
+  int len;
+  char *r;
+
+  uw_check_heap(ctx, INTS_MAX);
+  r = ctx->heap.front;
+  sprintf(r, "%lld%n", (uw_Basis_int)n, &len);
+  ctx->heap.front += len+1;
+  return r;
+}
+
+uw_unit uw_Basis_jsifyInt_w(uw_context ctx, uw_Basis_time n) {
+  int len;
+
+  uw_check(ctx, INTS_MAX);
+  sprintf(ctx->page.front, "%lld%n", (uw_Basis_int)n, &len);
+  ctx->page.front += len;
+  
+  return uw_unit_v;
+}
+
 char *uw_Basis_htmlifyString(uw_context ctx, uw_Basis_string s) {
   char *r, *s2;
 
@@ -3568,3 +3590,15 @@
 
   return r;
 }
+
+uw_Basis_string uw_Basis_crypt(uw_context ctx, uw_Basis_string key, uw_Basis_string salt) {
+  struct crypt_data *data;
+
+  if ((data = uw_get_global(ctx, "crypt")) == NULL) {
+    data = malloc(sizeof(struct crypt_data));
+    data->initialized = 0;
+    uw_set_global(ctx, "crypt", data, free);
+  }
+
+  return uw_strdup(ctx, crypt_r(key, salt, data));
+}