This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Storable: add SEEN0 macro
authorDavid Mitchell <davem@iabyn.com>
Thu, 21 Nov 2013 11:15:43 +0000 (11:15 +0000)
committerDavid Mitchell <davem@iabyn.com>
Thu, 21 Nov 2013 17:12:42 +0000 (17:12 +0000)
to shut up a compiler warning.

The SEEN(y,stash,i) macro expands to something like

    ...;
    if (stash)
       foo_NN(stash);

where foo_NN is a function that expects a non-null arg.

SEEN() is sometimes called as SEEN(sv,0,0) which of course expands to

    if (0)
       foo_NN(0);

which under gcc at least, emits the 'non-null' warning before the entire
block of code is optimised away.

So add a SEEN0() macro which handles the stash=0 case.

dist/Storable/Storable.pm
dist/Storable/Storable.xs

index fbe50c2..9cb1a85 100644 (file)
@@ -22,7 +22,7 @@ package Storable; @ISA = qw(Exporter);
 
 use vars qw($canonical $forgive_me $VERSION);
 
-$VERSION = '2.47';
+$VERSION = '2.48';
 
 BEGIN {
     if (eval { local $SIG{__DIE__}; require Log::Agent; 1 }) {
index c895170..439635b 100644 (file)
@@ -1018,7 +1018,7 @@ static const char byteorderstr_56[] = {BYTEORDER_BYTES_56, 0};
   } STMT_END
 
 /*
- * This macro is used at retrieve time, to remember where object 'y', bearing a
+ * SEEN() is used at retrieve time, to remember where object 'y', bearing a
  * given tag 'tagnum', has been retrieved. Next time we see an SX_OBJECT marker,
  * we'll therefore know where it has been retrieved and will be able to
  * share the same reference, as in the original stored memory image.
@@ -1036,18 +1036,25 @@ static const char byteorderstr_56[] = {BYTEORDER_BYTES_56, 0};
  * will bless the object.
  *
  * i should be true iff sv is immortal (ie PL_sv_yes, PL_sv_no or PL_sv_undef)
+ *
+ * SEEN0() is a short-cut where stash is always NULL.
  */
-#define SEEN(y,stash,i)                                                \
-  STMT_START {                                                         \
-       if (!y)                                                                 \
+#define SEEN0(y,i)                                                     \
+    STMT_START {                                                       \
+       if (!y)                                                         \
                return (SV *) 0;                                        \
        if (av_store(cxt->aseen, cxt->tagnum++, i ? (SV*)(y) : SvREFCNT_inc(y)) == 0) \
                return (SV *) 0;                                        \
-       TRACEME(("aseen(#%d) = 0x%"UVxf" (refcnt=%d)", cxt->tagnum-1, \
-                PTR2UV(y), SvREFCNT(y)-1));            \
-       if (stash)                                                              \
+       TRACEME(("aseen(#%d) = 0x%"UVxf" (refcnt=%d)", cxt->tagnum-1,   \
+                PTR2UV(y), SvREFCNT(y)-1));                            \
+    } STMT_END
+
+#define SEEN(y,stash,i)                                                        \
+    STMT_START {                                                       \
+        SEEN0(y,i);                                                    \
+       if (stash)                                                      \
                BLESS((SV *) (y), (HV *)(stash));                       \
-  } STMT_END
+    } STMT_END
 
 /*
  * Bless 's' in 'p', via a temporary reference, required by sv_bless().
@@ -4141,7 +4148,7 @@ static SV *retrieve_hook(pTHX_ stcxt_t *cxt, const char *cname)
        default:
                return retrieve_other(aTHX_ cxt, 0);            /* Let it croak */
        }
-       SEEN(sv, 0, 0);                                                 /* Don't bless yet */
+       SEEN0(sv, 0);                                                   /* Don't bless yet */
 
        /*
         * Whilst flags tell us to recurse, do so.
@@ -4338,7 +4345,7 @@ static SV *retrieve_hook(pTHX_ stcxt_t *cxt, const char *cname)
                SvREFCNT_dec(sv);
                /* we need to free RV but preserve value that RV point to */
                sv = SvRV(attached);
-               SEEN(sv, 0, 0);
+               SEEN0(sv, 0);
                SvRV_set(attached, NULL);
                SvREFCNT_dec(attached);
                if (!(flags & SHF_IDX_CLASSNAME) && classname != buf)
@@ -5713,7 +5720,7 @@ static SV *old_retrieve_array(pTHX_ stcxt_t *cxt, const char *cname)
        RLEN(len);
        TRACEME(("size = %d", len));
        av = newAV();
-       SEEN(av, 0, 0);                         /* Will return if array not allocated nicely */
+       SEEN0(av, 0);                           /* Will return if array not allocated nicely */
        if (len)
                av_extend(av, len);
        else
@@ -5776,7 +5783,7 @@ static SV *old_retrieve_hash(pTHX_ stcxt_t *cxt, const char *cname)
        RLEN(len);
        TRACEME(("size = %d", len));
        hv = newHV();
-       SEEN(hv, 0, 0);                 /* Will return if table not allocated properly */
+       SEEN0(hv, 0);                   /* Will return if table not allocated properly */
        if (len == 0)
                return (SV *) hv;       /* No data follow if table empty */
        hv_ksplit(hv, len + 1);         /* pre-extend hash to save multiple splits */