Skip to content

signal module wrongly relies on small int singletons #90566

Closed

Description

@tiran
BPO 46408
Nosy @tiran, @serhiy-storchaka
Superseder
  • 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 = None
    closed_at = <Date 2022-01-17.09:13:13.899>
    created_at = <Date 2022-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 = <Date 2022-01-17.09:13:40.107>
    user = 'https://github.com/tiran'

    bugs.python.org fields:

    activity = <Date 2022-01-17.09:13:40.107>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-17.09:13:13.899>
    closer = 'christian.heimes'
    components = ['Extension Modules']
    creation = <Date 2022-01-17.09:01:28.784>
    creator = 'christian.heimes'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46408
    keywords = []
    message_count = 3.0
    messages = ['410747', '410748', '410750']
    nosy_count = 2.0
    nosy_names = ['christian.heimes', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '23325'
    type = 'behavior'
    url = 'https://bugs.python.org/issue46408'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. tiran commented on Jan 17, 2022

      @tiran
      MemberAuthor

      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;
          }

      if (handler == modstate->ignore_handler) {
      func = SIG_IGN;
      }
      else if (handler == modstate->default_handler) {
      func = SIG_DFL;

    2. added
      3.11only security fixes
      type-bugAn unexpected behavior, bug, or error
      on Jan 17, 2022
    3. serhiy-storchaka commented on Jan 17, 2022

      @serhiy-storchaka
      Member

      See msg234768 and bpo-23325. I propose to close this as a duplicate of bpo-23325.

    4. tiran commented on Jan 17, 2022

      @tiran
      MemberAuthor

      Yes, it's a duplicate.

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifeextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions