Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pybind/pybind11
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0f9d2fa840213edf89d3c4b74e0b6c49d2954950
Choose a base ref
..
head repository: pybind/pybind11
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 198c9c21372047cf43856d4d01f0cc56d2f9a11f
Choose a head ref
Showing with 11 additions and 4 deletions.
  1. +4 −0 include/pybind11/attr.h
  2. +4 −0 include/pybind11/detail/class.h
  3. +3 −4 tests/test_embed/test_interpreter.cpp
4 changes: 4 additions & 0 deletions include/pybind11/attr.h
Original file line number Diff line number Diff line change
@@ -345,7 +345,11 @@ struct type_record {

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

#if PY_VERSION_HEX < 0x030B0000
dynamic_attr |= base_info->type->tp_dictoffset != 0;
#else
dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;
#endif

if (caster) {
base_info->implicit_casts.emplace_back(type, caster);
4 changes: 4 additions & 0 deletions include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
@@ -549,8 +549,12 @@ 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
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
type->tp_traverse = pybind11_traverse;
type->tp_clear = pybind11_clear;

7 changes: 3 additions & 4 deletions tests/test_embed/test_interpreter.cpp
Original file line number Diff line number Diff line change
@@ -178,13 +178,12 @@ TEST_CASE("Restart the interpreter") {
py::module_::import("os")
.attr("environ")
.attr("get")("PYTHONPATH")
.attr("__str__")()
.cast<std::string>()
.c_str());
auto sys_path = py::module_::import("sys").attr("path").attr("__str__")().cast<std::string>();
fprintf(stdout, "\nLOOOK_BEF %s\n", sys_path.c_str());
fflush(stdout);
py::module_::import("site").attr("main")(); // Ensure PYTHONPATH is processed.
fprintf(stdout, "\nLOOOK_AFT %s\n", sys_path.c_str());
auto sys_path = py::module_::import("sys").attr("path").attr("__str__")().cast<std::string>();
fprintf(stdout, "\nLOOOK sys.path %s\n", sys_path.c_str());
fflush(stdout);
REQUIRE(py::module_::import("widget_module").attr("add")(1, 2).cast<int>() == 3);
REQUIRE(has_pybind11_internals_builtin());