@@ -296,6 +296,23 @@ 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 ,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
+
299
316
#ifdef HvPLACEHOLDERS
300
317
#define HAS_RESTRICTED_HASHES
301
318
#else
@@ -2583,7 +2600,8 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
2583
2600
2584
2601
} else if (flags & (SVp_POK | SVp_NOK | SVp_IOK )) {
2585
2602
#ifdef SvVOK
2586
- MAGIC * mg ;
2603
+ const char * vstr_pv ;
2604
+ STRLEN vstr_len ;
2587
2605
#endif
2588
2606
UV wlen ; /* For 64-bit machines */
2589
2607
@@ -2597,18 +2615,16 @@ static int store_scalar(pTHX_ stcxt_t *cxt, SV *sv)
2597
2615
string :
2598
2616
2599
2617
#ifdef SvVOK
2600
- if (SvMAGICAL ( sv ) && ( mg = mg_find (sv , 'V' ))) {
2618
+ if (( vstr_pv = SvVSTRING (sv , vstr_len ))) {
2601
2619
/* The macro passes this by address, not value, and a lot of
2602
2620
called code assumes that it's 32 bits without checking. */
2603
- const SSize_t len = mg -> mg_len ;
2604
2621
/* we no longer accept vstrings over I32_SIZE-1, so don't emit
2605
2622
them, also, older Storables handle them badly.
2606
2623
*/
2607
- if (len >= I32_MAX ) {
2624
+ if (vstr_len >= I32_MAX ) {
2608
2625
CROAK (("vstring too large to freeze" ));
2609
2626
}
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 );
2612
2628
}
2613
2629
#endif
2614
2630
0 commit comments