diff options
author | Yves Orton <demerphq@gmail.com> | 2022-12-18 18:42:34 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-12-22 15:41:12 +0100 |
commit | 332af2278b8db03a0735d24a17bbaae7f7e20112 (patch) | |
tree | 18170096c3ea3401104a2cacb76ddcad52b11151 /ext/XS-APItest | |
parent | 81620fbedd5f5cb87f240d7809dc669cd60d0139 (diff) | |
download | perl-332af2278b8db03a0735d24a17bbaae7f7e20112.tar.gz |
sv.c - add support for HvNAMEf and HvNAMEf_QUOTEDPREFIX formats
They are similar to SVf and SVf_QUOTEDPREFIX but take an HV * argument
and use HvNAME() and related macros to extract the string. This is
helpful as it makes constructing error messages from a stash (HV *)
easier. It is the callers responsibility to ensure that the HV is
actually a stash.
Diffstat (limited to 'ext/XS-APItest')
-rw-r--r-- | ext/XS-APItest/APItest.pm | 2 | ||||
-rw-r--r-- | ext/XS-APItest/APItest.xs | 21 | ||||
-rw-r--r-- | ext/XS-APItest/t/svcatpvf.t | 12 |
3 files changed, 33 insertions, 2 deletions
diff --git a/ext/XS-APItest/APItest.pm b/ext/XS-APItest/APItest.pm index 821ca6530a..fb14f78dd5 100644 --- a/ext/XS-APItest/APItest.pm +++ b/ext/XS-APItest/APItest.pm @@ -4,7 +4,7 @@ use strict; use warnings; use Carp; -our $VERSION = '1.29'; +our $VERSION = '1.30'; require XSLoader; diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs index 54b9094fb9..00fccb3654 100644 --- a/ext/XS-APItest/APItest.xs +++ b/ext/XS-APItest/APItest.xs @@ -4676,6 +4676,27 @@ test_MAX_types() OUTPUT: RETVAL +SV * +test_HvNAMEf(sv) + SV *sv + CODE: + if (!sv_isobject(sv)) XSRETURN_UNDEF; + HV *pkg = SvSTASH(SvRV(sv)); + RETVAL = newSVpvf("class='%" HvNAMEf "'", pkg); + OUTPUT: + RETVAL + +SV * +test_HvNAMEf_QUOTEDPREFIX(sv) + SV *sv + CODE: + if (!sv_isobject(sv)) XSRETURN_UNDEF; + HV *pkg = SvSTASH(SvRV(sv)); + RETVAL = newSVpvf("class=%" HvNAMEf_QUOTEDPREFIX, pkg); + OUTPUT: + RETVAL + + bool sv_numeq(SV *sv1, SV *sv2) CODE: diff --git a/ext/XS-APItest/t/svcatpvf.t b/ext/XS-APItest/t/svcatpvf.t index 865020da30..b6cce12415 100644 --- a/ext/XS-APItest/t/svcatpvf.t +++ b/ext/XS-APItest/t/svcatpvf.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 4; +use Test::More tests => 6; use XS::APItest; @@ -19,3 +19,13 @@ for my $case (@cases) { like($exn, qr/\b\QCannot yet reorder sv_vcatpvfn() arguments from va_list\E\b/, "explicit $what index forbidden in va_list arguments"); } + +# these actually test newSVpvf() but it is the same underlying logic. +is(test_HvNAMEf(bless {}, "Whatever::You::Like"), + "class='Whatever::You::Like'"); +is(test_HvNAMEf_QUOTEDPREFIX(bless {}, "x" x 1000), + 'class="xxxxxxxxxxxxxxxxxxxxxxxxxx'. + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'. + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..."xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'. + 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'. + 'xxxxxxxxxxxxxxxxxxxxx"'); |