@@ -296,6 +296,28 @@ typedef STRLEN ntag_t;
296
296
#define VSTRING_CROAK () CROAK(("Cannot retrieve vstring in this perl"))
297
297
#endif
298
298
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
+
299
321
#ifdef HvPLACEHOLDERS
300
322
#define HAS_RESTRICTED_HASHES
301
323
#else
@@ -2582,10 +2604,11 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
2582
2604
TRACEME (("ok (double 0x%" UVxf ", value = %" NVff ")" , PTR2UV (sv ), nv .nv ));
2583
2605
2584
2606
} else if (flags & (SVp_POK | SVp_NOK | SVp_IOK )) {
2607
+ UV wlen ; /* For 64-bit machines */
2585
2608
#ifdef SvVOK
2586
- MAGIC * mg ;
2609
+ const char * vstr_pv ;
2610
+ STRLEN vstr_len ;
2587
2611
#endif
2588
- UV wlen ; /* For 64-bit machines */
2589
2612
2590
2613
string_readlen :
2591
2614
pv = SvPV (sv , len );
@@ -2597,18 +2620,16 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
2597
2620
string :
2598
2621
2599
2622
#ifdef SvVOK
2600
- if (SvMAGICAL (sv ) && ( mg = mg_find ( sv , 'V' ) )) {
2623
+ if (sv_vstring_get (sv , & vstr_pv , & vstr_len )) {
2601
2624
/* The macro passes this by address, not value, and a lot of
2602
2625
called code assumes that it's 32 bits without checking. */
2603
- const SSize_t len = mg -> mg_len ;
2604
2626
/* we no longer accept vstrings over I32_SIZE-1, so don't emit
2605
2627
them, also, older Storables handle them badly.
2606
2628
*/
2607
- if (len >= I32_MAX ) {
2629
+ if (vstr_len >= I32_MAX ) {
2608
2630
CROAK (("vstring too large to freeze" ));
2609
2631
}
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 );
2612
2633
}
2613
2634
#endif
2614
2635
@@ -5825,9 +5846,7 @@ static SV *retrieve_vstring(pTHX_ stcxt_t *cxt, const char *cname)
5825
5846
sv = retrieve (aTHX_ cxt , cname );
5826
5847
if (!sv )
5827
5848
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 );
5831
5850
5832
5851
TRACEME (("ok (retrieve_vstring at 0x%" UVxf ")" , PTR2UV (sv )));
5833
5852
return sv ;
@@ -5868,9 +5887,7 @@ static SV *retrieve_lvstring(pTHX_ stcxt_t *cxt, const char *cname)
5868
5887
Safefree (s );
5869
5888
return (SV * ) 0 ; /* Failed */
5870
5889
}
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 );
5874
5891
5875
5892
Safefree (s );
5876
5893
0 commit comments