Skip to content

Commit

Permalink
Mark functions as noexcept to ensure cython 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Matus Valo authored and Matus Valo committed Mar 18, 2023
1 parent 7783f1c commit ebe1ee1
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions uvloop/dns.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ cdef class AddrInfo:
uv.uv_freeaddrinfo(self.data) # returns void
self.data = NULL

cdef void set_data(self, system.addrinfo *data):
cdef void set_data(self, system.addrinfo *data) noexcept:
self.data = data

cdef unpack(self):
Expand Down Expand Up @@ -326,7 +326,7 @@ cdef class AddrInfo:
return result

@staticmethod
cdef int isinstance(object other):
cdef int isinstance(object other) noexcept:
return type(other) is AddrInfo


Expand Down Expand Up @@ -415,7 +415,7 @@ cdef _intenum_converter(value, enum_klass):


cdef void __on_addrinfo_resolved(uv.uv_getaddrinfo_t *resolver,
int status, system.addrinfo *res) with gil:
int status, system.addrinfo *res) noexcept with gil:

if resolver.data is NULL:
aio_logger.error(
Expand Down Expand Up @@ -446,7 +446,7 @@ cdef void __on_addrinfo_resolved(uv.uv_getaddrinfo_t *resolver,
cdef void __on_nameinfo_resolved(uv.uv_getnameinfo_t* req,
int status,
const char* hostname,
const char* service) with gil:
const char* service) noexcept with gil:
cdef:
NameInfoRequest request = <NameInfoRequest> req.data
Loop loop = request.loop
Expand Down
2 changes: 1 addition & 1 deletion uvloop/errors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cdef __convert_python_error(int uverr):
return exc(oserr, __strerr(oserr))


cdef int __convert_socket_error(int uverr):
cdef int __convert_socket_error(int uverr) noexcept:
cdef int sock_err = 0

if uverr == uv.UV_EAI_ADDRFAMILY:
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/async_.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cdef class UVAsync(UVHandle):
return handle


cdef void __uvasync_callback(uv.uv_async_t* handle) with gil:
cdef void __uvasync_callback(uv.uv_async_t* handle) noexcept with gil:
if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVAsync callback") == 0:
return

Expand Down
4 changes: 2 additions & 2 deletions uvloop/handles/basetransport.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ cdef class UVBaseTransport(UVSocketHandle):
# === overloads ===

cdef _new_socket(self)
cdef size_t _get_write_buffer_size(self)
cdef size_t _get_write_buffer_size(self) noexcept

cdef bint _is_reading(self)
cdef bint _is_reading(self) noexcept
cdef _start_reading(self)
cdef _stop_reading(self)
4 changes: 2 additions & 2 deletions uvloop/handles/basetransport.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cdef class UVBaseTransport(UVSocketHandle):

self._closing = 0

cdef size_t _get_write_buffer_size(self):
cdef size_t _get_write_buffer_size(self) noexcept:
return 0

cdef inline _schedule_call_connection_made(self):
Expand Down Expand Up @@ -211,7 +211,7 @@ cdef class UVBaseTransport(UVSocketHandle):
self._extra_info = {}
self._extra_info[name] = obj

cdef bint _is_reading(self):
cdef bint _is_reading(self) noexcept:
raise NotImplementedError

cdef _start_reading(self):
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/check.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cdef class UVCheck(UVHandle):
return handle


cdef void cb_check_callback(uv.uv_check_t* handle) with gil:
cdef void cb_check_callback(uv.uv_check_t* handle) noexcept with gil:
if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVCheck callback") == 0:
return

Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/fsevent.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ cdef class UVFSEvent(UVHandle):


cdef void __uvfsevent_callback(uv.uv_fs_event_t* handle, const char *filename,
int events, int status) with gil:
int events, int status) noexcept with gil:
if __ensure_handle_data(
<uv.uv_handle_t*>handle, "UVFSEvent callback"
) == 0:
Expand Down
8 changes: 4 additions & 4 deletions uvloop/handles/handle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ cdef class UVSocketHandle(UVHandle):


cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
const char* handle_ctx):
const char* handle_ctx) noexcept:

cdef Loop loop

Expand Down Expand Up @@ -335,7 +335,7 @@ cdef inline bint __ensure_handle_data(uv.uv_handle_t* handle,
return 1


cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) noexcept with gil:
cdef UVHandle h

if handle.data is NULL:
Expand Down Expand Up @@ -363,14 +363,14 @@ cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
Py_DECREF(h) # Was INCREFed in UVHandle._close


cdef void __close_all_handles(Loop loop):
cdef void __close_all_handles(Loop loop) noexcept:
uv.uv_walk(loop.uvloop,
__uv_walk_close_all_handles_cb,
<void*>loop) # void


cdef void __uv_walk_close_all_handles_cb(
uv.uv_handle_t* handle, void* arg) with gil:
uv.uv_handle_t* handle, void* arg) noexcept with gil:

cdef:
Loop loop = <Loop>arg
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/idle.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cdef class UVIdle(UVHandle):
return handle


cdef void cb_idle_callback(uv.uv_idle_t* handle) with gil:
cdef void cb_idle_callback(uv.uv_idle_t* handle) noexcept with gil:
if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVIdle callback") == 0:
return

Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/pipe.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ cdef class _PipeConnectRequest(UVRequest):
addr,
__pipe_connect_callback)

cdef void __pipe_connect_callback(uv.uv_connect_t* req, int status) with gil:
cdef void __pipe_connect_callback(uv.uv_connect_t* req, int status) noexcept with gil:
cdef:
_PipeConnectRequest wrapper
UnixTransport transport
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/poll.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cdef class UVPoll(UVHandle):
cdef inline _poll_start(self, int flags)
cdef inline _poll_stop(self)

cdef int is_active(self)
cdef int is_active(self) noexcept

cdef is_reading(self)
cdef is_writing(self)
Expand Down
4 changes: 2 additions & 2 deletions uvloop/handles/poll.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cdef class UVPoll(UVHandle):
handle._init(loop, fd)
return handle

cdef int is_active(self):
cdef int is_active(self) noexcept:
return (self.reading_handle is not None or
self.writing_handle is not None)

Expand Down Expand Up @@ -191,7 +191,7 @@ cdef class UVPoll(UVHandle):


cdef void __on_uvpoll_event(uv.uv_poll_t* handle,
int status, int events) with gil:
int status, int events) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVPoll callback") == 0:
return
Expand Down
4 changes: 2 additions & 2 deletions uvloop/handles/process.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ cdef __process_convert_fileno(object obj):

cdef void __uvprocess_on_exit_callback(uv.uv_process_t *handle,
int64_t exit_status,
int term_signal) with gil:
int term_signal) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>handle,
"UVProcess exit callback") == 0:
Expand Down Expand Up @@ -761,5 +761,5 @@ cdef __socketpair():
return fds[0], fds[1]


cdef void __uv_close_process_handle_cb(uv.uv_handle_t* handle) with gil:
cdef void __uv_close_process_handle_cb(uv.uv_handle_t* handle) noexcept with gil:
PyMem_RawFree(handle)
20 changes: 10 additions & 10 deletions uvloop/handles/stream.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ cdef class UVStream(UVBaseTransport):
cdef inline _close_on_read_error(self):
self.__read_error_close = 1

cdef bint _is_reading(self):
cdef bint _is_reading(self) noexcept:
return self.__reading

cdef _start_reading(self):
Expand Down Expand Up @@ -578,7 +578,7 @@ cdef class UVStream(UVBaseTransport):

self._maybe_resume_protocol()

cdef size_t _get_write_buffer_size(self):
cdef size_t _get_write_buffer_size(self) noexcept:
if self._handle is NULL:
return 0
return ((<uv.uv_stream_t*>self._handle).write_queue_size +
Expand Down Expand Up @@ -723,7 +723,7 @@ cdef class UVStream(UVBaseTransport):


cdef void __uv_stream_on_shutdown(uv.uv_shutdown_t* req,
int status) with gil:
int status) noexcept with gil:

# callback for uv_shutdown

Expand Down Expand Up @@ -752,7 +752,7 @@ cdef void __uv_stream_on_shutdown(uv.uv_shutdown_t* req,


cdef inline bint __uv_stream_on_read_common(UVStream sc, Loop loop,
ssize_t nread):
ssize_t nread) noexcept:
if sc._closed:
# The stream was closed, there is no reason to
# do any work now.
Expand Down Expand Up @@ -813,7 +813,7 @@ cdef inline bint __uv_stream_on_read_common(UVStream sc, Loop loop,

cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
ssize_t nread,
const uv.uv_buf_t* buf):
const uv.uv_buf_t* buf) noexcept:
cdef:
UVStream sc = <UVStream>stream.data
Loop loop = sc._loop
Expand Down Expand Up @@ -841,7 +841,7 @@ cdef inline void __uv_stream_on_read_impl(uv.uv_stream_t* stream,
sc._fatal_error(exc, False)


cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):
cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status) noexcept:
cdef:
_StreamWriteContext ctx = <_StreamWriteContext> req.data
UVStream stream = <UVStream>ctx.stream
Expand Down Expand Up @@ -874,7 +874,7 @@ cdef inline void __uv_stream_on_write_impl(uv.uv_write_t* req, int status):

cdef void __uv_stream_on_read(uv.uv_stream_t* stream,
ssize_t nread,
const uv.uv_buf_t* buf) with gil:
const uv.uv_buf_t* buf) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>stream,
"UVStream read callback") == 0:
Expand All @@ -884,7 +884,7 @@ cdef void __uv_stream_on_read(uv.uv_stream_t* stream,
__uv_stream_on_read_impl(stream, nread, buf)


cdef void __uv_stream_on_write(uv.uv_write_t* req, int status) with gil:
cdef void __uv_stream_on_write(uv.uv_write_t* req, int status) noexcept with gil:

if UVLOOP_DEBUG:
if req.data is NULL:
Expand All @@ -899,7 +899,7 @@ cdef void __uv_stream_on_write(uv.uv_write_t* req, int status) with gil:

cdef void __uv_stream_buffered_alloc(uv.uv_handle_t* stream,
size_t suggested_size,
uv.uv_buf_t* uvbuf) with gil:
uv.uv_buf_t* uvbuf) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>stream,
"UVStream alloc buffer callback") == 0:
Expand Down Expand Up @@ -947,7 +947,7 @@ cdef void __uv_stream_buffered_alloc(uv.uv_handle_t* stream,

cdef void __uv_stream_buffered_on_read(uv.uv_stream_t* stream,
ssize_t nread,
const uv.uv_buf_t* buf) with gil:
const uv.uv_buf_t* buf) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>stream,
"UVStream buffered read callback") == 0:
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/streamserver.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ cdef class UVStreamServer(UVSocketHandle):


cdef void __uv_streamserver_on_listen(uv.uv_stream_t* handle,
int status) with gil:
int status) noexcept with gil:

# callback for uv_listen

Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/tcp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ cdef class _TCPConnectRequest(UVRequest):
raise exc


cdef void __tcp_connect_callback(uv.uv_connect_t* req, int status) with gil:
cdef void __tcp_connect_callback(uv.uv_connect_t* req, int status) noexcept with gil:
cdef:
_TCPConnectRequest wrapper
TCPTransport transport
Expand Down
2 changes: 1 addition & 1 deletion uvloop/handles/timer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cdef class UVTimer(UVHandle):
return handle


cdef void __uvtimer_callback(uv.uv_timer_t* handle) with gil:
cdef void __uvtimer_callback(uv.uv_timer_t* handle) noexcept with gil:
if __ensure_handle_data(<uv.uv_handle_t*>handle, "UVTimer callback") == 0:
return

Expand Down
8 changes: 4 additions & 4 deletions uvloop/handles/udp.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ cdef class UDPTransport(UVBaseTransport):
exc = convert_error(err)
raise exc

cdef size_t _get_write_buffer_size(self):
cdef size_t _get_write_buffer_size(self) noexcept:
if self._handle is NULL:
return 0
return (<uv.uv_udp_t*>self._handle).send_queue_size

cdef bint _is_reading(self):
cdef bint _is_reading(self) noexcept:
return self.__receiving

cdef _start_reading(self):
Expand Down Expand Up @@ -309,7 +309,7 @@ cdef void __uv_udp_on_receive(uv.uv_udp_t* handle,
ssize_t nread,
const uv.uv_buf_t* buf,
const system.sockaddr* addr,
unsigned flags) with gil:
unsigned flags) noexcept with gil:

if __ensure_handle_data(<uv.uv_handle_t*>handle,
"UDPTransport receive callback") == 0:
Expand Down Expand Up @@ -375,7 +375,7 @@ cdef void __uv_udp_on_receive(uv.uv_udp_t* handle,
udp._error(exc, False)


cdef void __uv_udp_on_send(uv.uv_udp_send_t* req, int status) with gil:
cdef void __uv_udp_on_send(uv.uv_udp_send_t* req, int status) noexcept with gil:

if req.data is NULL:
# Shouldn't happen as:
Expand Down
2 changes: 1 addition & 1 deletion uvloop/loop.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ cdef class Loop:
cdef _call_later(self, uint64_t delay, object callback, object args,
object context)

cdef void _handle_exception(self, object ex)
cdef void _handle_exception(self, object ex) noexcept

cdef inline _is_main_thread(self)

Expand Down
6 changes: 3 additions & 3 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ cdef class Loop:
object context):
return TimerHandle(self, callback, args, delay, context)

cdef void _handle_exception(self, object ex):
cdef void _handle_exception(self, object ex) noexcept:
if isinstance(ex, Exception):
self.call_exception_handler({'exception': ex})
else:
Expand Down Expand Up @@ -3232,7 +3232,7 @@ def libuv_get_version():

cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,
size_t suggested_size,
uv.uv_buf_t* buf) with gil:
uv.uv_buf_t* buf) noexcept with gil:
cdef:
Loop loop = (<UVHandle>uvhandle.data)._loop

Expand Down Expand Up @@ -3330,7 +3330,7 @@ cdef vint __forking = 0
cdef Loop __forking_loop = None


cdef void __get_fork_handler() nogil:
cdef void __get_fork_handler() noexcept nogil:
with gil:
if (__forking and __forking_loop is not None and
__forking_loop.active_process_handler is not None):
Expand Down
4 changes: 2 additions & 2 deletions uvloop/sslproto.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ cdef class SSLProtocol:
# Flow control for writes from APP socket

cdef _control_app_writing(self, object context=*)
cdef size_t _get_write_buffer_size(self)
cdef size_t _get_write_buffer_size(self) noexcept
cdef _set_write_buffer_limits(self, high=*, low=*)

# Flow control for reads to APP socket
Expand All @@ -134,5 +134,5 @@ cdef class SSLProtocol:

cdef _control_ssl_reading(self)
cdef _set_read_buffer_limits(self, high=*, low=*)
cdef size_t _get_read_buffer_size(self)
cdef size_t _get_read_buffer_size(self) noexcept
cdef _fatal_error(self, exc, message=*)
Loading

0 comments on commit ebe1ee1

Please sign in to comment.