Skip to content

Commit 99131a8

Browse files
Provide PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF as an option (#4753)
* Remove GIL checks * Update common.h * Add flag * style: pre-commit fixes * Update pytypes.h * style: pre-commit fixes * Update common.h * style: pre-commit fixes * Update pytypes.h * style: pre-commit fixes * Update common.h * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ec1b57c commit 99131a8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/pybind11/detail/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ PYBIND11_WARNING_POP
324324
#endif
325325

326326
// See description of PR #4246:
327-
#if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(PYPY_VERSION) \
328-
&& !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
327+
#if !defined(PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(NDEBUG) \
328+
&& !defined(PYPY_VERSION) && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
329329
# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
330330
#endif
331331

include/pybind11/pytypes.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,12 @@ class handle : public detail::object_api<handle> {
303303
stderr,
304304
"%s is being called while the GIL is either not held or invalid. Please see "
305305
"https://pybind11.readthedocs.io/en/stable/advanced/"
306-
"misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n",
306+
"misc.html#common-sources-of-global-interpreter-lock-errors for debugging advice.\n"
307+
"If you are convinced there is no bug in your code, you can #define "
308+
"PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF"
309+
"to disable this check. In that case you have to ensure this #define is consistently "
310+
"used for all translation units linked into a given pybind11 extension, otherwise "
311+
"there will be ODR violations.",
307312
function_name.c_str());
308313
fflush(stderr);
309314
if (Py_TYPE(m_ptr)->tp_name != nullptr) {

0 commit comments

Comments
 (0)