From 134605c24764d7d96250c7a0ec3349fcde96902c Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 7 Jan 2026 14:38:59 +1100 Subject: [PATCH] B: honor the UTF-8-ness of the label in B::COP::label Fixes #24040 --- MANIFEST | 1 + ext/B/B.xs | 10 +++++++++- ext/B/t/b_uni.t | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ext/B/t/b_uni.t diff --git a/MANIFEST b/MANIFEST index 6e98563373..d20194933e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4755,6 +4755,7 @@ ext/B/Makefile.PL Compiler backend makefile writer ext/B/O.pm Compiler front-end module (-MO=...) ext/B/t/b.t See if B works ext/B/t/B/success.pm Test module for ext/B/t/o.t +ext/B/t/b_uni.t See if B works with Unicode ext/B/t/bool.t See if B works for bool ext/B/t/concise.t See whether B::Concise works ext/B/t/concise-xs.t See whether B::Concise recognizes XS functions diff --git a/ext/B/B.xs b/ext/B/B.xs index 7475a45bb2..4fc7ea8817 100644 --- a/ext/B/B.xs +++ b/ext/B/B.xs @@ -1037,7 +1037,15 @@ next(o) ret = newSVpvn_flags(cPVOPo->op_pv, strlen(cPVOPo->op_pv), SVs_TEMP); break; case 42: /* B::COP::label */ - ret = sv_2mortal(newSVpv(CopLABEL(cCOPo),0)); + { + STRLEN len; + U32 flags; + const char *pv = CopLABEL_len_flags(cCOPo, &len, &flags); + ret = sv_2mortal(newSVpvn(pv, len)); + SvUTF8_off(ret); + if (flags & SVf_UTF8) + SvUTF8_on(ret); + } break; case 43: /* B::COP::arybase */ ret = sv_2mortal(newSVuv(0)); diff --git a/ext/B/t/b_uni.t b/ext/B/t/b_uni.t new file mode 100644 index 0000000000..7278a354e6 --- /dev/null +++ b/ext/B/t/b_uni.t @@ -0,0 +1,39 @@ +#!./perl + +BEGIN { + unshift @INC, 't'; + require Config; + if (($Config::Config{'extensions'} !~ /\bB\b/) ){ + print "1..0 # Skip -- Perl configured without B module\n"; + exit 0; + } +} + +$| = 1; +use warnings; +use strict; +use utf8; +use B; +BEGIN { + eval { require threads; threads->import; } +} +use Test::More; + +sub f { + # I like pi + π:1; +} + +{ + # github 24040 + my $f = B::svref_2object(\&f); + my $op = $f->START; + while ($op && !($op->name =~ /^(db|next)state$/ && $op->label)) { + $op = $op->next; + } + $op or die "Not found"; + my $label = $op->label; + is($label, "π", "UTF8 label correctly UTF8"); +} + +done_testing();