Skip to content

Commit

Permalink
Improve function signatures for exception handling in recent Cython v…
Browse files Browse the repository at this point in the history
…ersions.
  • Loading branch information
scoder committed Dec 17, 2024
1 parent 5c74fe5 commit 0043caa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions fastrlock/_lock.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cdef struct _LockStatus:


cdef bint _acquire_lock(_LockStatus *lock, long current_thread,
bint blocking) nogil:
bint blocking) nogil except -1:
# Note that this function *must* hold the GIL when being called.
# We just use 'nogil' in the signature to make sure that no Python
# code execution slips in that might free the GIL
Expand Down Expand Up @@ -62,7 +62,7 @@ cdef bint _acquire_lock(_LockStatus *lock, long current_thread,
return True


cdef inline void _unlock_lock(_LockStatus *lock) nogil:
cdef inline void _unlock_lock(_LockStatus *lock) nogil noexcept:
# Note that this function *must* hold the GIL when being called.
# We just use 'nogil' in the signature to make sure that no Python
# code execution slips in that might free the GIL
Expand Down
8 changes: 4 additions & 4 deletions fastrlock/rlock.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cdef class FastRLock:


cdef inline bint _lock_rlock(_LockStatus *lock, pythread_t current_thread,
bint blocking) nogil:
bint blocking) nogil except -1:
# Note that this function *must* hold the GIL when being called.
# We just use 'nogil' in the signature to make sure that no Python
# code execution slips in that might free the GIL
Expand All @@ -66,12 +66,12 @@ cdef inline bint _lock_rlock(_LockStatus *lock, pythread_t current_thread,
# locked! - by myself?
if lock.owner == current_thread:
lock.entry_count += 1
return 1
return True
elif not lock.pending_requests:
# not locked, not requested - go!
lock.owner = current_thread
lock.entry_count = 1
return 1
return True
# need to get the real lock
return _acquire_lock(lock, current_thread, blocking)

Expand All @@ -89,7 +89,7 @@ cdef create_fastrlock():
cdef bint lock_fastrlock(rlock, long current_thread, bint blocking) except -1:
"""
Public C level entry function for locking a FastRlock instance.
The 'current_thread' argument is deprecated and ignored. Pass -1 for backwards compatibility.
"""
# Note: 'current_thread' used to be set to -1 or the current thread ID, but -1 is signed while "pythread_t" isn't.
Expand Down

0 comments on commit 0043caa

Please sign in to comment.