Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Segmentation fault from XML::Twig::Elt

by Anonymous Monk
on Nov 07, 2011 at 08:13 UTC ( #936435=note: print w/replies, xml ) Need Help??


in reply to Re: Segmentation fault from XML::Twig::Elt
in thread Segmentation fault from XML::Twig::Elt

I confirm a serious problem. I get premature end of program. No exceptions (segfault), program just ends for no reason before its finished.

I has something to do with Scalar::Util::weaken

I've whittled the proof down to

#!/usr/bin/perl -- $Devel::Trace::TRACE = 0; # Disable use strict; use warnings; use XML::Twig; Main( @ARGV ); warn "main who\n"; exit( 0 ); sub Main { my $self = {}; $self->{xml} = XML::Twig::Elt->new('urlset', { 'xmlns' => 'http://www.google.com/schemas/sitemap/0.84' +, 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => join(' ', 'http://www.google.com/schemas/sitemap/0.84', 'http://www.google.com/schemas/sitemap/0.84/sitemap.xsd', ), }); #~ <url> #~ <loc>http://www.example.com/some/really/interesting/file.html</ +loc> #~ <priority>0.5</priority> #~ </url> #~ for( 0 .. 149500 ){ #~ for( 0 .. 49500 ){ #~ for( 0 .. (49500-39500) ){ #~ for( 0 .. (10000 - 5000) ){ #~ for( 0 .. ( 5000 - 200 ) ){ #~ for( 0 .. ( 5000 - 140 ) ){ #~ for( 0 .. ( 5000 - 170 ) ){ #~ for( 0 .. ( 5000 - 180 ) ){ #~ for( 0 .. ( 5000 - 190 ) ){ #~ for( 0 .. ( 5000 - 183 ) ){ #~ for( 0 .. ( 5000 - 185 ) ){ #~ for( 0 .. ( 5000 - 183 ) ){ for( 0 .. 4817 ){ my @elements; push(@elements, XML::Twig::Elt->new('loc', {}, 'http://www.exa +mple.com/some/really/interesting/file.html' ) ); push(@elements, XML::Twig::Elt->new('priority', {}, '0.5' ) ); my $elt = XML::Twig::Elt->new('url', {}, @elements); $elt->paste(last_child => $self->{xml}); warn "main who $_\n" if $_ > ( 49497 - 3); } binmode STDOUT; #~ print $self->{xml}->sprint();# FAIL,incomplete $self->{xml}->set_pretty_print('indented'); my $header = '<?xml version="1.0" encoding="UTF-8"?>'."\n"; $self->{xml}->print_to_file('2'); # NO cutoff XML s, but still exi +ts on undef; #~ $self->{xml}->purge; #~ Can't call method "purge_up_to" on an undefined value at C:/perl/si +te/5.14.1/lib/XML/Twig.pm line 8087. #~ print $header; #~ $self->{xml}->print(); # XML is cut off #~ print $self->{xml}->sprint(); # XML is cut off, no closing #~ print $self->{xml}->flush; # fail #~ Can't call method "flush_up_to" on an undefined value at C:/perl/si +te/5.14.1/lib/XML/Twig.pm line 8082. warn "about to undef "; $Devel::Trace::TRACE = 1; # Enable undef $self->{xml}; warn "after undef "; return; } __END__

The Devel::Trace shows sub XML::Twig::Elt::DESTROY checking whether to break circular reference manually, 4820 times (versus 4817 children), and skipping because we're using Scalar::Util::weaken

undef $self->{xml}; >> C:/perl/site/5.14.1/lib/XML/Twig.pm:7534: { my $elt= shift; >> C:/perl/site/5.14.1/lib/XML/Twig.pm:7535: return if( $XML::Tw +ig::weakrefs); >> C:/perl/site/5.14.1/lib/XML/Twig.pm:7534: { my $elt= shift; >> C:/perl/site/5.14.1/lib/XML/Twig.pm:7535: return if( $XML::Tw +ig::weakrefs); ...

Adding local $XML::Twig::weakrefs; before undef doesn't change the problem.

I'm using perl 5.14.1 on win32

$ perl -d:Modlist -e " use strict; use warnings; use XML::Twig; " Carp 1.23 Config DynaLoader 1.13 Encode 2.44 Encode::Alias 2.15 Encode::Config 2.05 Encode::Encoding 2.05 Exporter 5.65 Exporter::Heavy 5.65 File::Basename 2.82 File::Glob 1.12 File::Spec 3.33 File::Spec::Unix 3.33 File::Spec::Win32 3.33 List::Util 1.23 Scalar::Util 1.23 UNIVERSAL 1.08 XML::Parser 2.41 XML::Parser::Expat 2.41 XML::Twig 3.39 XSLoader 0.15 base 2.16 bytes 1.04 constant 1.21 feature 1.20 overload 1.13 utf8 1.09 vars 1.02 warnings 1.12 warnings::register 1.02

Replies are listed 'Best First'.
Re^3: Segmentation fault from XML::Twig::Elt
by mirod (Canon) on Nov 07, 2011 at 10:33 UTC

    I can reproduce the problem in win32 (perl 5.12.3), but not on linux (perl5.12.3, 5.12.4 or 5.14.2). So since it's the same code on all 3 versions, I would think it's a bug somewhere in Scalar::Util::weaken or in the core, but only on windows. Which is a bit annoying since I don't develop on windows, I only use it to test modules before a release.

    I am not sure where to go from there honestly. Any idea?

      Most in this thread already is beyond my knowledge of the internal workings,
      but I can contribute that I got this error on a:
      Debian 4.0 box with Perl v5.10.0 built for i486-linux-gnu-thread-multi with these module versions: and on
      Ubuntu 11.04 with Perl v5.10.1 (*) built for i686-linux-gnu-thread-multi.

        The bug is in Perl itself, and seems to be fixed in 5.15.5.

        The following code, which is the simplest I have found to trigger the problem, causes a segmentation fault for versions up to 5.14.2, but not in 5.15.5 or bleadperl:

        #!/usr/bin/perl use strict; use warnings; use Scalar::Util 'weaken'; # the number of iteration that causes a segmentation fault varies # on my machine, 5.14.2 18700, 5.12.4 20147, blead # at these values, the bug shows up most of the time but not always my $ITER= $ARGV[0] || 18700; my $head= {}; my $tail= $head; foreach (1..$ITER) { my $new_tail= { p => $tail }; weaken( $new_tail->{p}); $tail->{n}= $new_tail; $tail= $new_tail; } print "done\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://936435]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2017-12-18 09:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (475 votes). Check out past polls.

    Notices?