Update version to 3.0.0

This commit is contained in:
Aleksandr Proklov 2023-07-27 16:15:48 +09:00
parent 47c4bd4abd
commit 3a8a355f21
4 changed files with 5 additions and 461 deletions

View file

@ -1,2 +1,2 @@
sources:
cython-0.29.36.tar.gz: 5b7a3e929edb741b670f318475318c3242b28e62
cython-3.0.0.tar.gz: e8f13c029fb7b5de123bfa3cc1b8cf688ddd9a1f

View file

@ -1,325 +0,0 @@
# from https://github.com/cython/cython/pull/4584
diff -ruN a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c
--- a/Cython/Utility/Coroutine.c 2023-04-02 19:39:29.000000000 +0900
+++ b/Cython/Utility/Coroutine.c 2023-04-18 11:32:47.352800662 +0900
@@ -601,6 +601,9 @@
static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) {
+#if PY_VERSION_HEX >= 0x030B00a4
+ Py_CLEAR(exc_state->exc_value);
+#else
PyObject *t, *v, *tb;
t = exc_state->exc_type;
v = exc_state->exc_value;
@@ -613,6 +616,7 @@
Py_XDECREF(t);
Py_XDECREF(v);
Py_XDECREF(tb);
+#endif
}
#define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL)
@@ -714,14 +718,21 @@
// - do not touch external frames and tracebacks
exc_state = &self->gi_exc_state;
- if (exc_state->exc_type) {
+ if (exc_state->exc_value) {
#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
// necessarily their creator.
- if (exc_state->exc_traceback) {
- PyTracebackObject *tb = (PyTracebackObject *) exc_state->exc_traceback;
+ PyObject *exc_tb;
+ #if PY_VERSION_HEX >= 0x030B00a4
+ // owned reference!
+ exc_tb = PyException_GetTraceback(exc_state->exc_value);
+ #else
+ exc_tb = exc_state->exc_traceback;
+ #endif
+ if (exc_tb) {
+ PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
PyFrameObject *f = tb->tb_frame;
assert(f->f_back == NULL);
@@ -733,6 +744,9 @@
Py_XINCREF(tstate->frame);
f->f_back = tstate->frame;
#endif
+ #if PY_VERSION_HEX >= 0x030B00a4
+ Py_DECREF(exc_tb);
+ #endif
}
#endif
}
@@ -774,17 +788,28 @@
// Don't keep the reference to f_back any longer than necessary. It
// may keep a chain of frames alive or it could create a reference
// cycle.
- PyObject *exc_tb = exc_state->exc_traceback;
-
- if (likely(exc_tb)) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
// FIXME: what to do in PyPy?
#else
+ PyObject *exc_tb;
+
+ #if PY_VERSION_HEX >= 0x030B00a4
+ if (!exc_state->exc_value) return;
+ // owned reference!
+ exc_tb = PyException_GetTraceback(exc_state->exc_value);
+ #else
+ exc_tb = exc_state->exc_traceback;
+ #endif
+
+ if (likely(exc_tb)) {
PyTracebackObject *tb = (PyTracebackObject *) exc_tb;
PyFrameObject *f = tb->tb_frame;
Py_CLEAR(f->f_back);
-#endif
+ #if PY_VERSION_HEX >= 0x030B00a4
+ Py_DECREF(exc_tb);
+ #endif
}
+#endif
}
static CYTHON_INLINE
@@ -1128,9 +1153,13 @@
}
static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) {
+#if PY_VERSION_HEX >= 0x030B00a4
+ Py_VISIT(exc_state->exc_value);
+#else
Py_VISIT(exc_state->exc_type);
Py_VISIT(exc_state->exc_value);
Py_VISIT(exc_state->exc_traceback);
+#endif
return 0;
}
@@ -1431,9 +1460,13 @@
gen->resume_label = 0;
gen->classobj = NULL;
gen->yieldfrom = NULL;
+ #if PY_VERSION_HEX >= 0x030B00a4
+ gen->gi_exc_state.exc_value = NULL;
+ #else
gen->gi_exc_state.exc_type = NULL;
gen->gi_exc_state.exc_value = NULL;
gen->gi_exc_state.exc_traceback = NULL;
+ #endif
#if CYTHON_USE_EXC_INFO_STACK
gen->gi_exc_state.previous_item = NULL;
#endif
@@ -2017,7 +2050,7 @@
#if CYTHON_FAST_THREAD_STATE
__Pyx_PyThreadState_assign
#if CYTHON_USE_EXC_INFO_STACK
- if (!$local_tstate_cname->exc_info->exc_type)
+ if (!$local_tstate_cname->exc_info->exc_value)
#else
if (!$local_tstate_cname->exc_type)
#endif
diff -ruN a/Cython/Utility/Exceptions.c b/Cython/Utility/Exceptions.c
--- a/Cython/Utility/Exceptions.c 2023-04-02 19:39:29.000000000 +0900
+++ b/Cython/Utility/Exceptions.c 2023-04-18 11:42:28.014745170 +0900
@@ -322,7 +322,7 @@
__Pyx_PyErr_GetTopmostException(PyThreadState *tstate)
{
_PyErr_StackItem *exc_info = tstate->exc_info;
- while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) &&
+ while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) &&
exc_info->previous_item != NULL)
{
exc_info = exc_info->previous_item;
@@ -388,12 +388,21 @@
#if CYTHON_USE_EXC_INFO_STACK
{
_PyErr_StackItem *exc_info = tstate->exc_info;
+ #if PY_VERSION_HEX >= 0x030B00a4
+ tmp_value = exc_info->exc_value;
+ exc_info->exc_value = local_value;
+ tmp_type = NULL;
+ tmp_tb = NULL;
+ Py_XDECREF(local_type);
+ Py_XDECREF(local_tb);
+ #else
tmp_type = exc_info->exc_type;
tmp_value = exc_info->exc_value;
tmp_tb = exc_info->exc_traceback;
exc_info->exc_type = local_type;
exc_info->exc_value = local_value;
exc_info->exc_traceback = local_tb;
+ #endif
}
#else
tmp_type = tstate->exc_type;
@@ -433,35 +442,44 @@
PyObject *type = NULL, *value = NULL, *tb = NULL;
#if CYTHON_FAST_THREAD_STATE
PyThreadState *tstate = PyThreadState_GET();
- #if CYTHON_USE_EXC_INFO_STACK
+ #if CYTHON_USE_EXC_INFO_STACK
_PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
- type = exc_info->exc_type;
value = exc_info->exc_value;
- tb = exc_info->exc_traceback;
+ #if PY_VERSION_HEX >= 0x030B00a4
+ if (unlikely(value == Py_None)) {
+ value = NULL;
+ } else if (value) {
+ Py_INCREF(value);
+ type = (PyObject*) Py_TYPE(value);
+ Py_INCREF(type);
+ tb = PyException_GetTraceback(value);
+ }
#else
+ type = exc_info->exc_type;
+ tb = exc_info->exc_traceback;
+ Py_XINCREF(type);
+ Py_XINCREF(value);
+ Py_XINCREF(tb);
+ #endif
+ #else
type = tstate->exc_type;
value = tstate->exc_value;
tb = tstate->exc_traceback;
- #endif
+ Py_XINCREF(type);
+ Py_XINCREF(value);
+ Py_XINCREF(tb);
+ #endif
#else
PyErr_GetExcInfo(&type, &value, &tb);
#endif
- if (!type || type == Py_None) {
-#if !CYTHON_FAST_THREAD_STATE
+ if (unlikely(!type || type == Py_None)) {
Py_XDECREF(type);
Py_XDECREF(value);
Py_XDECREF(tb);
-#endif
// message copied from Py3
PyErr_SetString(PyExc_RuntimeError,
"No active exception to reraise");
} else {
-#if CYTHON_FAST_THREAD_STATE
- Py_INCREF(type);
- Py_XINCREF(value);
- Py_XINCREF(tb);
-
-#endif
PyErr_Restore(type, value, tb);
}
}
@@ -487,24 +505,49 @@
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
- #if CYTHON_USE_EXC_INFO_STACK
+ #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
_PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
+ PyObject *exc_value = exc_info->exc_value;
+ if (exc_value == NULL || exc_value == Py_None) {
+ *value = NULL;
+ *type = NULL;
+ *tb = NULL;
+ } else {
+ *value = exc_value;
+ Py_INCREF(*value);
+ *type = (PyObject*) Py_TYPE(exc_value);
+ Py_INCREF(*type);
+ *tb = PyException_GetTraceback(exc_value);
+ }
+ #elif CYTHON_USE_EXC_INFO_STACK
+ _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate);
*type = exc_info->exc_type;
*value = exc_info->exc_value;
*tb = exc_info->exc_traceback;
- #else
+ Py_XINCREF(*type);
+ Py_XINCREF(*value);
+ Py_XINCREF(*tb);
+ #else
*type = tstate->exc_type;
*value = tstate->exc_value;
*tb = tstate->exc_traceback;
- #endif
Py_XINCREF(*type);
Py_XINCREF(*value);
Py_XINCREF(*tb);
+ #endif
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
+ #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
+ _PyErr_StackItem *exc_info = tstate->exc_info;
+ PyObject *tmp_value = exc_info->exc_value;
+ exc_info->exc_value = value;
+ Py_XDECREF(tmp_value);
+ // TODO: avoid passing these at all
+ Py_XDECREF(type);
+ Py_XDECREF(tb);
+ #else
PyObject *tmp_type, *tmp_value, *tmp_tb;
-
#if CYTHON_USE_EXC_INFO_STACK
_PyErr_StackItem *exc_info = tstate->exc_info;
tmp_type = exc_info->exc_type;
@@ -524,6 +567,7 @@
Py_XDECREF(tmp_type);
Py_XDECREF(tmp_value);
Py_XDECREF(tmp_tb);
+ #endif
}
#endif
@@ -543,8 +587,22 @@
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
PyObject *tmp_type, *tmp_value, *tmp_tb;
-
- #if CYTHON_USE_EXC_INFO_STACK
+ #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4
+ _PyErr_StackItem *exc_info = tstate->exc_info;
+ tmp_value = exc_info->exc_value;
+ exc_info->exc_value = *value;
+ if (tmp_value == NULL || tmp_value == Py_None) {
+ Py_XDECREF(tmp_value);
+ tmp_value = NULL;
+ tmp_type = NULL;
+ tmp_tb = NULL;
+ } else {
+ // TODO: avoid swapping these at all
+ tmp_type = (PyObject*) Py_TYPE(tmp_value);
+ Py_INCREF(tmp_type);
+ tmp_tb = PyException_GetTraceback(tmp_value);
+ }
+ #elif CYTHON_USE_EXC_INFO_STACK
_PyErr_StackItem *exc_info = tstate->exc_info;
tmp_type = exc_info->exc_type;
tmp_value = exc_info->exc_value;
@@ -553,7 +611,7 @@
exc_info->exc_type = *type;
exc_info->exc_value = *value;
exc_info->exc_traceback = *tb;
- #else
+ #else
tmp_type = tstate->exc_type;
tmp_value = tstate->exc_value;
tmp_tb = tstate->exc_traceback;
@@ -561,7 +619,7 @@
tstate->exc_type = *type;
tstate->exc_value = *value;
tstate->exc_traceback = *tb;
- #endif
+ #endif
*type = tmp_type;
*value = tmp_value;

View file

@ -1,73 +0,0 @@
https://github.com/cython/cython/commit/2a0d703048db48b31cc7ed84d8fe6aff46c60469
diff -ruN a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
--- a/Cython/Compiler/ExprNodes.py 2023-05-24 17:32:13.000000000 +0900
+++ b/Cython/Compiler/ExprNodes.py 2023-07-02 12:31:46.317048164 +0900
@@ -5797,8 +5797,6 @@
if self.is_temp and self.type.is_reference:
self.type = PyrexTypes.CFakeReferenceType(self.type.ref_base_type)
- # Called in 'nogil' context?
- self.nogil = env.nogil
if (self.nogil and
func_type.exception_check and
func_type.exception_check != '+'):
@@ -5920,6 +5918,7 @@
code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result())
elif func_type.is_cfunction:
+ nogil = not code.funcstate.gil_owned
if self.has_optional_args:
actual_nargs = len(self.args)
expected_nargs = len(func_type.args) - func_type.optional_arg_count
@@ -5947,7 +5946,7 @@
if exc_val is not None:
exc_checks.append("%s == %s" % (self.result(), func_type.return_type.cast_code(exc_val)))
if exc_check:
- if self.nogil:
+ if nogil:
exc_checks.append("__Pyx_ErrOccurredWithGIL()")
else:
exc_checks.append("PyErr_Occurred()")
@@ -5965,7 +5964,7 @@
if func_type.exception_check == '+':
translate_cpp_exception(code, self.pos, '%s%s;' % (lhs, rhs),
self.result() if self.type.is_pyobject else None,
- func_type.exception_value, self.nogil)
+ func_type.exception_value, nogil)
else:
if exc_checks:
goto_error = code.error_goto_if(" && ".join(exc_checks), self.pos)
diff -ruN a/Cython/Compiler/UtilNodes.py b/Cython/Compiler/UtilNodes.py
--- a/Cython/Compiler/UtilNodes.py 2023-05-24 17:32:13.000000000 +0900
+++ b/Cython/Compiler/UtilNodes.py 2023-07-02 12:32:49.046659801 +0900
@@ -10,7 +10,7 @@
from . import ExprNodes
from .Nodes import Node
from .ExprNodes import AtomicExprNode
-from .PyrexTypes import c_ptr_type
+from .PyrexTypes import c_ptr_type, c_bint_type
class TempHandle(object):
@@ -357,3 +357,20 @@
def generate_result_code(self, code):
self.result_ref.result_code = self.result()
self.body.generate_execution_code(code)
+
+
+class HasGilNode(AtomicExprNode):
+ """
+ Simple node that evaluates to 0 or 1 depending on whether we're
+ in a nogil context
+ """
+ type = c_bint_type
+
+ def analyse_types(self, env):
+ return self
+
+ def generate_result_code(self, code):
+ self.has_gil = code.funcstate.gil_owned
+
+ def calculate_result_code(self):
+ return "1" if self.has_gil else "0"

View file

@ -1,16 +1,14 @@
# Python module not linking to libpython
%global _disable_ld_no_undefined 1
%bcond_with python2
%bcond_with check
%define tarname cython
%define py2dir python2
%global optflags %optflags -O3
Summary: Language for writing C extensions to Python
Name: python-cython
Version: 0.29.36
Version: 3.0.0
Release: 1
License: Python
Group: Development/Python
@ -18,13 +16,11 @@ Url: http://www.cython.org
Source0: https://github.com/cython/cython/archive/%{version}.tar.gz?/cython-%{version}.tar.gz
Source1: %{name}.rpmlintrc
Patch0: cython-0.29.28-missing-header.patch
Patch1: cython-CPython-3.11a4.patch
Patch2: cython-gil.patch
BuildRequires: dos2unix
%if %{with check}
BuildRequires: gdb
BuildRequires: gomp-devel
BuildRequires: python-numpy-devel
BuildRequires: python3-numpy-devel
%endif
%description
@ -57,76 +53,22 @@ edge functionality and optimizations.
#--------------------------------------------------------------------
%if %{with python2}
%package -n python2-cython
%py2_migration_meta python2-cython
Summary: Language for writing C extensions to Python
Group: Development/Python
BuildRequires: pkgconfig(python2)
BuildRequires: python2-setuptools
%description -n python2-cython
Cython is a language that facilitates the writing of C extensions for
the Python language. It is based on Pyrex, but provides more cutting
edge functionality and optimizations.
%files -n python2-cython
%{_bindir}/cython2
%{_bindir}/cygdb2
%{py2_platsitedir}/Cython
%{py2_platsitedir}/Cython-%{version}-*.egg-info
%{py2_platsitedir}/cython*
%{py2_platsitedir}/pyximport
%endif
#--------------------------------------------------------------------
%prep
%autosetup -p1 -n %{tarname}-%{version}
%if %{with python2}
rm -rf %{py2dir}
mkdir %{py2dir}
tar -xvf %{SOURCE0} -C %{py2dir}
find %{py2dir} -name '*.py' | xargs sed -i '1s|^#!python|#!python2|'
%endif
find -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python}|'
find -name '*.py' | xargs sed -i '1s|^#!python|#!%{__python3}|'
%build
%setup_compile_flags
CFLAGS="%{optflags}" %{__python3} setup.py build
%if %{with python2}
cd %{py2dir}/%{tarname}-%{version}
CFLAGS="%{optflags}" %{__python2} setup.py build
cd -
%endif
%install
# Must do the python2 install first because the scripts in /usr/bin are
# overwritten with every setup.py install (and we want the python3 version
# to be the default).
%if %{with python2}
cd %{py2dir}/%{tarname}-%{version}
%{__python2} setup.py install --skip-build --root %{buildroot}
mv %{buildroot}/usr/bin/cython %{buildroot}/usr/bin/cython2
mv %{buildroot}/usr/bin/cygdb %{buildroot}/usr/bin/cygdb2
rm -rf %{buildroot}%{python2_sitelib}/setuptools/tests
cd -
%endif
%{__python3} setup.py install -O1 --skip-build --root %{buildroot}
rm -rf %{buildroot}%{python3_sitelib}/setuptools/tests
rm -rf %{buildroot}/%{python3_sitearch}/__pycache__/
%if %{with check}
%check
python runtests.py
python3 runtests.py
%if %{with python2}
cd %{py2dir}/%{tarname}-%{version}
python2 setup.py test
cd -
%endif
%endif