[Lxml-checkins] r48175 - in lxml/branch/lxml-1.3: . src/lxml

scoder at codespeak.net scoder at codespeak.net
Mon Oct 29 20:36:17 CET 2007


Author: scoder
Date: Mon Oct 29 20:36:17 2007
New Revision: 48175

Modified:
   lxml/branch/lxml-1.3/CHANGES.txt
   lxml/branch/lxml-1.3/src/lxml/etree.pyx
   lxml/branch/lxml-1.3/src/lxml/proxy.pxi
   lxml/branch/lxml-1.3/src/lxml/python.pxd
Log:
backported GC crash fix from trunk

Modified: lxml/branch/lxml-1.3/CHANGES.txt
==============================================================================
--- lxml/branch/lxml-1.3/CHANGES.txt	(original)
+++ lxml/branch/lxml-1.3/CHANGES.txt	Mon Oct 29 20:36:17 2007
@@ -11,6 +11,8 @@
 Bugs fixed
 ----------
 
+* Backported decref crash fix from 2.0
+
 * Well hidden free-while-in-use crash bug in ObjectPath
 
 

Modified: lxml/branch/lxml-1.3/src/lxml/etree.pyx
==============================================================================
--- lxml/branch/lxml-1.3/src/lxml/etree.pyx	(original)
+++ lxml/branch/lxml-1.3/src/lxml/etree.pyx	Mon Oct 29 20:36:17 2007
@@ -484,8 +484,9 @@
         #print "trying to free node:", <int>self._c_node
         #displayNode(self._c_node, 0)
         if self._c_node is not NULL:
-            unregisterProxy(self)
+            _unregisterProxy(self)
             attemptDeallocation(self._c_node)
+        _releaseProxy(self)
 
     # MANIPULATORS
 
@@ -1127,7 +1128,7 @@
         result = element_class()
     result._doc = doc
     result._c_node = c_node
-    registerProxy(result)
+    _registerProxy(result)
 
     if config.ENABLE_THREADING:
         python.PyThread_release_lock(ELEMENT_CREATION_LOCK)

Modified: lxml/branch/lxml-1.3/src/lxml/proxy.pxi
==============================================================================
--- lxml/branch/lxml-1.3/src/lxml/proxy.pxi	(original)
+++ lxml/branch/lxml-1.3/src/lxml/proxy.pxi	Mon Oct 29 20:36:17 2007
@@ -16,14 +16,14 @@
 cdef int hasProxy(xmlNode* c_node):
     return c_node._private is not NULL
     
-cdef registerProxy(_Element proxy):
+cdef int _registerProxy(_Element proxy) except -1:
     """Register a proxy and type for the node it's proxying for.
     """
     cdef xmlNode* c_node
     # cannot register for NULL
     c_node = proxy._c_node
     if c_node is NULL:
-        return
+        return 0
     #print "registering for:", <int>proxy._c_node
     assert c_node._private is NULL, "double registering proxy!"
     c_node._private = <void*>proxy
@@ -31,14 +31,20 @@
     proxy._gc_doc = <python.PyObject*>proxy._doc
     python.Py_INCREF(proxy._doc)
 
-cdef unregisterProxy(_Element proxy):
+cdef int _unregisterProxy(_Element proxy) except -1:
     """Unregister a proxy for the node it's proxying for.
     """
     cdef xmlNode* c_node
     c_node = proxy._c_node
     assert c_node._private is <void*>proxy, "Tried to unregister unknown proxy"
     c_node._private = NULL
-    python.Py_DECREF(<object>proxy._gc_doc)
+    return 0
+
+cdef _releaseProxy(_Element proxy):
+    """An additional DECREF for the document.
+    """
+    python.Py_XDECREF(proxy._gc_doc)
+    proxy._gc_doc = NULL
 
 ################################################################################
 # temporarily make a node the root node of its document

Modified: lxml/branch/lxml-1.3/src/lxml/python.pxd
==============================================================================
--- lxml/branch/lxml-1.3/src/lxml/python.pxd	(original)
+++ lxml/branch/lxml-1.3/src/lxml/python.pxd	Mon Oct 29 20:36:17 2007
@@ -10,6 +10,7 @@
 
     cdef void Py_INCREF(object o)
     cdef void Py_DECREF(object o)
+    cdef void Py_XDECREF(PyObject* o)
 
     cdef FILE* PyFile_AsFile(object p)
     cdef int PyFile_Check(object p)


More information about the lxml-checkins mailing list