Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions dist/Storable/Storable.xs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,6 +2960,19 @@ static int store_hash(pTHX_ stcxt_t *cxt, SV *xsv)
keyval = SvPV(key, keylen_tmp);
keylen = keylen_tmp;
if (SvUTF8(key)) {

#ifdef utf8_to_bytes_overwrite

/* If we are able to downgrade here; that means that we have a
* key which only had chars 0-255, but was utf8 encoded. */
if (utf8_to_bytes_overwrite( (U8**) &keyval, &keylen_tmp)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit worried about this, since this modifies the PV belonging to a SV, but the SV is a copy of the key from the hash on this branch, so it's safe.

It does make a UTF-8 SV with a validly encoded PV into a UTF-8 SV with a probably invalidly encoded PV, but that SV is almost immediately discarded.

Will the new utf8_to_bytes_* functions be added to ppport.h?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khwilliamson could you respond to @tonycoz's concerns above? Thx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they will

keylen = keylen_tmp;
flags |= SHV_K_WASUTF8;
}
else {
flags |= SHV_K_UTF8;
}
#else
const char *keysave = keyval;
bool is_utf8 = TRUE;

Expand All @@ -2982,6 +2995,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, SV *xsv)
to assign back to keylen. */
flags |= SHV_K_UTF8;
}
#endif
}

if (flagged_hash) {
Expand All @@ -3000,8 +3014,12 @@ static int store_hash(pTHX_ stcxt_t *cxt, SV *xsv)
WLEN(keylen);
if (keylen)
WRITE(keyval, keylen);

#ifndef utf8_to_bytes_overwrite

if (flags & SHV_K_WASUTF8)
Safefree (keyval);
#endif
}

/*
Expand Down
2 changes: 1 addition & 1 deletion dist/Storable/lib/Storable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ our @EXPORT_OK = qw(
our ($canonical, $forgive_me);

BEGIN {
our $VERSION = '3.38';
our $VERSION = '3.39';
}

our $recursion_limit;
Expand Down
Loading