From 4ea34344d710c5231aae2bde41acf5fda78eb175 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). --- dist/Storable/Storable.xs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs index b89ef6f..439009a 100644 --- a/dist/Storable/Storable.xs +++ b/dist/Storable/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) { -- 2.7.4