Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using DEF statements in Cython, as they are deprecated. #1915

Merged
merged 1 commit into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions docs/changes/1910.misc
@@ -1,7 +1 @@
Use a more modern setuptools build backend. There have also been some
other build related changes:

- Enable memory leak checking for Python 3.11.
..
TODO: Uncomment this once done
- Stop using the deprecated 'DEF' construct in Cython files. See https://github.com/cython/cython/issues/4310
Use a more modern setuptools build backend.
4 changes: 4 additions & 0 deletions docs/changes/Unknown.misc
@@ -0,0 +1,4 @@
Stop using the deprecated 'DEF' construct in Cython files. See
https://github.com/cython/cython/issues/4310

Enable memory leak checking for Python 3.11.
41 changes: 27 additions & 14 deletions src/gevent/libev/corecext.pyx
Expand Up @@ -323,7 +323,13 @@ cdef public class callback [object PyGeventCallbackObject, type PyGeventCallback
def _format(self):
return ''

DEF CALLBACK_CHECK_COUNT = 50
# See comments in cares.pyx about DEF constants and when to use
# what kind.
cdef extern from *:
"""
#define CALLBACK_CHECK_COUNT 50
"""
int CALLBACK_CHECK_COUNT

@cython.final
@cython.internal
Expand Down Expand Up @@ -803,19 +809,26 @@ from gevent._interfaces import ICallback
classImplements(loop, ILoop)
classImplements(callback, ICallback)

# XXX: DEF is deprecated. See _setuputils.py for info.
# about readonly _flags attribute:
# bit #1 set if object owns Python reference to itself (Py_INCREF was
# called and we must call Py_DECREF later)
DEF FLAG_WATCHER_OWNS_PYREF = 1 << 0 # 0x1
# bit #2 set if ev_unref() was called and we must call ev_ref() later
DEF FLAG_WATCHER_NEEDS_EVREF = 1 << 1 # 0x2
# bit #3 set if user wants to call ev_unref() before start()
DEF FLAG_WATCHER_UNREF_BEFORE_START = 1 << 2 # 0x4
# bits 2 and 3 are *both* set when we are active, but the user
# request us not to be ref'd anymore. We unref us (because going active will
# ref us) and then make a note of this in the future
DEF FLAG_WATCHER_MASK_UNREF_NEEDS_REF = 0x6

cdef extern from *:
"""
#define FLAG_WATCHER_OWNS_PYREF (1 << 0) /* 0x1 */
#define FLAG_WATCHER_NEEDS_EVREF (1 << 1) /* 0x2 */
#define FLAG_WATCHER_UNREF_BEFORE_START (1 << 2) /* 0x4 */
#define FLAG_WATCHER_MASK_UNREF_NEEDS_REF 0x6
"""
# about readonly _flags attribute:
# bit #1 set if object owns Python reference to itself (Py_INCREF was
# called and we must call Py_DECREF later)
unsigned int FLAG_WATCHER_OWNS_PYREF
# bit #2 set if ev_unref() was called and we must call ev_ref() later
unsigned int FLAG_WATCHER_NEEDS_EVREF
# bit #3 set if user wants to call ev_unref() before start()
unsigned int FLAG_WATCHER_UNREF_BEFORE_START
# bits 2 and 3 are *both* set when we are active, but the user
# request us not to be ref'd anymore. We unref us (because going active will
# ref us) and then make a note of this in the future
unsigned int FLAG_WATCHER_MASK_UNREF_NEEDS_REF


cdef void _python_incref(watcher self):
Expand Down
21 changes: 17 additions & 4 deletions src/gevent/resolver/cares.pyx
Expand Up @@ -35,11 +35,24 @@ else:
string_types = __builtins__.basestring,
text_type = __builtins__.unicode

# XXX: DEF is deprecated. See _setuputils.py for info.
DEF TIMEOUT = 1
# These three constants used to be DEF, but the DEF construct
# is deprecated in Cython. Using a cdef extern, the generated
# C code refers to the symbol (DEF would have inlined the value).
# That's great when we're strictly in a C context, but for passing to
# Python, it means we do a runtime translation from the C int to the
# Python int. That is avoided if we use a cdef constant. TIMEOUT
# is the only one that interacts with Python, but not in a performance-sensitive
# way, so runtime translation is fine to keep it consistent.
cdef extern from *:
"""
#define TIMEOUT 1
#define EV_READ 1
#define EV_WRITE 2
"""
int TIMEOUT
int EV_READ
int EV_WRITE

DEF EV_READ = 1
DEF EV_WRITE = 2

cdef extern from *:
"""
Expand Down