develooper Front page | perl.perl5.porters | Postings from March 2021

Re: Perl 7: Fix string leaks?

Thread Previous | Thread Next
Felipe Gasper
March 31, 2021 03:02
Re: Perl 7: Fix string leaks?
Message ID:

> On Mar 30, 2021, at 4:48 PM, Salvador Fandiño <> wrote:
> On 30/3/21 20:53, Felipe Gasper wrote:
>>> On Mar 30, 2021, at 12:16 PM, Salvador Fandiño <> wrote:
>>> Encoding/decoding should be done at the boundaries (syscall, XS, etc.) using sensible defaults and/or allowing the user to set them (as in PerlIO). That would IMO fix most of the problems.
>> “Encoding at the boundaries” is essentially what Sys::Binmode achieves for POSIX OSes, FWIW.
> Yeah, that part is right! what is wrong is that it uses the wrong encoding (latin1) most of the time!!!
> Actually, I think it would be pretty easy to modify your module so that it gets the encoding from the environment or alternatively taking it as a parameter at least on UNIX and alikes:
>  use Sys::Binmode "latin5";
> Windows is a different story...

I’d be curious to see an implementation of what you have in mind.

“Latin-1” is kind of a funny term; as Perl uses it internally it’s not really an “encoding” so much as “just bytes”. So I disagree (of course) that Sys::Binmode uses “the wrong encoding” because the “encoding” that it gives you is whatever bytes the string stores. It’s the same “encoding” that SvPVbyte provides for XSUBs.

If someone wants to pass a Latin-5 path to a POSIX OS, they’d do that the same way as UTF-8:

my $path_bytes = Encode::Simple::encode('Latin-5', $path_text);
mkdir $path_bytes, 0755;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About