summaryrefslogtreecommitdiff
path: root/pad.h
diff options
context:
space:
mode:
authorDaniel Dragan <bulk88@hotmail.com>2015-07-02 17:15:19 -0400
committerTony Cook <tony@develop-help.com>2015-07-09 11:04:48 +1000
commit30dc90f1923c08aae65b60f713ac12490a716e10 (patch)
treedcbebe87a5c700ff1ce7c28e22a7491375dd02c1 /pad.h
parent779c45cea2b7a1f170504381f3de6b4ba0d8e7ee (diff)
downloadperl-30dc90f1923c08aae65b60f713ac12490a716e10.tar.gz
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.
Diffstat (limited to 'pad.h')
-rw-r--r--pad.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/pad.h b/pad.h
index 31b87157d4..9e3caa65d0 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))