[Lxml-checkins] r39378 - in lxml/trunk: . src/lxml

scoder at codespeak.net scoder at codespeak.net
Sun Feb 25 10:34:12 CET 2007


Author: scoder
Date: Sun Feb 25 10:34:09 2007
New Revision: 39378

Modified:
   lxml/trunk/CHANGES.txt
   lxml/trunk/src/lxml/proxy.pxi
   lxml/trunk/src/lxml/tree.pxd
Log:
keep track of removed redundant namespace declarations and free then after merging documents

Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Sun Feb 25 10:34:09 2007
@@ -8,11 +8,16 @@
 Features added
 --------------
 
+* Optimised replacement for libxml2's _xmlReconsiliateNs(). This allows lxml
+  a better handling of namespaces when moving elements between documents.
 
 Bugs fixed
 ----------
 
-* renamed ObjectifiedDataElement.__setText() to _setText() to make it easier
+* Possible memory leaks in namespace handling when moving elements between
+  documents
+
+* Renamed ObjectifiedDataElement.__setText() to _setText() to make it easier
   to access
 
 * The pattern for attribute names in ObjectPath was too restrictive
@@ -20,9 +25,6 @@
 Other changes
 -------------
 
-* optimised replacement for libxml2's _xmlReconsiliateNs(). This allows lxml
-  a better handling of namespaces when moving elements between documents.
-
 * major restructuring in the documentation
 
 

Modified: lxml/trunk/src/lxml/proxy.pxi
==============================================================================
--- lxml/trunk/src/lxml/proxy.pxi	(original)
+++ lxml/trunk/src/lxml/proxy.pxi	Sun Feb 25 10:34:09 2007
@@ -198,6 +198,8 @@
     cdef xmlNs** c_ns_old_cache
     cdef xmlNs* c_ns
     cdef xmlNs* c_new_ns
+    cdef xmlNs* c_del_ns
+    cdef xmlNs* c_last_del_ns
     cdef cstd.size_t i, c_cache_size, c_cache_last
 
     c_element = node._c_node
@@ -211,6 +213,7 @@
     c_ns_old_cache = NULL
     c_cache_size = 0
     c_cache_last = 0
+    c_del_ns = c_last_del_ns = NULL
 
     while c_element is not NULL:
         # remove namespaces defined here that are known in the new ancestors
@@ -220,6 +223,11 @@
                     c_element.doc, c_element.parent, c_element.nsDef.href)
                 if c_ns is NULL:
                     break
+                if c_del_ns is NULL:
+                    c_del_ns = c_last_del_ns = c_element.nsDef
+                else:
+                    c_last_del_ns.next = c_element.nsDef
+                    c_last_del_ns = c_element.nsDef
                 c_element.nsDef = c_element.nsDef.next
             if c_element.nsDef is not NULL:
                 c_new_ns = c_element.nsDef
@@ -228,7 +236,12 @@
                         c_ns = tree.xmlSearchNsByHref(
                             c_element.doc, c_element.parent, c_new_ns.next.href)
                         if c_ns is not NULL:
-                            # not known or at least not different
+                            # already known or equal to a known definition
+                            if c_del_ns is NULL:
+                                c_del_ns = c_last_del_ns = c_new_ns.next
+                            else:
+                                c_last_del_ns.next = c_new_ns.next
+                                c_last_del_ns = c_new_ns.next
                             c_new_ns.next = c_new_ns.next.next
                         else:
                             c_new_ns = c_new_ns.next
@@ -319,6 +332,11 @@
             break
         c_element = c_node
 
+    # free now unused namespace declarations
+    if c_del_ns is not NULL:
+        c_last_del_ns.next = NULL
+        tree.xmlFreeNsList(c_del_ns)
+
     # cleanup
     if c_ns_new_cache is not NULL:
         python.PyMem_Free(c_ns_new_cache)

Modified: lxml/trunk/src/lxml/tree.pxd
==============================================================================
--- lxml/trunk/src/lxml/tree.pxd	(original)
+++ lxml/trunk/src/lxml/tree.pxd	Sun Feb 25 10:34:09 2007
@@ -155,6 +155,8 @@
         
     cdef void xmlFreeDoc(xmlDoc *cur)
     cdef void xmlFreeNode(xmlNode* cur)
+    cdef void xmlFreeNsList(xmlNs* ns)
+    cdef void xmlFreeNs(xmlNs* ns)
     cdef void xmlFree(char* buf)
     
     cdef xmlNode* xmlNewNode(xmlNs* ns, char* name)


More information about the lxml-checkins mailing list