From c368af418a4cf822287f098a4d639398fc352c20 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 17 Jan 2014 19:03:17 +0100 Subject: use @cython.no_gc_clear decorator for Elements to get rid of double _Document ref hack --- src/lxml/proxy.pxi | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'src/lxml/proxy.pxi') diff --git a/src/lxml/proxy.pxi b/src/lxml/proxy.pxi index 6e75c65b..8fb6c1f4 100644 --- a/src/lxml/proxy.pxi +++ b/src/lxml/proxy.pxi @@ -49,9 +49,6 @@ cdef inline int _registerProxy(_Element proxy, _Document doc, return -1 # manual exception propagation else: c_node._private = proxy - # additional INCREF to make sure _Document is GC-ed LAST! - proxy._gc_doc = doc - python.Py_INCREF(doc) return 0 cdef inline int _unregisterProxy(_Element proxy) except -1: @@ -68,22 +65,6 @@ cdef inline int _unregisterProxy(_Element proxy) except -1: c_node._private = NULL return 0 -cdef inline void _releaseProxy(_Element proxy): - u"""An additional DECREF for the document. - """ - python.Py_XDECREF(proxy._gc_doc) - proxy._gc_doc = NULL - -cdef inline void _updateProxyDocument(_Element element, _Document doc): - u"""Replace the document reference of a proxy. - """ - if element._doc is not doc: - old_doc = element._doc - element._doc = doc - python.Py_INCREF(doc) - element._gc_doc = doc - python.Py_DECREF(old_doc) - ################################################################################ # temporarily make a node the root node of its document @@ -416,7 +397,8 @@ cdef int moveNodeToDocument(_Document doc, xmlDoc* c_source_doc, if proxy_count == 1 and c_start_node._private is not NULL: proxy = getProxy(c_start_node) if proxy is not None: - _updateProxyDocument(proxy, doc) + if proxy._doc is not doc: + proxy._doc = doc else: fixElementDocument(c_start_node, doc, proxy_count) else: @@ -433,7 +415,8 @@ cdef void fixElementDocument(xmlNode* c_element, _Document doc, if c_node._private is not NULL: proxy = getProxy(c_node) if proxy is not None: - _updateProxyDocument(proxy, doc) + if proxy._doc is not doc: + proxy._doc = doc proxy_count -= 1 if proxy_count == 0: return -- cgit v1.2.1