Re: lost node at /usr/lib/perl5/XML/LibXML.pm line 1205.
Petr Pajas <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Organization | UFAL MFF UK |
| Message-ID | <[email protected]> |
On Sunday 10 August 2008, Jonas Häggqvist wrote:
> I'm getting a strange error when doing getElementsByTagName() on a
> Document. Admittedly it could be related to my sub-par Perl-fu, but it
> seems like I should at least not get a segfault it things were working
> correctly.
The problem is you are doing a real nasty thing there. You bless a non-libxml
object (a perl ARRAYREF) as XML::LibXML::Document and call a method on it.
The method gets a pointer and there is no way it can tell if it points to a
XML::LibXML data structure or not. It assumes it does, if it was blessed to
the right class. If it does not (your fault), bad things can happen, just
like if you were programming in C and made a wrong cast from a (void *).
Others have already pointed to the problematic lines in your code.
HTH,
Petr
> The minimal example below shows this behaviour.
>
> $ cat temp.pl
> #!/usr/bin/perl
>
> use XML::LibXML;
>
> sub readfile {
> my ($file) = @_;
> $doc = XML::LibXML->new->parse_file($file);
> return \($doc);
> }
>
> my ($doc) = readfile($ARGV[0]);
> bless($doc, 'XML::LibXML::Document');
> my $elements = $doc->getElementsByTagName("bar");
>
> $ cat temp.xml
> <?xml version='1.0' encoding='UTF-8'?>
> <foo>
> <bar>test</bar>
> </foo>
>
> $ perl temp.pl temp.xml
> lost node at /usr/lib/perl5/XML/LibXML.pm line 1205.
> Segmentation fault
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs