This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: signal module wrongly relies on small int singletons
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: duplicate
Dependencies: Superseder: Turn SIG_DFL and SIG_IGN into functions
View: 23325
Assigned To: Nosy List: christian.heimes, serhiy.storchaka
Priority: normal Keywords:

Created on 2022-01-17 09:01 by christian.heimes, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg410747 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-01-17 09:01
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;
    else if (handler == modstate->default_handler) {
        func = SIG_DFL;
msg410748 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-01-17 09:10
See msg234768 and issue23325. I propose to close this as a duplicate of issue23325.
msg410750 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2022-01-17 09:13
Yes, it's a duplicate.
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90566
2022-01-17 09:13:40christian.heimessetmessages: + msg410750
2022-01-17 09:13:13christian.heimessetstatus: open -> closed
superseder: Turn SIG_DFL and SIG_IGN into functions
resolution: duplicate
stage: resolved
2022-01-17 09:10:09serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg410748
2022-01-17 09:02:13christian.heimeslinkissue40280 dependencies
2022-01-17 09:01:28christian.heimescreate