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

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

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
September 12, 2017 00:13
Subject:
[perl #131683] Encode::ONLY_PRAGMA_WARNINGS in$PerlIO::encoding::fallback
Message ID:
rt-4.0.24-15726-1505175197-1992.131683-15-0@perl.org
On Mon, 11 Sep 2017 00:24:32 -0700, pali@cpan.org wrote:
> 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.

The warning would only be thrown if the code was called where that warning is enabled.

> > > 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.

Yes, that would no longer be necessary if the functions were written as XS.

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

Did you mean ONLY_PRAGMA_WARNINGS here?

One problem with implementing this as XS is the same problem as the goto solution - the call to utf8n_to_uvuni() would only produce warnings if the current context has utf8 warnings enabled, regardless of ONLY_PRAGMA_WARNINGS.

> > > 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?

There's no goto involved, the XS simply doesn't have a new context to control the warnings, so the caller's warnings flags are what matter.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=131683

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