Skip to content

Commit 22ee70e

Browse files
committed
Add option to force the use of the PYPY GIL scoped acquire/release logic to support nested gil access, see pybind#1276 and pytorch/pytorch#83101
1 parent 8275b76 commit 22ee70e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ endif()
9191
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
9292
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
9393
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
94+
option(PYBIND11_USE_PYPY_GIL "Force use of PYPY GIL acquire/release logic in gil.h" OFF)
9495
set(PYBIND11_INTERNALS_VERSION
9596
""
9697
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")
9798

99+
if(PYBIND11_USE_PYPY_GIL)
100+
add_compile_definitions(USE_PYPY_GIL)
101+
endif()
102+
98103
cmake_dependent_option(
99104
USE_PYTHON_INCLUDE_DIR
100105
"Install pybind11 headers in Python include directory instead of default installation prefix"

include/pybind11/gil.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PyThreadState *get_thread_state_unchecked();
2121

2222
PYBIND11_NAMESPACE_END(detail)
2323

24-
#if defined(WITH_THREAD) && !defined(PYPY_VERSION)
24+
#if defined(WITH_THREAD) && !defined(PYPY_VERSION) && !defined(USE_PYPY_GIL)
2525

2626
/* The functions below essentially reproduce the PyGILState_* API using a RAII
2727
* pattern, but there are a few important differences:
@@ -178,7 +178,7 @@ class gil_scoped_release {
178178
bool disassoc;
179179
bool active = true;
180180
};
181-
#elif defined(PYPY_VERSION)
181+
#elif defined(PYPY_VERSION) || defined(USE_PYPY_GIL)
182182
class gil_scoped_acquire {
183183
PyGILState_STATE state;
184184

0 commit comments

Comments
 (0)