Skip to content

Add variant of Py_BEGIN_CRITICAL_SECTION that accepts a NULL argument #115432

Description

@colesbury

Feature or enhancement

We should add a variant of Py_BEGIN_CRITICAL_SECTION / Py_END_CRITICAL_SECTION that accepts a possibly NULL object. If the passed object is NULL then nothing is locked or unlocked. Otherwise, it behaves like Py_BEGIN_CRITICAL_SECTION.

For example:

PyObject *object = maybe ? real_object : NULL;
Py_XBEGIN_CRITICAL_SECTION(object);
...
Py_XEND_CRITICAL_SECTION();

This will be useful in making set thread-safe. There are a number of functions that take an optional iterable that may be NULL. We want to lock it in the cases where it's not NULL.

I don't think we will need a version of Py_BEGIN_CRITICAL_SECTION2 that accepts optionally NULL arguments.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Feb 13, 2024
  2. self-assigned this
    on Mar 19, 2024
  3. colesbury commented on Mar 19, 2024

    @colesbury
    ContributorAuthor

    It turns out that we are not using this in set (or anywhere else), so I think we should revert the PR.

  4. added a commit that references this issue on Apr 17, 2024
  5. added 2 commits that reference this issue on May 9, 2024
  6. added a commit that references this issue on May 9, 2024
  7. added a commit that references this issue on May 9, 2024
  8. added a commit that references this issue on May 10, 2024
  9. added a commit that references this issue on Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions