Index: assemble.pl
===================================================================
RCS file: /home/perlcvs/parrot/assemble.pl,v
retrieving revision 1.7
diff -u -r1.7 assemble.pl
--- assemble.pl 2001/09/11 08:38:04     1.7
+++ assemble.pl 2001/09/12 07:36:21
@@ -117,11 +117,10 @@
 sub emit_constants_section {
     # First, compute how big it's going to be.
     # The fields we'll need to fill in are: strlen, flags, encoding, type
-    my $size =0 ;
+    my $size = 0;
     for (@constants) {
         $size += 4*$sizeof_packi;
-        $size += length($_);
-        $size += length($_) % $sizeof_packi; # Padding
+        $size += (length($_) + $sizeof_packi-1) & ~($sizeof_packi-1);
     }
 
     $size += $sizeof_packi if @constants; # That's for the number of constants
@@ -136,6 +135,7 @@
         $output .= pack($pack_type{i},0) x 3; # Flags, encoding, type
         $output .= pack($pack_type{i},length($_)); # Strlen followed by that many 
bytes.
         $output .= $_;
-        $output .= "\0" x (length($_) % $sizeof_packi); # Padding;
+        my $padlen = (length($_) + $sizeof_packi-1) & ~($sizeof_packi-1);
+        $output .= "\0" x ($padlen - length($_));
     }
 }
Index: bytecode.c
===================================================================
RCS file: /home/perlcvs/parrot/bytecode.c,v
retrieving revision 1.4
diff -u -r1.4 bytecode.c
--- bytecode.c  2001/09/10 21:47:26     1.4
+++ bytecode.c  2001/09/12 07:36:21
@@ -83,14 +83,13 @@
         len -= 4 * sizeof(IV);
 
         Parrot_string_constants[i++] = string_make(*program_code /* ouch */, buflen, 
encoding, flags, type);
-        (char*)*program_code += buflen;
-        len -= buflen;
 
-        /* Padding */
-        if (buflen % sizeof(IV)) {
-            len -= buflen % sizeof(IV);
-            (char*)*program_code += buflen % sizeof(IV);
+        {
+            IV padlen = (buflen + sizeof(IV)-1) & ~(sizeof(IV)-1);
+            len -= padlen;
+            (char*)*program_code += padlen;
         }
+
         num--;
         if (len < 0 || (len > 0 && num == 0)) {
             printf("Bytecode error: string constant segment corrupted: %i, %i\n", 
(int) len, (int) num);

Reply via email to