Skip to content

Commit

Permalink
Add option to force the use of the PYPY GIL scoped acquire/release lo…
Browse files Browse the repository at this point in the history
…gic to support nested gil access, see pybind#1276 and pytorch/pytorch#83101
  • Loading branch information
SeeChange-CI authored and Ralf W. Grosse-Kunstleve committed Oct 26, 2022
1 parent 07a61aa commit 5fd4621
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ endif()
option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT})
option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT})
option(PYBIND11_NOPYTHON "Disable search for Python" OFF)
option(PYBIND11_USE_PYPY_GIL "Force use of PYPY GIL acquire/release logic in gil.h" OFF)
set(PYBIND11_INTERNALS_VERSION
""
CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.")

if(PYBIND11_USE_PYPY_GIL)
add_compile_definitions(USE_PYPY_GIL)
endif()

cmake_dependent_option(
USE_PYTHON_INCLUDE_DIR
"Install pybind11 headers in Python include directory instead of default installation prefix"
Expand Down
4 changes: 2 additions & 2 deletions include/pybind11/gil.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PyThreadState *get_thread_state_unchecked();

PYBIND11_NAMESPACE_END(detail)

#if defined(WITH_THREAD) && !defined(PYPY_VERSION)
#if defined(WITH_THREAD) && !defined(PYPY_VERSION) && !defined(USE_PYPY_GIL)

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

Expand Down

0 comments on commit 5fd4621

Please sign in to comment.