Skip to content

Commit 7e1ab21

Browse files
committed
Use new PERL_MAGIC_vstring abstraction API in Storable.xs
1 parent b91b85c commit 7e1ab21

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

dist/Storable/Storable.xs

+30-13
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,28 @@ 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,pvp,lenp) S_sv_vstring_get(aTHX_ sv,pvp,lenp)
301+
static bool S_sv_vstring_get(pTHX_ SV *sv, const char **pvp, STRLEN *lenp)
302+
{
303+
MAGIC *mg;
304+
if(!SvMAGICAL(sv) || !(mg = mg_find(sv, PERL_MAGIC_vstring)))
305+
return FALSE;
306+
307+
*pvp = mg->mg_ptr;
308+
*lenp = mg->mg_len;
309+
return TRUE;
310+
}
311+
#endif
312+
313+
#ifndef sv_vstring_set
314+
#define sv_vstring_set(sv,pv,len) \
315+
STMT_START { \
316+
sv_magic((sv), NULL, PERL_MAGIC_vstring, (pv), (len)); \
317+
SvRMAGICAL_on(sv); \
318+
} STMT_END
319+
#endif
320+
299321
#ifdef HvPLACEHOLDERS
300322
#define HAS_RESTRICTED_HASHES
301323
#else
@@ -2582,10 +2604,11 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
25822604
TRACEME(("ok (double 0x%" UVxf ", value = %" NVff ")", PTR2UV(sv), nv.nv));
25832605

25842606
} else if (flags & (SVp_POK | SVp_NOK | SVp_IOK)) {
2607+
UV wlen; /* For 64-bit machines */
25852608
#ifdef SvVOK
2586-
MAGIC *mg;
2609+
const char *vstr_pv;
2610+
STRLEN vstr_len;
25872611
#endif
2588-
UV wlen; /* For 64-bit machines */
25892612

25902613
string_readlen:
25912614
pv = SvPV(sv, len);
@@ -2597,18 +2620,16 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
25972620
string:
25982621

25992622
#ifdef SvVOK
2600-
if (SvMAGICAL(sv) && (mg = mg_find(sv, 'V'))) {
2623+
if (sv_vstring_get(sv, &vstr_pv, &vstr_len)) {
26012624
/* The macro passes this by address, not value, and a lot of
26022625
called code assumes that it's 32 bits without checking. */
2603-
const SSize_t len = mg->mg_len;
26042626
/* we no longer accept vstrings over I32_SIZE-1, so don't emit
26052627
them, also, older Storables handle them badly.
26062628
*/
2607-
if (len >= I32_MAX) {
2629+
if (vstr_len >= I32_MAX) {
26082630
CROAK(("vstring too large to freeze"));
26092631
}
2610-
STORE_PV_LEN((const char *)mg->mg_ptr,
2611-
len, SX_VSTRING, SX_LVSTRING);
2632+
STORE_PV_LEN(vstr_pv, vstr_len, SX_VSTRING, SX_LVSTRING);
26122633
}
26132634
#endif
26142635

@@ -5825,9 +5846,7 @@ static SV *retrieve_vstring(pTHX_ stcxt_t *cxt, const char *cname)
58255846
sv = retrieve(aTHX_ cxt, cname);
58265847
if (!sv)
58275848
return (SV *) 0; /* Failed */
5828-
sv_magic(sv,NULL,PERL_MAGIC_vstring,s,len);
5829-
/* 5.10.0 and earlier seem to need this */
5830-
SvRMAGICAL_on(sv);
5849+
sv_vstring_set(sv, s, len);
58315850

58325851
TRACEME(("ok (retrieve_vstring at 0x%" UVxf ")", PTR2UV(sv)));
58335852
return sv;
@@ -5868,9 +5887,7 @@ static SV *retrieve_lvstring(pTHX_ stcxt_t *cxt, const char *cname)
58685887
Safefree(s);
58695888
return (SV *) 0; /* Failed */
58705889
}
5871-
sv_magic(sv,NULL,PERL_MAGIC_vstring,s,len);
5872-
/* 5.10.0 and earlier seem to need this */
5873-
SvRMAGICAL_on(sv);
5890+
sv_vstring_set(sv, s, len);
58745891

58755892
Safefree(s);
58765893

dist/Storable/lib/Storable.pm

+1-1
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)