Skip to content

Commit dc37cba

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 7903850 + d8565ac commit dc37cba

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- 'pypy-3.8'
4141
- 'pypy-3.9'
4242
- 'pypy-3.10'
43+
- 'pypy-3.11'
4344
- 'graalpy-24.1'
4445

4546
# Items in here will either be added to the build matrix (if not

docs/advanced/functions.rst

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

include/pybind11/attr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ struct type_record {
363363

364364
bases.append((PyObject *) base_info->type);
365365

366-
#if PY_VERSION_HEX < 0x030B0000
366+
#ifdef PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
367367
dynamic_attr |= base_info->type->tp_dictoffset != 0;
368368
#else
369369
dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;

include/pybind11/detail/class.h

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

include/pybind11/detail/common.h

+5
Original file line numberDiff line numberDiff line change
@@ -1261,5 +1261,10 @@ constexpr
12611261
# define PYBIND11_DETAILED_ERROR_MESSAGES
12621262
#endif
12631263

1264+
// CPython 3.11+ provides Py_TPFLAGS_MANAGED_DICT, but PyPy3.11 does not, see PR #5508.
1265+
#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION)
1266+
# define PYBIND11_BACKWARD_COMPATIBILITY_TP_DICTOFFSET
1267+
#endif
1268+
12641269
PYBIND11_NAMESPACE_END(detail)
12651270
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

0 commit comments

Comments
 (0)