This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make PADOFFSET be SSizet_t
authorDavid Mitchell <davem@iabyn.com>
Mon, 26 Sep 2016 14:22:25 +0000 (15:22 +0100)
committerDavid Mitchell <davem@iabyn.com>
Mon, 26 Sep 2016 14:48:48 +0000 (15:48 +0100)
Currently it's defined as U32 or U64 depending on whether pointers are
32 bit or 64-bit, which is just a long-winded way of doing

    typedef Size_t PADOFFSET

Change it to

    typedef SSize_t PADOFFSET

Making it signed makes it easier to handle comparisons against PADOFFSET
values that can be -1, such as PL_comppad_name_floor (which will be fixed
in the next commit).

op.c
pad.h
pp_hot.c

diff --git a/op.c b/op.c
index 3e44be8..c2f5406 100644 (file)
--- a/op.c
+++ b/op.c
@@ -13907,7 +13907,7 @@ Perl_rpeep(pTHX_ OP *o)
                 if (   intro
                     && (8*sizeof(base) >
                         8*sizeof(UV)-OPpPADRANGE_COUNTSHIFT-SAVE_TIGHT_SHIFT
-                        ? base
+                        ? (Size_t)base
                         : (UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT))
                         ) >
                         (UV_MAX >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT))
diff --git a/pad.h b/pad.h
index 7ed1033..56d88ab 100644 (file)
--- a/pad.h
+++ b/pad.h
 
 /* offsets within a pad */
 
-#if PTRSIZE == 4
-typedef U32TYPE PADOFFSET;
-#else
-#   if PTRSIZE == 8
-typedef U64TYPE PADOFFSET;
-#   endif
-#endif
+typedef SSize_t PADOFFSET; /* signed so that -1 is a valid value */
 #define NOT_IN_PAD ((PADOFFSET) -1)
 
 /* B.xs expects the first members of these two structs to line up
index 9da9ab0..35cc4da 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -382,7 +382,8 @@ PP(pp_padrange)
                     | (count << SAVE_TIGHT_SHIFT)
                     | SAVEt_CLEARPADRANGE);
         STATIC_ASSERT_STMT(OPpPADRANGE_COUNTMASK + 1 == (1 << OPpPADRANGE_COUNTSHIFT));
-        assert((payload >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT)) == base);
+        assert((payload >> (OPpPADRANGE_COUNTSHIFT+SAVE_TIGHT_SHIFT))
+                == (Size_t)base);
         {
             dSS_ADD;
             SS_ADD_UV(payload);