summaryrefslogtreecommitdiff
path: root/src/lxml/proxy.pxi
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2014-01-17 19:03:17 +0100
committerStefan Behnel <stefan_ml@behnel.de>2014-01-17 19:03:17 +0100
commitc368af418a4cf822287f098a4d639398fc352c20 (patch)
tree160bd85675ae2c686b1b876ed93b46876700169e /src/lxml/proxy.pxi
parent92b93dd2d72dd706e4ce05b8043c33e23b186e17 (diff)
downloadpython-lxml-c368af418a4cf822287f098a4d639398fc352c20.tar.gz
use @cython.no_gc_clear decorator for Elements to get rid of double _Document ref hack
Diffstat (limited to 'src/lxml/proxy.pxi')
-rw-r--r--src/lxml/proxy.pxi25
1 files changed, 4 insertions, 21 deletions
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 = <void*>proxy
- # additional INCREF to make sure _Document is GC-ed LAST!
- proxy._gc_doc = <python.PyObject*>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 = <python.PyObject*>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