Skip to content

Commit 1853a2f

Browse files
committed
Use SvVSTRING() in Storable
1 parent 9b30839 commit 1853a2f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

dist/Storable/Storable.xs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@ typedef STRLEN ntag_t;
296296
#define VSTRING_CROAK() CROAK(("Cannot retrieve vstring in this perl"))
297297
#endif
298298

299+
#ifndef sv_vstring_get
300+
#define sv_vstring_get(sv,lenp) S_sv_vstring_get(aTHX_ sv,lenp)
301+
static const char *S_sv_vstring_get(pTHX_ SV *sv, STRLEN *lenp)
302+
{
303+
MAGIC *mg;
304+
if(!SvMAGICAL(sv) || !(mg = mg_find(sv, PERL_MAGIC_vstring)))
305+
return NULL;
306+
307+
*lenp = mg->mg_len;
308+
return mg->mg_ptr;
309+
}
310+
#endif
311+
312+
#ifndef SvVSTRING
313+
#define SvVSTRING(sv,len) (sv_vstring_get(sv, &(len)))
314+
#endif
315+
299316
#ifdef HvPLACEHOLDERS
300317
#define HAS_RESTRICTED_HASHES
301318
#else
@@ -2583,7 +2600,8 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
25832600

25842601
} else if (flags & (SVp_POK | SVp_NOK | SVp_IOK)) {
25852602
#ifdef SvVOK
2586-
MAGIC *mg;
2603+
const char *vstr_pv;
2604+
STRLEN vstr_len;
25872605
#endif
25882606
UV wlen; /* For 64-bit machines */
25892607

@@ -2597,18 +2615,16 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
25972615
string:
25982616

25992617
#ifdef SvVOK
2600-
if (SvMAGICAL(sv) && (mg = mg_find(sv, 'V'))) {
2618+
if ((vstr_pv = SvVSTRING(sv, vstr_len))) {
26012619
/* The macro passes this by address, not value, and a lot of
26022620
called code assumes that it's 32 bits without checking. */
2603-
const SSize_t len = mg->mg_len;
26042621
/* we no longer accept vstrings over I32_SIZE-1, so don't emit
26052622
them, also, older Storables handle them badly.
26062623
*/
2607-
if (len >= I32_MAX) {
2624+
if (vstr_len >= I32_MAX) {
26082625
CROAK(("vstring too large to freeze"));
26092626
}
2610-
STORE_PV_LEN((const char *)mg->mg_ptr,
2611-
len, SX_VSTRING, SX_LVSTRING);
2627+
STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING);
26122628
}
26132629
#endif
26142630

dist/Storable/lib/Storable.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ our @EXPORT_OK = qw(
3030
our ($canonical, $forgive_me);
3131

3232
BEGIN {
33-
our $VERSION = '3.35';
33+
our $VERSION = '3.36';
3434
}
3535

3636
our $recursion_limit;

0 commit comments

Comments
 (0)