pybind11/tests/test_class_sh_trampoline_unique_ptr.py
Ralf W. Grosse-Kunstleve 5ab036bf08
[smart_holder] Simplification: Enable smart_holder functionality unconditionally. (#5531)
* git merge --squash purge_internals_versions_4_5

* Remove PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT, set PYBIND11_INTERNALS_VERSION 7

* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under include/pybind11

* Remove obsolete PYBIND11_ACTUALLY_USING_SMART_HOLDER_AS_DEFAULT macro.

* Remove PYBIND11_SMART_HOLDER_ENABLED in ubench/holder_comparison.cpp

* Remove all uses of PYBIND11_SMART_HOLDER_ENABLED under tests/

* Remove `#define PYBIND11_SMART_HOLDER_ENABLED`

* Remove all uses of PYBIND11_SMART_HOLDER_TYPE_CASTERS under tests/

* Remove all uses of PYBIND11_TYPE_CASTER_BASE_HOLDER under tests/

* Add missing `#include <cstdint>`

Example error message (🐍 3.11 • ubuntu-latest • x64, GNU 13.3.0):

```
include/pybind11/detail/value_and_holder.h:56:52: error: ‘uint8_t’ is not a member of ‘std’; did you mean ‘wint_t’?
   56 |             inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
      |                                                    ^~~~~~~
```

* Change PYBIND11_INTERNALS_VERSION to 106: It will be changed to 7 in a follow-on PR that actually changes the internals.
2025-02-22 10:22:20 -08:00

32 lines
760 B
Python

from __future__ import annotations
import pybind11_tests.class_sh_trampoline_unique_ptr as m
class MyClass(m.Class):
def foo(self):
return 10 + self.get_val()
def clone(self):
cloned = MyClass()
cloned.set_val(self.get_val() + 3)
return cloned
def test_m_clone():
obj = MyClass()
while True:
obj.set_val(5)
obj = m.clone(obj)
assert obj.get_val() == 5 + 3
assert obj.foo() == 10 + 5 + 3
return # Comment out for manual leak checking (use `top` command).
def test_m_clone_and_foo():
obj = MyClass()
obj.set_val(7)
while True:
assert m.clone_and_foo(obj) == 10 + 7 + 3
return # Comment out for manual leak checking (use `top` command).