>> On Tuesday 02 April 2002 04:36, Peter Gibbs wrote:
>"Bryan C. Warnock" <[EMAIL PROTECTED]> wrote:

> buflen should be 16, not 0.  bufused should be 0.

Currently, string_make sets the value of buflen. It does not know about
Parrot_allocate's rounding rule, so it uses the supplied size. The patch
below changes string_make to set the allocation request (and hence buflen)
to one less than the next multiple of 16; thus a zero allocation will end up
with a buflen of 15. This looks to be the best that can be done simply.

> > Parrot_go_collect uses a slightly different rounding rule, and will
> allocate
> > zero bytes to a zero-length buffer; the current allocation address will
be
> > placed in bufstart, but the same address will be used for the next
buffer
> > collected.
>
> They should probably round the same.

The patch below changes the GC code to use the same rounding algorithm as
Parrot_allocate i.e. round up to next multiple of 16.

--
Peter Gibbs
EmKel Systems

Index: string.c
===================================================================
RCS file: /home/perlcvs/parrot/string.c,v
retrieving revision 1.65
diff -u -r1.65 string.c
--- string.c  30 Mar 2002 03:04:37 -0000  1.65
+++ string.c  2 Apr 2002 13:24:50 -0000
@@ -47,13 +47,13 @@
     }

     s = new_string_header(interpreter);
-    s->bufstart = Parrot_allocate(interpreter, buflen);
+    s->bufstart = Parrot_allocate(interpreter, buflen | 15);
     s->encoding = encoding;
     /* Make sure we maintain the flags we might already have on the
      * string header we just fetched */
     s->flags |= flags;
     s->type = type;
-    s->buflen = buflen;
+    s->buflen = buflen | 15;

     if (buffer) {
         mem_sys_memcopy(s->bufstart, buffer, buflen);
Index: resources.c
===================================================================
RCS file: /home/perlcvs/parrot/resources.c,v
retrieving revision 1.39
diff -u -r1.39 resources.c
--- resources.c 1 Apr 2002 04:35:14 -0000 1.39
+++ resources.c 2 Apr 2002 13:13:53 -0000
@@ -727,10 +727,8 @@
          interpreter->arena_base->string_header_pool->pool_buffer.buflen);
   interpreter->arena_base->string_header_pool->pool_buffer.bufstart =
cur_spot;
   cur_size =
interpreter->arena_base->string_header_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size += 16;
+  cur_size &= ~0x0f;
   cur_spot += cur_size;

   /* Collect the PMC header pool */
@@ -739,10 +737,8 @@
          interpreter->arena_base->pmc_pool->pool_buffer.buflen);
   interpreter->arena_base->pmc_pool->pool_buffer.bufstart = cur_spot;
   cur_size = interpreter->arena_base->pmc_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size += 16;
+  cur_size &= ~0x0f;
   cur_spot += cur_size;

   /* And the buffer header pool */
@@ -751,10 +747,8 @@
          interpreter->arena_base->buffer_header_pool->pool_buffer.buflen);
   interpreter->arena_base->buffer_header_pool->pool_buffer.bufstart =
cur_spot;
   cur_size =
interpreter->arena_base->buffer_header_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size += 16;
+  cur_size &= ~0x0f;
   cur_spot += cur_size;

   /* Run through all the buffer header pools and copy */
@@ -772,10 +766,8 @@
                string_array[i].buflen);
         string_array[i].bufstart = cur_spot;
         cur_size = string_array[i].buflen;
-        if (cur_size & 0x0f) {
-          cur_size &= ~0x0f;
-          cur_size += 16;
-        }
+        cur_size += 16;
+        cur_size &= ~0x0f;
         cur_spot += cur_size;
       }
     }


Reply via email to