This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make Storable support read-only COWs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 11 Aug 2013 21:46:55 +0000 (14:46 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 12 Aug 2013 08:53:26 +0000 (01:53 -0700)
Unfortunately, the historical double meaning of SvREADONLY makes
it hard to do the correct thing under all perl versions.

If this proves too problematic for other XS modules, we might need
to forbid read-only COWs, which would be unfortunate, since they
speed things up.

However, a CPAN search reveals nothing outside core for
READONLY.*?(IsCOW|FAKE).

dist/Storable/Storable.xs

index b89ef6f..439009a 100644 (file)
 #  define HvTOTALKEYS(hv)      HvKEYS(hv)
 #endif
 
+#ifdef SVf_IsCOW
+#  define SvTRULYREADONLY(sv)  SvREADONLY(sv)
+#else
+#  define SvTRULYREADONLY(sv)  (SvREADONLY(sv) && !SvIsCOW(sv))
+#endif
+
 #ifdef DEBUGME
 
 #ifndef DASSERT
@@ -2452,7 +2458,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
                         /* Implementation of restricted hashes isn't nicely
                            abstracted:  */
                        if ((hash_flags & SHV_RESTRICTED)
-                        && SvREADONLY(val) && !SvIsCOW(val)) {
+                        && SvTRULYREADONLY(val)) {
                                flags |= SHV_K_LOCKED;
                        }
 
@@ -2544,7 +2550,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv)
                            abstracted:  */
                         flags
                             = (((hash_flags & SHV_RESTRICTED)
-                                && SvREADONLY(val) && !SvIsCOW(val))
+                                && SvTRULYREADONLY(val))
                                              ? SHV_K_LOCKED : 0);
 
                         if (val == &PL_sv_placeholder) {