Skip to content

Commit 9ea1976

Browse files
Use new 3.14 C APIs when available (#5854)
* Use new 3.14 C APIs when available Use the new "unstable" C APIs for the functions added in #5494. * style: pre-commit fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4dc33d6 commit 9ea1976

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/pybind11/detail/class.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ inline void traverse_offset_bases(void *valueptr,
314314

315315
#ifdef Py_GIL_DISABLED
316316
inline void enable_try_inc_ref(PyObject *obj) {
317-
// TODO: Replace with PyUnstable_Object_EnableTryIncRef when available.
318-
// See https://github.com/python/cpython/issues/128844
317+
# if PY_VERSION_HEX >= 0x030E00A4
318+
PyUnstable_EnableTryIncRef(obj);
319+
# else
319320
if (_Py_IsImmortal(obj)) {
320321
return;
321322
}
@@ -330,6 +331,7 @@ inline void enable_try_inc_ref(PyObject *obj) {
330331
return;
331332
}
332333
}
334+
# endif
333335
}
334336
#endif
335337

include/pybind11/detail/type_caster_base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp, bool throw_if
253253

254254
inline bool try_incref(PyObject *obj) {
255255
// Tries to increment the reference count of an object if it's not zero.
256-
// TODO: Use PyUnstable_TryIncref when available.
257-
// See https://github.com/python/cpython/issues/128844
258-
#ifdef Py_GIL_DISABLED
256+
#if defined(Py_GIL_DISABLED) && PY_VERSION_HEX >= 0x030E00A4
257+
return PyUnstable_TryIncRef(obj);
258+
#elif defined(Py_GIL_DISABLED)
259259
// See
260260
// https://github.com/python/cpython/blob/d05140f9f77d7dfc753dd1e5ac3a5962aaa03eff/Include/internal/pycore_object.h#L761
261261
uint32_t local = _Py_atomic_load_uint32_relaxed(&obj->ob_ref_local);

0 commit comments

Comments
 (0)