in reply to Re^3: Memory Leak with XS but not pure C
in thread Memory Leak with XS but not pure C

uc suffers from The Unicode Bug when the unicode_strings feature isn't in enabled.

It works correctly (giving SS for ß) when the string the unicode_strings feature is enabled.

It works correctly (giving SS for ß) when the string is stored in the UTF8=1 format.

It works incorrectly (ß unchanged) otherwise.

use open ":std", ":locale"; use feature qw( say ); my $ss = "\xDF"; utf8::upgrade( my $ss_u = $ss ); utf8::downgrade( my $ss_d = $ss ); { no feature qw( unicode_strings ); say uc( $ss_d ); # ß say uc( $ss_u ); # SS } { use feature qw( unicode_strings ); say uc( $ss_d ); # SS say uc( $ss_u ); # SS }

Replies are listed 'Best First'.
Re^5: Memory Leak with XS but not pure C
by FrankFooty (Novice) on Mar 31, 2025 at 10:21 UTC

    Thanks very much Ikegami. I hadn't heard of that feature

    How is it possible to get the same behaviour within an XS function

      If you're asking how to convert to uppercase from XS, you'd start with an upgraded string, then call toUPPER_uvchr or toUPPER_utf8 repeatedly. (Or call a Perl function that uses uc.)

      There is nothing that can affect the behaviour of Perl's uc operator in XS code. But you can't use Perl operators in C/XS code anyway.