You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
signal module wrongly relies on small int singletons #90566
bpo-23325: Turn SIG_DFL and SIG_IGN into functions
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2022-01-17.09:13:13.899>created_at=<Date2022-01-17.09:01:28.784>labels= ['extension-modules', 'type-bug', '3.9', '3.10', '3.11']
title='signal module wrongly relies on small int singletons'updated_at=<Date2022-01-17.09:13:40.107>user='https://github.com/tiran'
The signal.signal() function directly compares PyObject *handler with PyObject *modstate->ignore_handler. This works on most platforms because they are both small ints and Python uses singletons for cached small ints.
The assumption breaks when Python is built without small int cache or a platform has SIG_IGN / SIG_DFL that is outside the range of small int cache. The wasm32-emscripten platform uses "((void (*)(int))-2)" (4294967294) for SIG_IGN. The wrong comparison breaks several tests on WASM32. The function should use PyObject_RichCompareBool(handler, modstate->ignore_handler, Py_EQ) instead.
if (handler==modstate->ignore_handler) {
func=SIG_IGN;
}
elseif (handler==modstate->default_handler) {
func=SIG_DFL;
}
Activity
tiran commentedon Jan 17, 2022
The signal.signal() function directly compares PyObject *handler with PyObject *modstate->ignore_handler. This works on most platforms because they are both small ints and Python uses singletons for cached small ints.
The assumption breaks when Python is built without small int cache or a platform has SIG_IGN / SIG_DFL that is outside the range of small int cache. The wasm32-emscripten platform uses "((void (*)(int))-2)" (4294967294) for SIG_IGN. The wrong comparison breaks several tests on WASM32. The function should use PyObject_RichCompareBool(handler, modstate->ignore_handler, Py_EQ) instead.
cpython/Modules/signalmodule.c
Lines 530 to 534 in 7f4b69b
serhiy-storchaka commentedon Jan 17, 2022
See msg234768 and bpo-23325. I propose to close this as a duplicate of bpo-23325.
tiran commentedon Jan 17, 2022
Yes, it's a duplicate.