summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lxml/includes/etree_defs.h17
-rw-r--r--src/lxml/proxy.pxi12
-rw-r--r--src/lxml/python.pxd1
3 files changed, 24 insertions, 6 deletions
diff --git a/src/lxml/includes/etree_defs.h b/src/lxml/includes/etree_defs.h
index a8f47474..1cbae39d 100644
--- a/src/lxml/includes/etree_defs.h
+++ b/src/lxml/includes/etree_defs.h
@@ -36,8 +36,25 @@
#ifdef PYPY_VERSION
# define IS_PYPY 1
+/*
+PyPy 4.0 contains some important cpyext fixes and identifies as Python 2.7.10 or 3.2.5,
+just like PyPy 2.6.1, which does not have these fixes.
+*/
+# if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7 || \
+ PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7 && PY_MICRO_VERSION < 10 || \
+ PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 2 || \
+ PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION < 5)
+ #define IS_PYPY26 1
+# elif (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7 && PY_MICRO_VERSION == 10 || \
+ PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION == 5)
+# include "string.h"
+ #define IS_PYPY26 (strncmp(PYPY_VERSION, "2.", 2) == 0)
+# else
+ #define IS_PYPY26 0
+# endif
#else
# define IS_PYPY 0
+# define IS_PYPY26 0
#endif
#if PY_MAJOR_VERSION >= 3
diff --git a/src/lxml/proxy.pxi b/src/lxml/proxy.pxi
index 76f4a6a8..e584ad94 100644
--- a/src/lxml/proxy.pxi
+++ b/src/lxml/proxy.pxi
@@ -17,7 +17,7 @@ cdef inline _Element getProxy(xmlNode* c_node):
"""
#print "getProxy for:", <int>c_node
if c_node is not NULL and c_node._private is not NULL:
- if python.IS_PYPY:
+ if python.IS_PYPY26:
return <_Element>python.PyWeakref_LockObject(<python.PyObject*>c_node._private)
else:
return <_Element>c_node._private
@@ -29,13 +29,13 @@ cdef inline _Element getProxy(xmlNode* c_node):
cdef inline bint hasProxy(xmlNode* c_node):
if c_node._private is NULL:
return False
- if python.IS_PYPY:
- return _isProxyAliveInPypy(c_node)
+ if python.IS_PYPY26:
+ return _isProxyAliveInPypy26(c_node)
return True
@cython.linetrace(False)
-cdef bint _isProxyAliveInPypy(xmlNode* c_node):
+cdef bint _isProxyAliveInPypy26(xmlNode* c_node):
retval = True
if python.PyWeakref_LockObject(<python.PyObject*>c_node._private) is None:
# proxy has already died => remove weak reference
@@ -55,7 +55,7 @@ cdef inline int _registerProxy(_Element proxy, _Document doc,
assert not hasProxy(c_node), u"double registering proxy!"
proxy._doc = doc
proxy._c_node = c_node
- if python.IS_PYPY:
+ if python.IS_PYPY26:
c_node._private = <void*>python.PyWeakref_NewRef(proxy, NULL)
else:
c_node._private = <void*>proxy
@@ -67,7 +67,7 @@ cdef inline int _unregisterProxy(_Element proxy) except -1:
u"""Unregister a proxy for the node it's proxying for.
"""
cdef xmlNode* c_node = proxy._c_node
- if python.IS_PYPY:
+ if python.IS_PYPY26:
weakref_ptr = <python.PyObject*>c_node._private
c_node._private = NULL
python.Py_XDECREF(weakref_ptr)
diff --git a/src/lxml/python.pxd b/src/lxml/python.pxd
index 72fa27ee..60075286 100644
--- a/src/lxml/python.pxd
+++ b/src/lxml/python.pxd
@@ -124,6 +124,7 @@ cdef extern from "etree_defs.h": # redefines some functions as macros
cdef object PY_NEW(object t)
cdef bint LXML_UNICODE_STRINGS
cdef bint IS_PYTHON3
+ cdef bint IS_PYPY26
cdef bint IS_PYPY
cdef extern from "lxml_endian.h":