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

Fix warnings (C and cython) #217

Merged
merged 10 commits into from
Jan 23, 2025
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
33 changes: 8 additions & 25 deletions src/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from _pytest.nodes import Collector
from _pytest.doctest import DoctestModule

from _pytest.pathlib import resolve_pkg_root_and_module_name
import importlib

# cysignals-CSI only works from gdb, i.e. invoke ./testgdb.py directly
collect_ignore = ["cysignals/cysignals-CSI-helper.py"]

Expand All @@ -24,30 +27,10 @@ def pytest_collect_file(
config = parent.config
if file_path.suffix == ".pyx":
if config.option.doctestmodules:
# import the module so it's available to pytest
_, module_name = resolve_pkg_root_and_module_name(file_path)
module = importlib.import_module(module_name)
# delete __test__ injected by cython, to avoid duplicate tests
del module.__test__
return DoctestModule.from_parent(parent, path=file_path)
return None


# Need to import cysignals to initialize it
import cysignals # noqa: E402

try:
import cysignals.alarm
except ImportError:
pass
try:
import cysignals.signals
except ImportError:
pass
try:
import cysignals.pselect
except ImportError:
pass
try:
import cysignals.pysignals
except ImportError:
pass
try:
import cysignals.tests # noqa: F401
except ImportError:
pass
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
Loading