changeset 2017:bcda3ae88677

Align to sizeof(void *) instead of fixed 4
author Adam Chlipala <adam@chlipala.net>
date Wed, 28 May 2014 11:53:19 -0400 (2014-05-28)
parents 3ed2ee0815d2
children 57f59e46c336 cb74460f046a
files src/c/request.c src/c/urweb.c tests/listinit.ur
diffstat 3 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/request.c	Sun May 25 09:21:56 2014 -0400
+++ b/src/c/request.c	Wed May 28 11:53:19 2014 -0400
@@ -212,10 +212,10 @@
 }
 
 
-typedef struct uw_rc {
+struct uw_rc {
   size_t path_copy_size, queryString_size;
   char *path_copy, *queryString;
-} *uw_request_context;
+};
 
 uw_request_context uw_new_request_context(void) {
   uw_request_context r = malloc(sizeof(struct uw_rc));
--- a/src/c/urweb.c	Sun May 25 09:21:56 2014 -0400
+++ b/src/c/urweb.c	Wed May 28 11:53:19 2014 -0400
@@ -1259,8 +1259,8 @@
 static void align_heap(uw_context ctx) {
   size_t posn = ctx->heap.front - ctx->heap.start;
 
-  if (posn % 4 != 0) {
-    size_t bump = 4 - posn % 4;
+  if (posn % sizeof(void *) != 0) {
+    size_t bump = sizeof(void *) - posn % sizeof(void *);
     uw_check_heap(ctx, bump);
     ctx->heap.front += bump;
   }
@@ -1275,7 +1275,7 @@
   void *result;
 
   if (ctx->amInitializing) {
-    int error = posix_memalign(&result, 4, len);
+    int error = posix_memalign(&result, sizeof(void *), len);
 
     if (!error)
       return result;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/listinit.ur	Wed May 28 11:53:19 2014 -0400
@@ -0,0 +1,43 @@
+fun makeList n =
+    if n = 0 then
+        []
+    else
+        n :: makeList (n-1)
+
+fun sum ls =
+    case ls of
+        [] => 0
+      | n :: ls' => n + sum ls'
+
+val ls = 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: 1 :: 2 :: 3 :: 4 :: 5 :: 6 :: 7 :: 8 :: 9 :: 10
+           :: []
+
+task initialize = fn () =>
+                     debug (show (sum ls + sum ls))