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

The standard Perl uc just leaves it there when uppercasing.

Any currently supported perl should uppercase it correctly:

$ cat uct.pl 
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;

my $string = 'straße';
my $ucstring = uc $string;
print "Uppercase $string is $ucstring\n";
$ perl uct.pl 
Uppercase straße is STRASSE
$

Are you running an old version?


🦛

  • Comment on Re^3: Memory Leak with XS but not pure C

Replies are listed 'Best First'.
Re^4: Memory Leak with XS but not pure C
by ikegami (Patriarch) on Mar 29, 2025 at 17:15 UTC

    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 }

      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.