[xml] patch for libxslt python document loading



With current trunk the python document loader can't fail to return a
document without causing a segfault.

The patch against trunk fixes that problem. NULL is now correctly
returned from here.

It also fixes a problem with the python loader function raising an
exception. Such exceptions should be considered simply as loader
failure. Since the loader is under complete XSLT control the only
thing it can do is return NULL to indicate no resource.

Hope this helps. It helps me!


 svn diff python/libxslt.c 
Index: python/libxslt.c
===================================================================
--- python/libxslt.c    (revision 1417)
+++ python/libxslt.c    (working copy)
@@ -558,13 +558,27 @@
 
         if (result != NULL) {
             /*
-            * The return value should be the document
-             * Should we test it somehow before getting the C object from it?
+            * The return value should be the document or None.
             */
-            PyObject *py_doc = PyObject_GetAttrString(result, (char *) "_o");
-            doc = (xmlDocPtr) PyxmlNode_Get(py_doc);
-            /* do we have to DECCREF the result?? */
+            if (result == Py_None)
+                return (NULL);
+            else {
+                PyObject *py_doc = PyObject_GetAttrString(result, (char *) "_o");
+                doc = (xmlDocPtr) PyxmlNode_Get(py_doc);
+                /* do we have to DECCREF the result?? */
+            }
         }
+        else {
+            /*
+             * Document load failure is controlled by XSLT... so we should
+             * not pass the exception back to python.
+             */
+            if (PyErr_Occurred() != NULL) {
+                PyErr_Clear();
+            }
+
+            return (NULL);
+        }
     }
 
     if (! pctxt->wellFormed) {


-- 
Nic Ferrier
http://www.tapsellferrier.co.uk   for all your tapsell ferrier needs



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]