No Gtk2 and no Perl utf8 bug (was: Re: Something-else-than-utf8 bug (was: Re: utf8 bug ?))




[ First I thought it's really a Perl utf8 bug, but at the end
  I figured out, that it's a bug in the Perl program here.
  I decided to keep the whole story, because not anything I wrote
  was useless and should help understanging the problem ;) ]

Jan Hudec wrote:

Hell, perl handling of utf8 is *broken*!

There may be bugs, but you shouldn't go so far to denote the whole thing
broken ;)

1) If I insert 'use utf8;' in the first line, the error does NOT go
   away.
2) If I insert 'use utf8;' in the first line and comment out the
   Gtk2::Label->new, the error DOES go away.
3) If I insert 'use utf8;' and actualy use a non-ascii in $string, the
   problem DOES go away -- the label is still there!

The main difference for case 3) is that $string gets the utf8 flag set 
at compile time, because you assigned a literal utf8 value to $string. 
For the cases 1) and 2) 'use utf8' makes no difference, because your 
source code doesn't contain any utf8 characters, but plain ASCII - so 
$string has no utf8 flag set.

'use utf8;' tells the Perl compiler that your source code is written in
utf8 encoding. It doesn't change Perl's runtime behaviour, in particular
it's not needed to enable Unicode handling.

Now, the error obviously has something to do with the Gtk2 typemap.
Without calling Gtk2::Label->new($string), there is no problem.

But what is strange is, that it makes a difference whether $string
actualy contains a non-ascii character.

Indeed. We should file a bug report to the Perl developers with 
Christians not-Gtk2-using script. BTW it makes no difference whether 
$string actually contains non-ASCII chars or not. It suffice that the 
utf8 flag is set.

Interesting is that all these variants

  sub replace { $_[0] }
  sub replace { my $a = shift; $a }
  sub replace { local $_ = shift; $_ }

work, but the global $_ assignment not

  sub replace { $_=shift; $_ }

And now after wrting this down and looking at the code, I'm sure it's no
Perl or Gtk2 bug at all!

What are we doing here? We'r doing a substition regex on the global $_,
but the right side calls a sub which *modifies* $_. Is this expected to
work? No, this is really a bug in the script. Perl get's totatly 
confused about $_ and panics! ;)

We learn: don't struggle with globals! Use lexicals! ;)

Regards,

Joern

-- 
$a=$a[8][67][9][0][42][214][82][78][0][50][69][68][69][82][0][73][78][0]
[65][0][20][16][0][68][73][77][69][78][83][73][79][78][65][76][0][65][82
][82][65][89]=sub{sub _($){print$_[ z]}($z,$i)= _;(++$i)while!$z->[$i];$
s+=$i;_ chr($i+32);$s!=2292&&&$a($z->[$i],$c>>$e)};&$a(\ a,$d<<$f);_"\n"

Attachment: pgpJ0ceSDml1y.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]