Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Weird STDERR/SIGDIE/Encodings issue

by vsespb (Chaplain)
on Mar 28, 2013 at 23:10 UTC ( #1026054=note: print w/replies, xml ) Need Help??

in reply to Re: Weird STDERR/SIGDIE/Encodings issue
in thread Weird STDERR/SIGDIE/Encodings issue

Almost any change to that code fixes it. Yes, including decode.

I more interesting in finding root of problem, as user have crashes in a bit different circumstances.

Also in my program I will be unable to just "decode" things, as it prints stacktrace, including function argument and sometimes I have binary data (not character string) or even filenames in binary format (not UTF-8, because FreeBSD filesystem sometimes use non-UTF-8 filenames)

I think die inside die handler cannot cause a recursion:

 The __DIE__ handler is explicitly disabled during the call, so that you can die from a __DIE__ handler

also such recursion would produce stackoverflow fast.

Currently it looks to me that it's just a bug in Encode XS code, and I can workaround it by _escaping_ any non-ASCII octets (both binary data and wide characters)

Replies are listed 'Best First'.
Re^3: Weird STDERR/SIGDIE/Encodings issue
by McA (Priest) on Mar 28, 2013 at 23:51 UTC

    Concerning the recursion I speculated about the following: You're right that the sig handler is disabled, but the standard die functionality is done anyway. So the error string is printed via STDERR on which you enabled the encoding IO layer with binmode. The following code reproduces the error:

    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Encode; $SIG{__DIE__} = sub { if (defined $^S && $^S == 0) { for my $s (0..$#_) { dcs($_[$s]); }; } }; sub dcs { print Dumper(\@_); my ($p1, $p2) = @_; my @caller = caller(0); print Dumper(\@caller); print STDERR $caller[1]; print STDERR "me: " . $p1; } sub mysub { die; } binmode STDERR, ":encoding(koi8-r)"; binmode STDOUT, ":encoding(koi8-r)"; mysub();

    As soon as you change the line

    print STDERR $caller[1];
    print STDOUT $caller[1];
    you don't get the hanging behaviour.

    UPDATE: If you keep the first version but you insert the follwoing line in the if-clause of your die-handler

    binmode STDERR, ':raw';
    you also don't get the hanging behaviour even when printing at STDERR.


      OK. Seems you are right! Thanks! BTW I tried to reproduce it on FreeBSD system with non-Unicode locale (i.e. console, locale and filenames are in KOI8-R). But seems it works fine (perl 12) and escapes characters (while escape are wrong):
      "\x{00d5}" does not map to koi8-r at \x{0552}\x{006f} line 18. "\x{00d2}" does not map to koi8-r at \x{0552}\x{006f} line 18. "\x{00c1}" does not map to koi8-r at \x{0552}\x{006f} line 18. ... Died at \x{0552}\x{006f} line 28.
      While linux (perl 10 and perl 14) does not try to escape (probably detects UTF8 locale)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026054]
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-05-28 05:52 GMT
Find Nodes?
    Voting Booth?