Anonymous avatar Anonymous 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

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
 
 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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.