#pragma once
#include "../attr.h"
+#include "../options.h"
NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
NAMESPACE_BEGIN(detail)
inline void add_patient(PyObject *nurse, PyObject *patient) {
auto &internals = get_internals();
auto instance = reinterpret_cast<detail::instance *>(nurse);
- auto ¤t_patients = internals.patients[nurse];
instance->has_patients = true;
- for (auto &p : current_patients)
- if (p == patient)
- return;
Py_INCREF(patient);
- current_patients.push_back(patient);
+ internals.patients[nurse].push_back(patient);
}
inline void clear_patients(PyObject *self) {
auto type = Py_TYPE(self);
type->tp_free(self);
+#if PY_VERSION_HEX < 0x03080000
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
// as part of a derived type's dealloc, in which case we're not allowed to decref
// the type here. For cross-module compatibility, we shouldn't compare directly
auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
Py_DECREF(type);
+#else
+ // This was not needed before Python 3.8 (Python issue 35810)
+ // https://github.com/pybind/pybind11/issues/1946
+ Py_DECREF(type);
+#endif
}
/** Create the type which can be used as a common base for all classes. This is
if (tinfo && tinfo->get_buffer)
break;
}
- if (view == nullptr || obj == nullptr || !tinfo || !tinfo->get_buffer) {
+ if (view == nullptr || !tinfo || !tinfo->get_buffer) {
if (view)
view->obj = nullptr;
PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error");
view->len = view->itemsize;
for (auto s : info->shape)
view->len *= s;
+ view->readonly = info->readonly;
+ if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) {
+ if (view)
+ view->obj = nullptr;
+ PyErr_SetString(PyExc_BufferError, "Writable buffer requested for readonly storage");
+ return -1;
+ }
if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
view->format = const_cast<char *>(info->format.c_str());
if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
type->tp_as_number = &heap_type->as_number;
type->tp_as_sequence = &heap_type->as_sequence;
type->tp_as_mapping = &heap_type->as_mapping;
+#if PY_VERSION_HEX >= 0x03050000
+ type->tp_as_async = &heap_type->as_async;
+#endif
/* Flags */
type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;