diff --git a/docs/changes/1910.misc b/docs/changes/1910.misc index 81a12c0b2..cc0d6eff7 100644 --- a/docs/changes/1910.misc +++ b/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. diff --git a/docs/changes/Unknown.misc b/docs/changes/Unknown.misc new file mode 100644 index 000000000..d38fc3559 --- /dev/null +++ b/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. diff --git a/src/gevent/libev/corecext.pyx b/src/gevent/libev/corecext.pyx index 28bb12896..4d814b6d8 100644 --- a/src/gevent/libev/corecext.pyx +++ b/src/gevent/libev/corecext.pyx @@ -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 @@ -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): diff --git a/src/gevent/resolver/cares.pyx b/src/gevent/resolver/cares.pyx index 24f261a16..db4b70653 100644 --- a/src/gevent/resolver/cares.pyx +++ b/src/gevent/resolver/cares.pyx @@ -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 *: """