Skip to content

Commit

Permalink
Provide PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF as an option (#4753)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
EthanSteinberg and pre-commit-ci[bot] committed Jul 17, 2023
1 parent ec1b57c commit 99131a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ PYBIND11_WARNING_POP
#endif

// See description of PR #4246:
#if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(PYPY_VERSION) \
&& !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
#if !defined(PYBIND11_NO_ASSERT_GIL_HELD_INCREF_DECREF) && !defined(NDEBUG) \
&& !defined(PYPY_VERSION) && !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
#endif

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

0 comments on commit 99131a8

Please sign in to comment.