Skip to content

Commit

Permalink
Make Storable support read-only COWs
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Father Chrysostomos committed Aug 12, 2013
1 parent 4e4d870 commit 824d745
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Storable.xs
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 824d745

Please sign in to comment.