mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
pybind11::handle
inc_ref()
& dec_ref()
PyGILState_Check()
**excluding** nullptr
(#4246)
* pybind11/pytypes.h `inc_ref()`, `dec_ref()` `PyGILState_Check()` **excluding** `nullptr` Guarded by `PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF` * Disable `PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF` for PyPy under Windows. * Add reference to PR #4268 (PyPy Windows)
This commit is contained in:
parent
65cc9d2a29
commit
65374c8e62
@ -323,6 +323,15 @@ PYBIND11_WARNING_POP
|
|||||||
# define PYBIND11_HAS_U8STRING
|
# define PYBIND11_HAS_U8STRING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// See description of PR #4246:
|
||||||
|
#if !defined(NDEBUG) && !defined(PY_ASSERT_GIL_HELD_INCREF_DECREF) \
|
||||||
|
&& !(defined(PYPY_VERSION) \
|
||||||
|
&& defined(_MSC_VER)) /* PyPy Windows: pytest hangs indefinitely at the end of the \
|
||||||
|
process (see PR #4268) */ \
|
||||||
|
&& !defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
|
||||||
|
# define PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF
|
||||||
|
#endif
|
||||||
|
|
||||||
// #define PYBIND11_STR_LEGACY_PERMISSIVE
|
// #define PYBIND11_STR_LEGACY_PERMISSIVE
|
||||||
// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
|
// If DEFINED, pybind11::str can hold PyUnicodeObject or PyBytesObject
|
||||||
// (probably surprising and never documented, but this was the
|
// (probably surprising and never documented, but this was the
|
||||||
|
@ -249,6 +249,11 @@ public:
|
|||||||
const handle &inc_ref() const & {
|
const handle &inc_ref() const & {
|
||||||
#ifdef PYBIND11_HANDLE_REF_DEBUG
|
#ifdef PYBIND11_HANDLE_REF_DEBUG
|
||||||
inc_ref_counter(1);
|
inc_ref_counter(1);
|
||||||
|
#endif
|
||||||
|
#if defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
|
||||||
|
if (m_ptr != nullptr && !PyGILState_Check()) {
|
||||||
|
throw std::runtime_error("pybind11::handle::inc_ref() PyGILState_Check() failure.");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
Py_XINCREF(m_ptr);
|
Py_XINCREF(m_ptr);
|
||||||
return *this;
|
return *this;
|
||||||
@ -260,6 +265,11 @@ public:
|
|||||||
this function automatically. Returns a reference to itself.
|
this function automatically. Returns a reference to itself.
|
||||||
\endrst */
|
\endrst */
|
||||||
const handle &dec_ref() const & {
|
const handle &dec_ref() const & {
|
||||||
|
#if defined(PYBIND11_ASSERT_GIL_HELD_INCREF_DECREF)
|
||||||
|
if (m_ptr != nullptr && !PyGILState_Check()) {
|
||||||
|
throw std::runtime_error("pybind11::handle::dec_ref() PyGILState_Check() failure.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Py_XDECREF(m_ptr);
|
Py_XDECREF(m_ptr);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user