ascray has asked for the wisdom of the Perl Monks concerning the following question:

I'am using AUTOLOAD in some kind of Object-Relation Mapping class. My application just freeze when working with utf8 data. With non-utf8 everything is OK.
Base class:
package XNObject; use strict; sub new { my $class = shift; my %fields = ( _modified => 0, _actual => 0, _f => {}, # "real" object fields ); my $self = { %fields, }; bless $self, $class; } our $AUTOLOAD; sub AUTOLOAD { my $self = shift; my $value = shift; my $type = ref($self) or croak "No class for AUTOLOAD"; my $name = $AUTOLOAD; $name =~ s/.*://; if(defined($value)){ return $self->{_f}->{$name} = $value; }else{ return $self->{_f}->{$name}; } } # other stuff skipped 1;
Derived class:
package ForumMessage; use strict; use base qw(XNObject); sub new { my $class = shift; my $self = $class->SUPER::new(@_); my %fields = ( _type => 'forum_message', ); @{$self}{keys %fields} = values %fields; bless $self, $class; } #other stuff skipped 1;
Using in app:
use strict; use ForumMessage; my $msg = ForumMessage->new; my $body = "This is a test"; # utf8 string here $msg->body($body); # strange pause with utf8 string print $msg->body; # works fine with any data #$msg->user_id($user_id); #$msg->_store;

Works fine. Only while $body is non-UTF-8 string.

In other case $msg->body($body) produces strange pause (15-60 secs) with 100% CPU load.

Any ideas?

$ perl -v This is perl, v5.8.9 built for i386-freebsd-64int

Replies are listed 'Best First'.
Re: Strange AUTOLOAD's bevavior with utf8 data
by almut (Canon) on Apr 29, 2009 at 10:54 UTC

    FWIW (I currently don't have 5.8.9 available), I've just tried it with 5.8.8 (x86_64-linux-gnu-thread-multi) and 5.10.0 (x86_64-linux) and

    $body = "This \x{5555} is \x{6666} a \x{7777} test\n";

    and it prints out fine (immediately).  Of course, that won't help much if it's a 5.8.9-specific issue...

    Could you post a specific UTF-8 string that reproduces the problem in your case with the code as shown? (BTW, I had to put in a use Carp for the croak)

      Thanks for your reply.

      I've looked at my code again before posting here full module source and found string in my AUTOLOAD sub that stoped my app:

      carp "value now is ".$value; # ..this message will not be printed if $value is utf8 string

      So I found the real error source: combination carp & use diagnostics

      Can you check following code in your environment?:

      #!/usr/bin/perl use strict; #use diagnostics; # when uncommented will freeze the app use Carp; print "before carp\n"; carp "\x{41f}\x{440}\x{438}\x{432}\x{435}\x{442}"; #'Hello' in Russian print "after carp\n";

      Is this a normal reaction on "use diagnostics"?

        I tried it on

        • Debian Linux 5.8.8
        • ActivePerl Windown 5.6.0
        • ActivePerl Windown 5.6.1
        • ActivePerl Windown 5.8.0
        • ActivePerl Windown 5.8.8
        • ActivePerl Windown 5.8.9
        • ActivePerl Windown 5.10.0

        With 5.8.8 and 5.8.9 in Windows, I get a 4 second "pause" where CPU activity reached 100%.

        It doesn't occur with warnings and without diagnostics (a debugging tool) and it doesn't happen in 5.10, so it's a non-issue.