Commit d06e0459 authored by Jason Madden's avatar Jason Madden

Get compiling again without (new) deprecation warnings from Cython.

All tests pass locally on 3.10 except one, reported earlier: test_no_refcycle_through_target (gevent.tests.test__threading_2.ThreadTests)
And a new one that is similar:    test_no_refcycle_through_target (__main__.ThreadTests)

I haven't tried to debug that yet.
parent e04cff4b
...@@ -249,9 +249,19 @@ def cythonize1(ext): ...@@ -249,9 +249,19 @@ def cythonize1(ext):
# of Pyrex defines. Taking this kind of decision based on # of Pyrex defines. Taking this kind of decision based on
# the runtime environment of the build is wrong, it needs # the runtime environment of the build is wrong, it needs
# to be taken at C compile time." # to be taken at C compile time."
compile_time_env={ #
'PY39B1': sys.hexversion >= 0x030900B1, # They also say, "The 'IF' statement is deprecated and
}, # will be removed in a future Cython version. Consider
# using runtime conditions or C macros instead. See
# https://github.com/cython/cython/issues/4310"
#
# And: " The 'DEF' statement is deprecated and will be
# removed in a future Cython version. Consider using
# global variables, constants, and in-place literals
# instead."
#compile_time_env={
#
#},
# The common_utility_include_dir (not well documented) # The common_utility_include_dir (not well documented)
# causes Cython to emit separate files for much of the # causes Cython to emit separate files for much of the
# static support code. Each of the modules then includes # static support code. Each of the modules then includes
......
...@@ -450,6 +450,7 @@ def run_setup(ext_modules): ...@@ -450,6 +450,7 @@ def run_setup(ext_modules):
"Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: MacOS :: MacOS X", "Operating System :: MacOS :: MacOS X",
......
#ifndef _COMPAT_H
#define _COMPAT_H
/**
* Compatibility helpers for things that are better handled at C
* compilation time rather than Cython code generation time.
*/
#include <Python.h>
#ifdef __cplusplus
extern "C" {
#endif
#if PY_VERSION_HEX >= 0x30B00A6
# define GEVENT_PY311 1
/* _PyInterpreterFrame moved to the internal C API in Python 3.11 */
# include <internal/pycore_frame.h>
#else
# define GEVENT_PY311 0
# define _PyCFrame CFrame
#endif
/* FrameType and CodeType changed a lot in 3.11. */
#if GREENLET_PY311
typedef PyObject PyFrameObject;
#else
#include <frameobject.h>
#if PY_MAJOR_VERSION < 3 || PY_MINOR_VERSION < 9
/* these were added in 3.9, though they officially became stable in 3.10 */
static void* PyFrame_GetBack(PyFrameObject* frame)
{
return (PyObject*)((PyFrameObject*)frame)->f_back;
}
static PyObject* PyFrame_GetCode(PyFrameObject* frame)
{
return (PyObject*)((PyFrameObject*)frame)->f_code;
}
#endif /* support 3.8 and below. */
#endif
#ifdef __cplusplus
}
#endif
#endif /* _COMPAT_H */
...@@ -54,45 +54,19 @@ cdef inline void greenlet_init(): ...@@ -54,45 +54,19 @@ cdef inline void greenlet_init():
ctypedef object CodeType ctypedef object CodeType
IF PY39B1: # XXX: Move all of this to C includes. Pyrex defines are not appropriate, according to the Cython devs. cdef extern from "_compat.h":
ctypedef object FrameType
cdef extern from "Python.h":
CodeType PyFrame_GetCode(FrameType frame)
void* PyFrame_GetBack(FrameType frame)
ELSE:
cdef extern from "frameobject.h":
ctypedef class types.FrameType [object PyFrameObject]:
# We don't have PyFrame_GetCode, need to use the pointer directly
cdef CodeType f_code
# We can't declare this in the object as an object, because it's
# allowed to be NULL, and Cython can't handle that.
# We have to go through the python machinery to get a
# proper None instead, or use a function.
cdef void* f_back
cdef extern from "frameobject.h":
int PyFrame_GetLineNumber(FrameType frame) int PyFrame_GetLineNumber(FrameType frame)
CodeType PyFrame_GetCode(FrameType frame)
void* PyFrame_GetBack(FrameType frame)
ctypedef class types.FrameType [object PyFrameObject]:
pass
@cython.nonecheck(False) @cython.nonecheck(False)
cdef inline FrameType get_f_back(FrameType frame): cdef inline FrameType get_f_back(FrameType frame):
IF PY39B1: f_back = PyFrame_GetBack(frame)
f_back = PyFrame_GetBack(frame)
ELSE:
f_back = frame.f_back
if f_back != NULL: if f_back != NULL:
return <FrameType>f_back return <FrameType>f_back
cdef inline int get_f_lineno(FrameType frame):
return PyFrame_GetLineNumber(frame)
cdef inline CodeType get_f_code(FrameType frame):
IF PY39B1:
return PyFrame_GetCode(frame)
ELSE:
return frame.f_code
cdef void _init() cdef void _init()
...@@ -122,7 +96,7 @@ cdef class _Frame: ...@@ -122,7 +96,7 @@ cdef class _Frame:
newest_Frame=_Frame, newest_Frame=_Frame,
newer_Frame=_Frame, newer_Frame=_Frame,
older_Frame=_Frame) older_Frame=_Frame)
cdef inline _Frame _extract_stack(int limit) cdef _Frame _extract_stack(int limit)
cdef class Greenlet(greenlet): cdef class Greenlet(greenlet):
cdef readonly object value cdef readonly object value
......
...@@ -56,9 +56,10 @@ locals()['get_my_hub'] = lambda s: s.parent ...@@ -56,9 +56,10 @@ locals()['get_my_hub'] = lambda s: s.parent
locals()['get_generic_parent'] = lambda s: s.parent locals()['get_generic_parent'] = lambda s: s.parent
# Frame access # Frame access
locals()['PyFrame_GetCode'] = lambda frame: frame.f_code
locals()['PyFrame_GetLineNumber'] = lambda frame: frame.f_lineno
locals()['get_f_back'] = lambda frame: frame.f_back locals()['get_f_back'] = lambda frame: frame.f_back
locals()['get_f_lineno'] = lambda frame: frame.f_lineno
locals()['get_f_code'] = lambda frame: frame.f_code
if _PYPY: if _PYPY:
import _continuation # pylint:disable=import-error import _continuation # pylint:disable=import-error
...@@ -158,8 +159,8 @@ def _extract_stack(limit): ...@@ -158,8 +159,8 @@ def _extract_stack(limit):
# Arguments are always passed to the constructor as Python objects, # Arguments are always passed to the constructor as Python objects,
# meaning we wind up boxing the f_lineno just to unbox it if we pass it. # meaning we wind up boxing the f_lineno just to unbox it if we pass it.
# It's faster to simply assign once the object is created. # It's faster to simply assign once the object is created.
older_Frame.f_code = get_f_code(frame) older_Frame.f_code = PyFrame_GetCode(frame) # pylint:disable=undefined-variable
older_Frame.f_lineno = get_f_lineno(frame) # pylint:disable=undefined-variable older_Frame.f_lineno = PyFrame_GetLineNumber(frame) # pylint:disable=undefined-variable
if newer_Frame is not None: if newer_Frame is not None:
newer_Frame.f_back = older_Frame newer_Frame.f_back = older_Frame
newer_Frame = older_Frame newer_Frame = older_Frame
......
...@@ -803,6 +803,7 @@ from gevent._interfaces import ICallback ...@@ -803,6 +803,7 @@ from gevent._interfaces import ICallback
classImplements(loop, ILoop) classImplements(loop, ILoop)
classImplements(callback, ICallback) classImplements(callback, ICallback)
# XXX: DEF is deprecated. See _setuputils.py for info.
# about readonly _flags attribute: # about readonly _flags attribute:
# bit #1 set if object owns Python reference to itself (Py_INCREF was # bit #1 set if object owns Python reference to itself (Py_INCREF was
# called and we must call Py_DECREF later) # called and we must call Py_DECREF later)
......
...@@ -35,6 +35,7 @@ else: ...@@ -35,6 +35,7 @@ else:
string_types = __builtins__.basestring, string_types = __builtins__.basestring,
text_type = __builtins__.unicode text_type = __builtins__.unicode
# XXX: DEF is deprecated. See _setuputils.py for info.
DEF TIMEOUT = 1 DEF TIMEOUT = 1
DEF EV_READ = 1 DEF EV_READ = 1
......
...@@ -427,8 +427,13 @@ class TestCase(TestCaseMetaClass("NewBase", ...@@ -427,8 +427,13 @@ class TestCase(TestCaseMetaClass("NewBase",
self.assertEqual(sig.args, gevent_sig.args, func_name) self.assertEqual(sig.args, gevent_sig.args, func_name)
# The next three might not actually matter? # The next three might not actually matter?
self.assertEqual(sig.varargs, gevent_sig.varargs, func_name) self.assertEqual(sig.varargs, gevent_sig.varargs, func_name)
self.assertEqual(sig.keywords, gevent_sig.keywords, func_name)
self.assertEqual(sig.defaults, gevent_sig.defaults, func_name) self.assertEqual(sig.defaults, gevent_sig.defaults, func_name)
if hasattr(sig, 'keywords'): # the old version
self.assertEqual(sig.keywords, gevent_sig.keywords, func_name)
else:
# The new hotness
self.assertEqual(sig.kwonlyargs, gevent_sig.kwonlyargs)
self.assertEqual(sig.kwonlydefaults, gevent_sig.kwonlydefaults)
# Should deal with others: https://docs.python.org/3/library/inspect.html#inspect.getfullargspec # Should deal with others: https://docs.python.org/3/library/inspect.html#inspect.getfullargspec
def assertEqualFlakyRaceCondition(self, a, b): def assertEqualFlakyRaceCondition(self, a, b):
......
[tox] [tox]
envlist = envlist =
py27,py36,py37,py38,py39,py310,py27-cffi,pypy,pypy3,py27-libuv,lint py27,py36,py37,py38,py39,py310,py311,py27-cffi,pypy,pypy3,py27-libuv,lint
[testenv] [testenv]
usedevelop = true usedevelop = true
......
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