mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
* Strictly enforce: trampoline must inherit from trampoline_self_life_support when used in combination with smart_holder
* Simplify test_class_sh_trampoline_basic.cpp,py (only one Abase is needed now)
* Replace obsolete sophisticated `throw value_error()` with a simple `assert()`
* Strictly enforce: trampoline should inherit from trampoline_self_life_support only if used in combination with smart_holder
* Resolve clang-tidy error
```
/__w/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:35:46: error: the parameter 'obj' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors]
35 | int AddInCppSharedPtr(std::shared_ptr<Abase> obj, int other_val) {
| ^
| const &
```
* Disable new static_assert if PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE is defined.
36 lines
977 B
Python
36 lines
977 B
Python
from __future__ import annotations
|
|
|
|
from pybind11_tests import class_sh_trampoline_basic as m
|
|
|
|
|
|
class PyDrvd(m.Abase):
|
|
def __init__(self, val):
|
|
super().__init__(val)
|
|
|
|
def Add(self, other_val):
|
|
return self.Get() * 100 + other_val
|
|
|
|
|
|
def test_drvd_add():
|
|
drvd = PyDrvd(74)
|
|
assert drvd.Add(38) == (74 * 10 + 3) * 100 + 38
|
|
|
|
|
|
def test_drvd_add_in_cpp_raw_ptr():
|
|
drvd = PyDrvd(52)
|
|
assert m.AddInCppRawPtr(drvd, 27) == ((52 * 10 + 3) * 100 + 27) * 10 + 7
|
|
|
|
|
|
def test_drvd_add_in_cpp_shared_ptr():
|
|
while True:
|
|
drvd = PyDrvd(36)
|
|
assert m.AddInCppSharedPtr(drvd, 56) == ((36 * 10 + 3) * 100 + 56) * 100 + 11
|
|
return # Comment out for manual leak checking (use `top` command).
|
|
|
|
|
|
def test_drvd_add_in_cpp_unique_ptr():
|
|
while True:
|
|
drvd = PyDrvd(25)
|
|
assert m.AddInCppUniquePtr(drvd, 83) == ((25 * 10 + 3) * 100 + 83) * 100 + 13
|
|
return # Comment out for manual leak checking (use `top` command).
|