Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add variant of Py_BEGIN_CRITICAL_SECTION that accepts a NULL argument #115432

Closed
@colesbury

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions