develooper Front page | perl.perl5.porters | Postings from September 2017

Re: [perl #131683] Encode::ONLY_PRAGMA_WARNINGS in$PerlIO::encoding::fallback

Thread Next
From:
pali
Date:
September 11, 2017 07:24
Subject:
Re: [perl #131683] Encode::ONLY_PRAGMA_WARNINGS in$PerlIO::encoding::fallback
Message ID:
20170911072412.GA1238@pali
On Sunday 10 September 2017 17:01:40 Tony Cook via RT wrote:
> The "My code" I was referring to is the one-liner above.  I meant it would confuse the user whose code doesn't include a goto (just a call to encode/decode()).

So, you are referring to that unexpected warning with "goto" in its
message, right? Therefore I asked if it is possible to reimplement that
function in XS without possibility that such warning would be thrown.

> > I used goto in Encode::encode/decode dispatcher functions, so warnings
> > from modules would be correctly propagated to caller of the
> > Encode::encode/decode function.
> 
> I guessed that, but the existing encode/decode functions already has code that handles that:
> 
>     ...
>     my $octets;
>     if ( ref($enc) eq 'Encode::Unicode' ) {
>         my $warn = '';
>         {
>             local $SIG{__WARN__} = sub { $warn = shift };
>             $octets = $enc->encode( $string, $check );
>         }
>         warnings::warnif('utf8', $warn) if length $warn;
>     }
>     ...

Yes, but that code is wrong for more reasons.

E.g. https://rt.cpan.org/Public/Bug/Display.html?id=120505
Also because it catch only 'utf8' warnings and also because it check
only UTF-16/UTF-32 encodings, not UTF-8 or some Latin-X.

My approach try to use goto to run encode function in current context,
so warning/error messages would be properly propagated to caller.

And introduce Encode::ENCODE_WARN_ON_ERR, so above bug 120505 can be
fixed too.

> > It is possible to reimplement Encode::encode/decode function in C/XS
> > in
> > same way how it is implemented in my patch, but without that warning
> > from goto?
> 
> The most complex part would probably be the call to find_encoding(), the rest I think is relatively simple.

Can you show me simple example how to write that "goto" part?

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