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

Re: Perl 7: Fix string leaks?

Thread Previous | Thread Next
From:
Felipe Gasper
Date:
March 31, 2021 03:02
Subject:
Re: Perl 7: Fix string leaks?
Message ID:
A8DDDC0B-BE99-467B-90FA-5AA38DB82C4B@felipegasper.com


> On Mar 30, 2021, at 4:48 PM, Salvador Fandiño <sfandino@gmail.com> wrote:
> 
> On 30/3/21 20:53, Felipe Gasper wrote:
>>> On Mar 30, 2021, at 12:16 PM, Salvador Fandiño <sfandino@gmail.com> 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;

-F
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About