Skip to content

Commit

Permalink
Merge pull request #217 from tornaria/warnings
Browse files Browse the repository at this point in the history
Fix warnings (C and cython)
  • Loading branch information
dimpase authored Jan 23, 2025
2 parents 3cf5e38 + 6fd403c commit d54ee91
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
pip install --upgrade -r requirements.txt
pip install --upgrade ninja
- name: Build
run: pip install --no-build-isolation --config-settings=builddir=builddir .
run: pip install -v --no-build-isolation --config-settings=builddir=builddir .
- name: Test
run: meson test --print-errorlogs -C builddir
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('cysignals', 'c', 'cpp', 'cython',
default_options: ['warning_level=3', 'cpp_std=c++17']
default_options: ['warning_level=2', 'cpp_std=c++17']
)

# Python
Expand Down
2 changes: 1 addition & 1 deletion src/cysignals/alarm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def cancel_alarm():
setitimer_real(0)


cdef inline void setitimer_real(double x):
cdef inline void setitimer_real(double x) noexcept:
cdef itimerval itv
itv.it_interval.tv_sec = 0
itv.it_interval.tv_usec = 0
Expand Down
4 changes: 2 additions & 2 deletions src/cysignals/implementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ static void cysigs_signal_handler(int sig)
* fact, POSIX recommends threads in
* http://pubs.opengroup.org/onlinepubs/009695299/functions/makecontext.html
*/
static void* _sig_on_trampoline(void* dummy)
static void* _sig_on_trampoline(CYTHON_UNUSED void* dummy)
{
register int sig;

Expand Down Expand Up @@ -523,7 +523,7 @@ static void setup_trampoline(void)
size_t trampolinestacksize = 1 << 17;

#ifdef PTHREAD_STACK_MIN
if (trampolinestacksize < PTHREAD_STACK_MIN)
if (trampolinestacksize < (size_t) PTHREAD_STACK_MIN)
trampolinestacksize = PTHREAD_STACK_MIN;
#endif
trampolinestack = malloc(trampolinestacksize + 4096);
Expand Down
2 changes: 1 addition & 1 deletion src/cysignals/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extern "C" {
/*
* Set message, return 0 if we need to cysetjmp(), return 1 otherwise.
*/
static inline int _sig_on_prejmp(const char* message, const char* file, int line)
static inline int _sig_on_prejmp(const char* message, CYTHON_UNUSED const char* file, CYTHON_UNUSED int line)
{
cysigs.s = message;
#if ENABLE_DEBUG_CYSIGNALS
Expand Down
1 change: 1 addition & 0 deletions src/cysignals/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ foreach name, pyx : extensions
py.extension_module(name,
pyx,
include_directories: [include_directories('.'), src],
cython_args: ['-Wextra'],
dependencies: [py_dep, threads_dep],
install: true,
subdir: 'cysignals'
Expand Down
1 change: 0 additions & 1 deletion src/cysignals/pysignals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ cdef class containsignals:
cdef sigset_t unblock

def __init__(self, signals=None):
cdef int s
if signals is None:
self.signals = [s for s in range(1, 32) if s != SIGKILL and s != SIGSTOP]
else:
Expand Down
10 changes: 5 additions & 5 deletions src/cysignals/signals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ cdef int sig_raise_exception "sig_raise_exception"(int sig, const char* msg) exc
PyErr_Format(SystemError, "unknown signal number %i", sig)

# Save exception in cysigs.exc_value
cdef PyObject* typ
cdef PyObject* val
cdef PyObject* tb
cdef PyObject* typ = NULL
cdef PyObject* val = NULL
cdef PyObject* tb = NULL
PyErr_Fetch(&typ, &val, &tb)
PyErr_NormalizeException(&typ, &val, &tb)
Py_XINCREF(val)
Expand Down Expand Up @@ -246,10 +246,10 @@ def sig_print_exception(sig, msg=None):

try:
sig_raise_exception(sig, m)
except BaseException as e:
except BaseException:
# Print exception to stdout without traceback
import sys, traceback
typ, val, tb = sys.exc_info()
typ, val, _ = sys.exc_info()
traceback.print_exception(typ, val, None, file=sys.stdout, chain=False)


Expand Down
28 changes: 17 additions & 11 deletions src/cysignals/tests.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cython: preliminary_late_includes_cy28=True
# cython: preliminary_late_includes_cy28=True, show_performance_hints=False
"""
Test interrupt and signal handling
Expand Down Expand Up @@ -58,6 +58,12 @@ cdef extern from "<pthread.h>" nogil:


cdef extern from *:
"""
#if defined(__GNUC__) && !defined(__clang__)
// disable warning (variable might be clobbered by longjmp)
#pragma GCC diagnostic ignored "-Wclobbered"
#endif
"""
ctypedef int volatile_int "volatile int"


Expand Down Expand Up @@ -101,6 +107,9 @@ cdef void dereference_null_pointer() noexcept nogil:
cdef volatile_int* ptr = <volatile_int*>(0)
ptr[0] += 1

# disable warning (infinite recursion in stack_overflow)
cdef extern from *:
'#pragma GCC diagnostic ignored "-Winfinite-recursion"'

cdef int stack_overflow(volatile_int* x=NULL) noexcept nogil:
cdef volatile_int a = 0
Expand Down Expand Up @@ -197,7 +206,7 @@ def subpython_err(command, **kwds):
"""
argv = [sys.executable, '-c', command]
P = Popen(argv, stdout=PIPE, stderr=PIPE, universal_newlines=True, **kwds)
(out, err) = P.communicate()
(_, err) = P.communicate()
sys.stdout.write(err)


Expand Down Expand Up @@ -249,7 +258,7 @@ def test_sig_str(long delay=DEFAULT_DELAY):
signal_after_delay(SIGABRT, delay)
infinite_loop()

cdef c_test_sig_on_cython() noexcept:
cdef c_test_sig_on_cython():
sig_on()
infinite_loop()

Expand Down Expand Up @@ -977,7 +986,7 @@ def test_sig_occurred_dealloc():
No current exception
"""
x = DeallocDebug()
_ = DeallocDebug()
sig_str("test_sig_occurred_dealloc()")
abort()

Expand Down Expand Up @@ -1155,9 +1164,8 @@ def sig_on_bench():
>>> sig_on_bench()
"""
cdef int i
with nogil:
for i in range(1000000):
for _ in range(1000000):
sig_on()
sig_off()

Expand All @@ -1171,9 +1179,8 @@ def sig_check_bench():
>>> sig_check_bench()
"""
cdef int i
with nogil:
for i in range(1000000):
for _ in range(1000000):
sig_check()


Expand Down Expand Up @@ -1277,7 +1284,7 @@ def test_thread_sig_block(long delay=DEFAULT_DELAY):
>>> test_thread_sig_block()
"""
cdef pthread_t t1, t2
cdef pthread_t t1 = 0, t2 = 0
with nogil:
sig_on()
if pthread_create(&t1, NULL, func_thread_sig_block, NULL):
Expand All @@ -1293,8 +1300,7 @@ def test_thread_sig_block(long delay=DEFAULT_DELAY):

cdef void* func_thread_sig_block(void* ignored) noexcept with gil:
# This is executed by the two threads spawned by test_thread_sig_block()
cdef int n
for n in range(1000000):
for _ in range(1000000):
sig_block()
if not (1 <= cysigs.block_sigint <= 2):
PyErr_SetString(RuntimeError, "sig_block() is not thread-safe")
Expand Down

0 comments on commit d54ee91

Please sign in to comment.