From 824d745add11a85b344c1b19102120b52563f446 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 11 Aug 2013 14:46:55 -0700 Subject: [PATCH] Make Storable support read-only COWs 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). --- Storable.xs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Storable.xs b/Storable.xs index b89ef6f85de0..439009a789bd 100644 --- a/Storable.xs +++ b/Storable.xs @@ -81,6 +81,12 @@ # 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) {