Change 30056 by [EMAIL PROTECTED] on 2007/01/29 11:15:51

        Integrate:
        [ 27795]
        (Hopefully) fix coredumps in ByteLoader, which were a side effect of
        fixing a bug in B, and non-robust autogenerated code. When
        autogenerating initialiser statements for an array, it's a bad plan to
        have the size of that array hard coded.
        
        [ 27826]
        Coverity was getting upset about an assignment from a function
        returning int to a U8 variable. Curiously it was only getting upset
        about the first of many.
        However, we are doing NO ERROR CHECKING on whether we read in the
        requested number of bytes of bytecode. All except BGET_op_tr_array
        will now croak on a short read.
        
        [ 27874]
        Oops. Change 27826 had an error in the definition of BGET_PADOFFSET().
        
        [ 28638]
        Silence the VC7 compiler warning in the following smoke:
        http://www.nntp.perl.org/group/perl.daily-build.reports/39824
        
        [ 28667]
        Try to reinstate the fix of change #28638 by patching bytecode.pl and
        not the file it generates
        
        [ 28668]
        Provide a BGET_svtype, required by #28667
        
        [ 28739]
        Subject: [PATCH] bytecode.t failures in Tru64: svtype (enum) is int, 
not long
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Date: Sat, 19 Aug 2006 14:34:53 +0300 (EEST)
        Message-Id: <[EMAIL PROTECTED]>
        
        plus fix 28739 to use U32 rather than I32 to avoid an error on this
        ILP 32 bit system. (Checked also with -Duse64bitint, but we await the
        verdict on an LP64 system)

Affected files ...

... //depot/maint-5.8/perl/bytecode.pl#21 integrate
... //depot/maint-5.8/perl/ext/B/B/Asmdata.pm#12 integrate
... //depot/maint-5.8/perl/ext/B/B/Assembler.pm#9 edit
... //depot/maint-5.8/perl/ext/ByteLoader/bytecode.h#13 integrate
... //depot/maint-5.8/perl/ext/ByteLoader/byterun.c#15 integrate

Differences ...

==== //depot/maint-5.8/perl/bytecode.pl#21 (text) ====
Index: perl/bytecode.pl
--- perl/bytecode.pl#20~30038~  2007-01-27 10:13:24.000000000 -0800
+++ perl/bytecode.pl    2007-01-29 03:15:51.000000000 -0800
@@ -89,7 +89,10 @@
     printf BYTERUN_C "    sizeof(%s),\n", $optype[$i], $i;
 }
 printf BYTERUN_C "    sizeof(%s)\n", $optype[$i], $i;
-print BYTERUN_C <<'EOT';
+
+my $size = @specialsv;
+
+print BYTERUN_C <<"EOT";
 };
 
 void *
@@ -108,7 +111,7 @@
 {
     register int insn;
     U32 ix;
-    SV *specialsv_list[6];
+    SV *specialsv_list[$size];
 
     BYTECODE_HEADER_CHECK;     /* croak if incorrect platform */
     Newx(bstate->bs_obj_list, 32, void*); /* set op objlist */
@@ -364,7 +367,7 @@
 ldspecsv       bstate->bs_sv                           U8              x
 ldspecsvx      bstate->bs_sv                           U8              x
 newsv          bstate->bs_sv                           svtype          x
-newsvx         bstate->bs_sv                           U32             x
+newsvx         bstate->bs_sv                           svtype          x
 newop          PL_op                                   U8              x
 newopx         PL_op                                   U16             x
 newopn         PL_op                                   U8              x

==== //depot/maint-5.8/perl/ext/B/B/Asmdata.pm#12 (text+w) ====
Index: perl/ext/B/B/Asmdata.pm
--- perl/ext/B/B/Asmdata.pm#11~30038~   2007-01-27 10:13:24.000000000 -0800
+++ perl/ext/B/B/Asmdata.pm     2007-01-29 03:15:51.000000000 -0800
@@ -35,7 +35,7 @@
 $insn_data{ldspecsv} = [6, \&PUT_U8, "GET_U8"];
 $insn_data{ldspecsvx} = [7, \&PUT_U8, "GET_U8"];
 $insn_data{newsv} = [8, \&PUT_svtype, "GET_svtype"];
-$insn_data{newsvx} = [9, \&PUT_U32, "GET_U32"];
+$insn_data{newsvx} = [9, \&PUT_svtype, "GET_svtype"];
 $insn_data{newop} = [11, \&PUT_U8, "GET_U8"];
 $insn_data{newopx} = [12, \&PUT_U16, "GET_U16"];
 $insn_data{newopn} = [13, \&PUT_U8, "GET_U8"];

==== //depot/maint-5.8/perl/ext/B/B/Assembler.pm#9 (text) ====
Index: perl/ext/B/B/Assembler.pm
--- perl/ext/B/B/Assembler.pm#8~30038~  2007-01-27 10:13:24.000000000 -0800
+++ perl/ext/B/B/Assembler.pm   2007-01-29 03:15:51.000000000 -0800
@@ -150,8 +150,8 @@
     $Config{longsize} == 8 ? &B::Asmdata::PUT_IV64 : &B::Asmdata::PUT_U32;
 }
 
-sub B::Asmdata::PUT_svtype {
-    $Config{longsize} == 8 ? &B::Asmdata::PUT_IV64 : &B::Asmdata::PUT_U32;
+sub B::Asmdata::PUT_svtype { # svtype is an enum, so an int.
+    $Config{intsize} == 4 ? &B::Asmdata::PUT_U32 : &B::Asmdata::PUT_IV64;
 }
 
 my %unesc = (n => "\n", r => "\r", t => "\t", a => "\a",

==== //depot/maint-5.8/perl/ext/ByteLoader/bytecode.h#13 (text) ====
Index: perl/ext/ByteLoader/bytecode.h
--- perl/ext/ByteLoader/bytecode.h#12~30038~    2007-01-27 10:13:24.000000000 
-0800
+++ perl/ext/ByteLoader/bytecode.h      2007-01-29 03:15:51.000000000 -0800
@@ -13,20 +13,30 @@
 
 /* all this should be made endianness-agnostic */
 
-#define BGET_U8(arg)   arg = BGET_FGETC()
-#define BGET_U16(arg)  \
-       BGET_FREAD(&arg, sizeof(U16), 1)
-#define BGET_U32(arg)  \
-       BGET_FREAD(&arg, sizeof(U32), 1)
-#define BGET_UV(arg)   \
-       BGET_FREAD(&arg, sizeof(UV), 1)
-#define BGET_PADOFFSET(arg)    \
-       BGET_FREAD(&arg, sizeof(PADOFFSET), 1)
-#define BGET_long(arg)         \
-       BGET_FREAD(&arg, sizeof(long), 1)
+#define BGET_U8(arg) STMT_START {                                      \
+       const int _arg = BGET_FGETC();                                  \
+       if (_arg < 0) {                                                 \
+           Perl_croak(aTHX_                                            \
+                      "EOF or error while trying to read 1 byte for U8"); \
+       }                                                               \
+       arg = (U8) _arg;                                                \
+    } STMT_END
 
-#define BGET_I32(arg)  BGET_U32(arg)
-#define BGET_IV(arg)   BGET_UV(arg)
+#define BGET_U16(arg)          BGET_OR_CROAK(arg, U16)
+#define BGET_I32(arg)          BGET_OR_CROAK(arg, U32)
+#define BGET_U32(arg)          BGET_OR_CROAK(arg, U32)
+#define BGET_IV(arg)           BGET_OR_CROAK(arg, IV)
+#define BGET_PADOFFSET(arg)    BGET_OR_CROAK(arg, PADOFFSET)
+#define BGET_long(arg)         BGET_OR_CROAK(arg, long)
+
+#define BGET_OR_CROAK(arg, type) STMT_START {                          \
+       if (BGET_FREAD(&arg, sizeof(type), 1) < 1) {                    \
+           Perl_croak(aTHX_                                            \
+                      "EOF or error while trying to read %d bytes for %s", \
+                      sizeof(type), STRINGIFY(type));                  \
+       }                                                               \
+    } STMT_END
+#define BGET_svtype(arg)       BGET_OR_CROAK(arg, svtype)
 
 #define BGET_PV(arg)   STMT_START {                                    \
        BGET_U32(arg);                                                  \
@@ -91,7 +101,11 @@
        arg = arg ? savepv(arg) : arg;                  \
     } STMT_END
 
-#define BSET_ldspecsv(sv, arg) sv = specialsv_list[arg]
+#define BSET_ldspecsv(sv, arg) STMT_START {                              \
+       assert(arg < sizeof(specialsv_list) / sizeof(specialsv_list[0])); \
+       sv = specialsv_list[arg];                                         \
+    } STMT_END
+
 #define BSET_ldspecsvx(sv, arg) STMT_START {   \
        BSET_ldspecsv(sv, arg);                 \
        BSET_OBJ_STOREX(sv);                    \

==== //depot/maint-5.8/perl/ext/ByteLoader/byterun.c#15 (text+w) ====
Index: perl/ext/ByteLoader/byterun.c
--- perl/ext/ByteLoader/byterun.c#14~30038~     2007-01-27 10:13:24.000000000 
-0800
+++ perl/ext/ByteLoader/byterun.c       2007-01-29 03:15:51.000000000 -0800
@@ -50,7 +50,7 @@
 {
     register int insn;
     U32 ix;
-    SV *specialsv_list[6];
+    SV *specialsv_list[7];
 
     BYTECODE_HEADER_CHECK;     /* croak if incorrect platform */
     Newx(bstate->bs_obj_list, 32, void*); /* set op objlist */
@@ -141,9 +141,9 @@
            }
          case INSN_NEWSVX:             /* 9 */
            {
-               U32 arg;
-               BGET_U32(arg);
-               BSET_newsvx(bstate->bs_sv, arg);
+               svtype arg;
+               BGET_svtype(arg);
+               BSET_newsvx(bstate->bs_sv, (svtype)arg);
                break;
            }
          case INSN_NEWOP:              /* 11 */
End of Patch.

Reply via email to