Merge branch 'master' into sh_merge_master

This commit is contained in:
Ralf W. Grosse-Kunstleve 2025-02-20 19:26:42 -08:00
commit dc37cba85d
No known key found for this signature in database
5 changed files with 15 additions and 7 deletions

View File

@ -40,6 +40,7 @@ jobs:
- 'pypy-3.8'
- 'pypy-3.9'
- 'pypy-3.10'
- 'pypy-3.11'
- 'graalpy-24.1'
# Items in here will either be added to the build matrix (if not

View File

@ -81,9 +81,11 @@ The following table provides an overview of available policies:
| | it is no longer used. Warning: undefined behavior will ensue when the C++ |
| | side deletes an object that is still referenced and used by Python. |
+--------------------------------------------------+----------------------------------------------------------------------------+
| :enum:`return_value_policy::reference_internal` | Indicates that the lifetime of the return value is tied to the lifetime |
| | of a parent object, namely the implicit ``this``, or ``self`` argument of |
| | the called method or property. Internally, this policy works just like |
| :enum:`return_value_policy::reference_internal` | If the return value is an lvalue reference or a pointer, the parent object |
| | (the implicit ``this``, or ``self`` argument of the called method or |
| | property) is kept alive for at least the lifespan of the return value. |
| | **Otherwise this policy falls back to :enum:`return_value_policy::move` |
| | (see #5528).** Internally, this policy works just like |
| | :enum:`return_value_policy::reference` but additionally applies a |
| | ``keep_alive<0, 1>`` *call policy* (described in the next section) that |
| | prevents the parent object from being garbage collected as long as the |

View File

@ -363,7 +363,7 @@ struct type_record {
bases.append((PyObject *) base_info->type);
#if PY_VERSION_HEX < 0x030B0000
#ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
dynamic_attr |= base_info->type->tp_dictoffset != 0;
#else
dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;

View File

@ -576,9 +576,9 @@ extern "C" inline int pybind11_clear(PyObject *self) {
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
auto *type = &heap_type->ht_type;
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION) // For PyPy see PR #5508
type->tp_dictoffset = type->tp_basicsize; // place dict at the end
type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it
#ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
type->tp_dictoffset = type->tp_basicsize; // place dict at the end
type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it
#else
type->tp_flags |= Py_TPFLAGS_MANAGED_DICT;
#endif

View File

@ -1261,5 +1261,10 @@ constexpr
# define PYBIND11_DETAILED_ERROR_MESSAGES
#endif
// CPython 3.11+ provides Py_TPFLAGS_MANAGED_DICT, but PyPy3.11 does not, see PR #5508.
#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION)
# define PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
#endif
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)