mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-24 06:05:10 +00:00
e250155afa
* Equivalent of5718e4d080
* Resolve clang-tidy errors. * Moving test_PPCCInit() first changes the behavior! * Resolve new Clang dev C++11 errors: ``` The CXX compiler identification is Clang 17.0.0 ``` ``` pytypes.h:1615:23: error: identifier '_s' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator] ``` ``` cast.h:1380:26: error: identifier '_a' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator] ``` * Resolve gcc 4.8.5 error: ``` pytypes.h:1615:12: error: missing space between '""' and suffix identifier ``` * Specifically exclude `__clang__` * Snapshot of debugging code (does NOT pass pre-commit checks). * Revert "Snapshot of debugging code (does NOT pass pre-commit checks)." This reverts commit1d4f9ff263
. * [ci skip] Order Dependence Demo * Revert "[ci skip] Order Dependence Demo" This reverts commitd37b5409d4
. * One way to deal with the order dependency issue. This is not the best way, more like a proof of concept. * Move test_PC() first again. * Add `all_type_info_add_base_most_derived_first()`, use in `all_type_info_populate()` * Revert "One way to deal with the order dependency issue. This is not the best way, more like a proof of concept." This reverts commiteb09c6c1b9
. * clang-tidy fixes (automatic) * Add `is_redundant_value_and_holder()` and use to avoid forcing `__init__` overrides when they are not needed. * Streamline implementation and avoid unsafe `reinterpret_cast<instance *>()` introduced with PR #2152 The `reinterpret_cast<instance *>(self)` is unsafe if `__new__` is mocked, which was actually found in the wild: the mock returned `None` for `self`. This was inconsequential because `inst` is currently cast straight back to `PyObject *` to compute `all_type_info()`, which is empty if `self` is not a pybind11 `instance`, and then `inst` is never dereferenced. However, the unsafe detour through `instance *` is easily avoided and the updated implementation is less prone to accidents while debugging or refactoring. * Fix actual undefined behavior exposed by previous changes. It turns out the previous commit message is incorrect, the `inst` pointer is actually dereferenced, in the `value_and_holder` ctor here:f3e0602802/include/pybind11/detail/type_caster_base.h (L262-L263)
``` 259 // Main constructor for a found value/holder: 260 value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index) 261 : inst{i}, index{index}, type{type}, 262 vh{inst->simple_layout ? inst->simple_value_holder 263 : &inst->nonsimple.values_and_holders[vpos]} {} ``` * Add test_mock_new() * Experiment: specify indirect bases * Revert "Experiment: specify indirect bases" This reverts commit4f90d85f9f
. * Add `all_type_info_check_for_divergence()` and some tests. * Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>` * Resolve clang-tidy error: ``` include/pybind11/detail/type_caster_base.h:795:21: error: the 'empty' method should be used to check for emptiness instead of 'size' [readability-container-size-empty,-warnings-as-errors] if (matching_bases.size() != 0) { ^~~~~~~~~~~~~~~~~~~~~~~~~~ !matching_bases.empty() ``` * Revert "Resolve clang-tidy error:" This reverts commitdf27188dc6
. * Revert "Call `all_type_info_check_for_divergence()` also from `type_caster_generic::load_impl<>`" This reverts commit5f5fd6a68e
. * Revert "Add `all_type_info_check_for_divergence()` and some tests." This reverts commit0a9599f775
.
46 lines
1.5 KiB
C++
46 lines
1.5 KiB
C++
#include "pybind11_tests.h"
|
|
|
|
namespace test_python_multiple_inheritance {
|
|
|
|
// Copied from:
|
|
// https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python_multiple_inheritance.h
|
|
|
|
struct CppBase {
|
|
explicit CppBase(int value) : base_value(value) {}
|
|
int get_base_value() const { return base_value; }
|
|
void reset_base_value(int new_value) { base_value = new_value; }
|
|
|
|
private:
|
|
int base_value;
|
|
};
|
|
|
|
struct CppDrvd : CppBase {
|
|
explicit CppDrvd(int value) : CppBase(value), drvd_value(value * 3) {}
|
|
int get_drvd_value() const { return drvd_value; }
|
|
void reset_drvd_value(int new_value) { drvd_value = new_value; }
|
|
|
|
int get_base_value_from_drvd() const { return get_base_value(); }
|
|
void reset_base_value_from_drvd(int new_value) { reset_base_value(new_value); }
|
|
|
|
private:
|
|
int drvd_value;
|
|
};
|
|
|
|
} // namespace test_python_multiple_inheritance
|
|
|
|
TEST_SUBMODULE(python_multiple_inheritance, m) {
|
|
using namespace test_python_multiple_inheritance;
|
|
|
|
py::class_<CppBase>(m, "CppBase")
|
|
.def(py::init<int>())
|
|
.def("get_base_value", &CppBase::get_base_value)
|
|
.def("reset_base_value", &CppBase::reset_base_value);
|
|
|
|
py::class_<CppDrvd, CppBase>(m, "CppDrvd")
|
|
.def(py::init<int>())
|
|
.def("get_drvd_value", &CppDrvd::get_drvd_value)
|
|
.def("reset_drvd_value", &CppDrvd::reset_drvd_value)
|
|
.def("get_base_value_from_drvd", &CppDrvd::get_base_value_from_drvd)
|
|
.def("reset_base_value_from_drvd", &CppDrvd::reset_base_value_from_drvd);
|
|
}
|