Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed dfc0155

Modified Files:
LibXML.xs LibXML.pm
[fix] XPath functions will croak() on errors instead just die (segfault).

Changes
+ note about this fix

t/08findnodes.t
+ error test

  • Participants
  • Parent commits 55c0cb8

Comments (0)

Files changed (4)

    - pretty formating to all serializing functions
      *NOTE* the XML::LibXML::Node::toString interface changed
      check the XML::LibXML::Node man page 
+   - made xpath functions verbose to perl (one can wrap evals now)
    - better libxml2 version testing
    - more documentation
 
 
 sub findvalue {
     my ($node, $xpath) = @_;
-    return $node->find($xpath)->to_literal->value;
+    my $res;
+    eval {
+        $res = $node->find($xpath);
+    };
+    if  ( $@ ) {
+        die $@;
+    }
+    return $res->to_literal->value;
 }
 
 sub find {
             domNodeNormalize( PmmOWNER(SvPROXYNODE(pnode)) );
         }
 
+        LibXML_error = NEWSV(0, 512);
+        sv_setpvn(LibXML_error, "", 0);
+        xmlSetGenericErrorFunc(PerlIO_stderr(), 
+                               (xmlGenericErrorFunc)LibXML_error_handler);
+
         found = domXPathFind( node, xpath );
         xmlFree( xpath );
 
+        xmlSetGenericErrorFunc(NULL, NULL);
+
+        if ( SvCUR( LibXML_error ) > 0 ) {
+            croak(SvPV(LibXML_error, len));
+        }
+
         if (found) {
             switch (found->type) {
                 case XPATH_NODESET:
             }
             xmlXPathFreeObject(found);
         }
+        else {
+            if ( SvCUR( LibXML_error ) > 0 ) {
+                croak(SvPV(LibXML_error, len));
+            }
+            XSRETURN_UNDEF;
+        }
 
 void
 _findnodes( pnode, perl_xpath )
             domNodeNormalize( PmmOWNER(SvPROXYNODE(pnode)) );
         }
 
+        LibXML_error = NEWSV(0, 512);
+        sv_setpvn(LibXML_error, "", 0);
+        xmlSetGenericErrorFunc(PerlIO_stderr(), 
+                               (xmlGenericErrorFunc)LibXML_error_handler);
+
         nodelist = domXPathSelect( node, xpath );
         xmlFree(xpath);
+        xmlSetGenericErrorFunc(NULL, NULL);
+        if ( SvCUR( LibXML_error ) > 0 ) {
+            croak(SvPV(LibXML_error, len));
+        }
 
         if ( nodelist ) {
             if ( nodelist->nodeNr > 0 ) {
             }
             xmlXPathFreeNodeSet( nodelist );
         }
+        else {
+            if ( SvCUR( LibXML_error ) > 0 ) {
+                croak(SvPV(LibXML_error, len));
+            }
+            XSRETURN_UNDEF;
+        }
         
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::Element
 

File t/08findnodes.t

 use Test;
-BEGIN { plan tests=>14 }
+BEGIN { plan tests=>15 }
 END {ok(0) unless $loaded;}
 use XML::LibXML;
 $loaded = 1;
 ok(@doc);
 # warn($doc[0]->toString);
 
+eval { my $literal = $root->findvalue( "/-" ); };
+ok( $@ );
+
+
 sub finddoc {
     my $doc = shift;
     return unless defined $doc;