Commit a597d1b6 authored by Boxiang Sun's avatar Boxiang Sun

Update Cython from 0.22 to 0.24

parent 2190118b
......@@ -5,20 +5,20 @@ from test_helper import create_virtenv, run_test
ENV_NAME = "lxml_test_env_" + os.path.basename(sys.executable)
SRC_DIR = os.path.abspath(os.path.join(ENV_NAME, "src"))
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython"))
PYTHON_EXE = os.path.abspath(os.path.join(ENV_NAME, "bin", "python"))
def install_and_test_lxml():
shutil.rmtree(SRC_DIR, ignore_errors=True)
os.makedirs(SRC_DIR)
url = "https://github.com/cython/cython/archive/0.22.tar.gz"
subprocess.check_call(["wget", url, "-O", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
subprocess.check_call(["tar", "-zxf", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
url = "https://github.com/cython/cython"
subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "0.24", url], cwd=SRC_DIR)
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython-0.22"))
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "integration", "Cython-0.22.patch"))
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "../integration/Cython-0.24.patch"))
subprocess.check_call(["patch", "-p1", "--input=" + PATCH_FILE], cwd=CYTHON_DIR)
print "Applied Cython patch"
print ">>> Applied Cython patch"
subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=CYTHON_DIR)
subprocess.check_call([PYTHON_EXE, "-c", "import Cython"], cwd=CYTHON_DIR)
......@@ -33,7 +33,7 @@ def install_and_test_lxml():
subprocess.check_call([PYTHON_EXE, "setup.py", "build_ext", "-i", "--with-cython"], cwd=LXML_DIR)
expected = [{'ran': 1381, 'failures': 1}]
expected = [{'ran': 1381}]
run_test([PYTHON_EXE, "test.py"], cwd=LXML_DIR, expected=expected)
create_virtenv(ENV_NAME, None, force_create = True)
......
......@@ -22,18 +22,17 @@ test_helper.create_virtenv(ENV_NAME, DEPENDENCIES)
SRC_DIR = ENV_NAME
ENV_DIR = os.path.abspath(ENV_NAME)
PYTHON_EXE = os.path.abspath(ENV_NAME + "/bin/python")
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython-0.22"))
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython"))
NUMPY_DIR = os.path.abspath(os.path.join(SRC_DIR, "numpy"))
print_progress_header("Setting up Cython...")
if not os.path.exists(CYTHON_DIR):
url = "https://github.com/cython/cython/archive/0.22.tar.gz"
subprocess.check_call(["wget", url, "-O", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
subprocess.check_call(["tar", "-zxf", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
url = "https://github.com/cython/cython"
subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "0.24", url], cwd=SRC_DIR)
if USE_CUSTOM_PATCHES:
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "../integration/Cython-0.22.patch"))
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "../integration/Cython-0.24.patch"))
subprocess.check_call(["patch", "-p1", "--input=" + PATCH_FILE], cwd=CYTHON_DIR)
print ">>> Applied Cython patch"
......
From eaf300b61a56af151e93aa51803e6a61a0f8afee Mon Sep 17 00:00:00 2001
From: Marius Wachtler <undingen@gmail.com>
Date: Fri, 6 May 2016 16:19:50 +0100
Subject: [PATCH] [PATCH] Pyston change: make cython work with pyston
---
Cython/Compiler/ExprNodes.py | 9 +++++++++
Cython/Utility/CythonFunction.c | 4 +++-
Cython/Utility/Exceptions.c | 4 +++-
Cython/Utility/ModuleSetupCode.c | 2 +-
4 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index f99ec6e..7ab41f3 100644
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -7784,12 +7784,21 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
@classmethod
def from_defnode(cls, node, binding):
+ """
+ # Pyston change: dont't generate custom code objects because we don't support them currently
return cls(node.pos,
def_node=node,
pymethdef_cname=node.entry.pymethdef_cname,
binding=binding or node.specialized_cpdefs,
specialized_cpdefs=node.specialized_cpdefs,
code_object=CodeObjectNode(node))
+ """
+ return cls(node.pos,
+ def_node=node,
+ pymethdef_cname=node.entry.pymethdef_cname,
+ binding=binding or node.specialized_cpdefs,
+ specialized_cpdefs=node.specialized_cpdefs,
+ code_object=None)
def analyse_types(self, env):
if self.binding:
diff --git a/Cython/Utility/CythonFunction.c b/Cython/Utility/CythonFunction.c
index 9cc38f0..ab05ad1 100644
--- a/Cython/Utility/CythonFunction.c
+++ b/Cython/Utility/CythonFunction.c
@@ -561,7 +561,9 @@ __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
#endif
}
-#if CYTHON_COMPILING_IN_PYPY
+// Pyston change:
+// #if CYTHON_COMPILING_IN_PYPY
+#if 0 && CYTHON_COMPILING_IN_PYPY
// originally copied from PyCFunction_Call() in CPython's Objects/methodobject.c
// PyPy does not have this function
static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
diff --git a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c
index 354a776..567970d 100644
--- a/Cython/Utility/Exceptions.c
+++ b/Cython/Utility/Exceptions.c
@@ -528,7 +528,9 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
- py_frame->f_lineno = py_line;
+ // Pyston change:
+ // py_frame->f_lineno = py_line;
+ PyFrame_SetLineNumber(py_frame, py_line);
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_code);
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index 6477fb2..75dcdda 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -32,7 +32,7 @@
#define Py_HUGE_VAL HUGE_VAL
#endif
-#ifdef PYPY_VERSION
+#if defined(PYPY_VERSION) || defined(PYSTON_VERSION)
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
--
1.9.1
diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c
index dd4c40b..8161702 100644
--- a/Cython/Utility/Builtins.c
+++ b/Cython/Utility/Builtins.c
@@ -115,7 +115,7 @@ static PyObject* __Pyx_PyExec3(PyObject* o, PyObject* globals, PyObject* locals)
}
if (PyCode_Check(o)) {
- if (PyCode_GetNumFree((PyCodeObject *)o) > 0) {
+ if (PyCode_HasFreeVars((PyCodeObject *)o) > 0) {
PyErr_SetString(PyExc_TypeError,
"code object passed to exec() may not contain free variables");
goto bad;
diff --git a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c
index db7d95b..3513d5f 100644
--- a/Cython/Utility/Coroutine.c
+++ b/Cython/Utility/Coroutine.c
@@ -476,7 +476,7 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
__Pyx_PyThreadState_assign
if (value) {
-#if CYTHON_COMPILING_IN_PYPY
+#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
// FIXME: what to do in PyPy?
#else
// Generators always return to their most recent caller, not
@@ -503,7 +503,7 @@ PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
if (retval) {
__Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
&self->exc_traceback);
-#if CYTHON_COMPILING_IN_PYPY
+#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
// FIXME: what to do in PyPy?
#else
// Don't keep the reference to f_back any longer than necessary. It
@@ -1400,7 +1400,7 @@ static void __Pyx__ReturnWithStopIteration(PyObject* value); /*proto*/
static void __Pyx__ReturnWithStopIteration(PyObject* value) {
PyObject *exc, *args;
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
__Pyx_PyThreadState_declare
if ((PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x030500B1) || PyTuple_Check(value)) {
args = PyTuple_New(1);
diff --git a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c
index d1aceb3..48812bb 100644
--- a/Cython/Utility/Exceptions.c
+++ b/Cython/Utility/Exceptions.c
@@ -9,7 +9,7 @@
/////////////// PyThreadStateGet.proto ///////////////
//@substitute: naming
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_PyThreadState_declare PyThreadState *$local_tstate_cname;
#define __Pyx_PyThreadState_assign $local_tstate_cname = PyThreadState_GET();
#else
@@ -21,7 +21,7 @@
/////////////// PyErrExceptionMatches.proto ///////////////
//@substitute: naming
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState($local_tstate_cname, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
@@ -30,7 +30,7 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta
/////////////// PyErrExceptionMatches ///////////////
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
PyObject *exc_type = tstate->curexc_type;
if (exc_type == err) return 1;
@@ -43,7 +43,7 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta
//@substitute: naming
//@requires: PyThreadStateGet
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState($local_tstate_cname, type, value, tb)
@@ -60,7 +60,7 @@ static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject
/////////////// PyErrFetchRestore ///////////////
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
tmp_type = tstate->curexc_type;
@@ -285,7 +285,7 @@ bad:
//@substitute: naming
//@requires: PyThreadStateGet
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_GetException(type, value, tb) __Pyx__GetException($local_tstate_cname, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#else
@@ -294,13 +294,13 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
/////////////// GetException ///////////////
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
PyObject *local_type, *local_value, *local_tb;
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
PyObject *tmp_type, *tmp_value, *tmp_tb;
local_type = tstate->curexc_type;
local_value = tstate->curexc_value;
@@ -312,7 +312,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
PyErr_NormalizeException(&local_type, &local_value, &local_tb);
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
if (unlikely(tstate->curexc_type))
#else
if (unlikely(PyErr_Occurred()))
@@ -332,7 +332,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb)
*type = local_type;
*value = local_value;
*tb = local_tb;
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback;
@@ -366,7 +366,7 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void); /*proto*/
static CYTHON_INLINE void __Pyx_ReraiseException(void) {
PyObject *type = NULL, *value = NULL, *tb = NULL;
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
PyThreadState *tstate = PyThreadState_GET();
type = tstate->exc_type;
value = tstate->exc_value;
@@ -398,7 +398,7 @@ static CYTHON_INLINE void __Pyx_ReraiseException(void) {
//@substitute: naming
//@requires: PyThreadStateGet
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave($local_tstate_cname, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset($local_tstate_cname, type, value, tb)
@@ -412,7 +412,7 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject
/////////////// SaveResetException ///////////////
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
*type = tstate->exc_type;
*value = tstate->exc_value;
@@ -440,7 +440,7 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject
//@substitute: naming
//@requires: PyThreadStateGet
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap($local_tstate_cname, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); /*proto*/
#else
@@ -449,7 +449,7 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value,
/////////////// SwapException ///////////////
-#if CYTHON_COMPILING_IN_CPYTHON
+#if CYTHON_COMPILING_IN_CPYTHON && !CYTHON_COMPILING_IN_PYSTON
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
tmp_type = tstate->exc_type;
@@ -615,7 +615,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line,
0 /*PyObject *locals*/
);
if (!py_frame) goto bad;
- py_frame->f_lineno = py_line;
+ PyFrame_SetLineNumber(py_frame, py_line);
PyTraceBack_Here(py_frame);
bad:
Py_XDECREF(py_code);
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index ad04117..5c394f2 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -32,15 +32,77 @@
#define Py_HUGE_VAL HUGE_VAL
#endif
-#ifdef PYPY_VERSION
+// This is coiped from https://github.com/Nexedi/pycapicompat
+// Which defined extra CAPI functions for compatibility between various C-based Python implementations
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(PYSTON_VERSION) && !defined(PYPY_VERSION)
+# define CPYTHON_VERSION PY_VERSION
+#endif
+
+#ifdef CPYTHON_VERSION
+#include <frameobject.h>
+
+// PyCode. Check whether there are free variables
+static inline int PyCode_HasFreeVars(PyCodeObject *co) {
+ return PyCode_GetNumFree(co) > 0 ? 1 : 0;
+}
+
+// PyFrame. Set frame line number
+static inline void
+PyFrame_SetLineNumber(PyFrameObject *f, int lineno) {
+ f->f_lineno = lineno;
+}
+
+#elif defined(PYSTON_VERSION)
+
+// PyCode_HasFreeVars(co) provided out of the box
+// PyFrame_SetLineNumber(f, lineno) provided out of the box : 0; }
+
+#elif defined(PYPY_VERSION)
+
+// PyCode. Check whether there are free variables
+// TODO: need to test it on PyPy
+static inline int PyCode_HasFreeVars(PyCodeObject *co) {
+ return PyCode_GetNumFree(co) > 0 ? 1 : 0;
+}
+
+// PyFrame. Set frame line number
+// TODO: need to test it on PyPy
+static inline void
+PyFrame_SetLineNumber(PyFrameObject *f, int lineno) {
+ f->f_lineno = lineno;
+}
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+// Because Pyston is more like CPython. Most of Cython code under CPython directive could also work for
+// Pyston. So if Cython work under Pyston, set CYTHON_COMPILING_IN_CPYTHON too.
+// But there still have exceptions. So set CYTHON_COMPILING_IN_PYSTON for the places that Pyston can not
+// use the code for CPython.
+#if defined(PYSTON_VERSION)
+ #define CYTHON_COMPILING_IN_PYPY 0
+ #define CYTHON_COMPILING_IN_CPYTHON 1
+ #define CYTHON_COMPILING_IN_PYSTON 1
+#elif defined(PYPY_VERSION)
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
+ #define CYTHON_COMPILING_IN_PYSTON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
+ #define CYTHON_COMPILING_IN_PYSTON 0
#endif
-#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
+
+#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000 && !CYTHON_COMPILING_IN_PYSTON
+// Pyston not use CPython PyLong implementation
#define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_USE_PYLONG_INTERNALS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment