In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/30dc90f1923c08aae65b60f713ac12490a716e10?hp=779c45cea2b7a1f170504381f3de6b4ba0d8e7ee>

- Log -----------------------------------------------------------------
commit 30dc90f1923c08aae65b60f713ac12490a716e10
Author: Daniel Dragan <[email protected]>
Date:   Thu Jul 2 17:15:19 2015 -0400

    improve debugging of padlist API
    
    xpadl_alloc should really be pointer to a struct with a flexible array
    member, but flexible array members aren't portable enough among CCs. While
    debugging the padlist API for memory corruption (caused by an unrelated
    XS module), I saw that the pointer in the first slice of xpadl_alloc
    pointed to an AV head of gibberish but 2nd slice was fine. This was
    confusing and led me to belive the memory corruption was a bad write to
    the array in xpadl_alloc. PadlistARRAY's POD a couple pages down mentions
    that index 0 is not an AV *, but the struct comments just said
    "pointer to beginning of array of AVs " and didnt mention index 0.
    
    Fix the comments to make it clear what xpadl_alloc is. Add a union so it
    is easier to analyze a crash dump/breakpoint with a C debugger, without
    writing new code "PADNAMELIST * pnl =  PadlistNAMES(pl);" in many places
    and recompiling the interp with -O0, just to be able to inspect the
    padnamelist struct.
-----------------------------------------------------------------------

Summary of changes:
 pad.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/pad.h b/pad.h
index 31b8715..9e3caa6 100644
--- a/pad.h
+++ b/pad.h
@@ -33,7 +33,15 @@ typedef U64TYPE PADOFFSET;
 
 struct padlist {
     SSize_t    xpadl_max;      /* max index for which array has space */
-    PAD **     xpadl_alloc;    /* pointer to beginning of array of AVs */
+    union {
+       PAD **  xpadlarr_alloc; /* Pointer to beginning of array of AVs.
+                                  index 0 is a padnamelist *          */
+       struct {
+           PADNAMELIST * padnl;
+           PAD * pad_1;        /* this slice of PAD * array always alloced */
+           PAD * pad_2;        /* maybe unalloced */
+       } * xpadlarr_dbg;       /* for use with a C debugger only */
+    } xpadl_arr;
     U32                xpadl_id;       /* Semi-unique ID, shared between 
clones */
     U32                xpadl_outid;    /* ID of outer pad */
 };
@@ -293,7 +301,7 @@ Restore the old pad saved into the local variable opad by 
PAD_SAVE_LOCAL()
 =cut
 */
 
-#define PadlistARRAY(pl)       (pl)->xpadl_alloc
+#define PadlistARRAY(pl)       (pl)->xpadl_arr.xpadlarr_alloc
 #define PadlistMAX(pl)         (pl)->xpadl_max
 #define PadlistNAMES(pl)       *((PADNAMELIST **)PadlistARRAY(pl))
 #define PadlistNAMESARRAY(pl)  PadnamelistARRAY(PadlistNAMES(pl))

--
Perl5 Master Repository

Reply via email to