@@ -23,6 +23,9 @@ SvUV_nomg
2323SvNV_nomg
2424SvTRUE_nomg
2525
26+ sv_vstring_get
27+ SvVSTRING
28+
2629=implementation
2730
2831#undef SvGETMAGIC
@@ -254,10 +257,36 @@ sv_unmagicext(pTHX_ SV *const sv, const int type, const MGVTBL *vtbl)
254257#endif
255258#endif
256259
260+ __UNDEFINED__ SvVSTRING(sv, len) (sv_vstring_get(sv, &(len)))
261+ __UNDEFINED__ SvVOK(sv) (FALSE)
262+
263+ #if !defined(sv_vstring_get)
264+
265+ #if { NEED sv_vstring_get }
266+
267+ const char *
268+ sv_vstring_get(pTHX_ SV *sv, STRLEN *lenp)
269+ {
270+ #ifdef SvVOK
271+ MAGIC *mg = SvVSTRING_mg(sv);
272+ if (!mg) return NULL;
273+
274+ if (lenp) *lenp = mg->mg_len;
275+ return mg->mg_ptr;
276+ #else
277+ return NULL;
278+ #endif
279+ }
280+
281+ #endif
282+
283+ #endif
284+
257285=xsinit
258286
259287#define NEED_mg_findext
260288#define NEED_sv_unmagicext
289+ #define NEED_sv_vstring_get
261290
262291#ifndef STATIC
263292#define STATIC static
@@ -580,7 +609,26 @@ magic_SvPV_nomg_nolen(sv)
580609
581610#endif
582611
583- =tests plan => 63
612+ int
613+ SvVOK(sv)
614+ SV *sv
615+
616+ SV *
617+ SvVSTRING(sv)
618+ SV *sv
619+ CODE:
620+ {
621+ const char *vstr_pv;
622+ STRLEN vstr_len;
623+ if((vstr_pv = SvVSTRING(sv, vstr_len)))
624+ RETVAL = newSVpvn(vstr_pv, vstr_len);
625+ else
626+ RETVAL = &PL_sv_undef;
627+ }
628+ OUTPUT:
629+ RETVAL
630+
631+ =tests plan => 65
584632
585633# Find proper magic
586634ok(my $obj1 = Devel::PPPort->new_with_mg());
@@ -725,6 +773,13 @@ if (ivers($]) >= ivers("5.6")) {
725773is tied($big)->{fetch}, 1;
726774is tied($big)->{store}, 0;
727775
776+ SKIP:
777+ {
778+ my $vstr = eval "v1.23.456";
779+ ok Devel::PPPort::SvVOK($vstr), '$vstr has SvVOK';
780+ is Devel::PPPort::SvVSTRING($vstr), "v1.23.456", 'SvVSTRING()';
781+ }
782+
728783package TieScalarCounter;
729784
730785sub TIESCALAR {
0 commit comments