Commit 3fe70aca authored by Victor Stinner's avatar Victor Stinner Committed by Jason Madden

Add Python 3.11 beta 3 support

Co-Authored-By: default avatarPetr Viktorin <encukou@gmail.com>
parent e29bd2ee
...@@ -244,6 +244,9 @@ def cythonize1(ext): ...@@ -244,6 +244,9 @@ def cythonize1(ext):
'infer_types': True, 'infer_types': True,
'nonecheck': False, 'nonecheck': False,
}, },
compile_time_env={
'PY39B1': sys.hexversion >= 0x030900B1,
},
# 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
......
...@@ -52,35 +52,48 @@ cdef inline void greenlet_init(): ...@@ -52,35 +52,48 @@ cdef inline void greenlet_init():
PyGreenlet_Import() PyGreenlet_Import()
_greenlet_imported = True _greenlet_imported = True
cdef extern from "Python.h": ctypedef object CodeType
ctypedef class types.CodeType [object PyCodeObject]: IF PY39B1:
pass ctypedef object FrameType
cdef extern from "frameobject.h": 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
ctypedef class types.FrameType [object PyFrameObject]: # We can't declare this in the object as an object, because it's
cdef CodeType f_code # allowed to be NULL, and Cython can't handle that.
# Accessing the f_lineno directly doesn't work. There is an accessor # We have to go through the python machinery to get a
# function, PyFrame_GetLineNumber that is needed to turn the raw line number # proper None instead, or use a function.
# into the executing line number. cdef void* f_back
# cdef int f_lineno
# 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 an inline function.
cdef void* f_back
cdef extern from "frameobject.h":
int PyFrame_GetLineNumber(FrameType frame) int PyFrame_GetLineNumber(FrameType frame)
@cython.nonecheck(False) @cython.nonecheck(False)
cdef inline FrameType get_f_back(FrameType frame): cdef inline FrameType get_f_back(FrameType frame):
if frame.f_back != NULL: IF PY39B1:
return <FrameType>frame.f_back f_back = PyFrame_GetBack(frame)
ELSE:
f_back = frame.f_back
if f_back != NULL:
return <FrameType>f_back
cdef inline int get_f_lineno(FrameType frame): cdef inline int get_f_lineno(FrameType frame):
return PyFrame_GetLineNumber(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()
cdef class SpawnedLink: cdef class SpawnedLink:
......
...@@ -58,6 +58,7 @@ locals()['get_generic_parent'] = lambda s: s.parent ...@@ -58,6 +58,7 @@ locals()['get_generic_parent'] = lambda s: s.parent
# Frame access # Frame access
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_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
...@@ -157,7 +158,7 @@ def _extract_stack(limit): ...@@ -157,7 +158,7 @@ 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 = frame.f_code older_Frame.f_code = get_f_code(frame)
older_Frame.f_lineno = get_f_lineno(frame) # pylint:disable=undefined-variable older_Frame.f_lineno = get_f_lineno(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
......
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