mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
bd8985aa0f
* Step 1: Establish new `PYBIND11_SMART_HOLDER_ENABLED` macro, but only under include/pybind11/ At the stage `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent. * Systematically replace all `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` with `PYBIND11_SMART_HOLDER_ENABLED` under tests/ and ubench/ As at the previous stage, `PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT` and `PYBIND11_SMART_HOLDER_ENABLED` are still equivalent. * Introduce `PYBIND11_SMART_HOLDER_DISABLE` option. * `#ifdef` out entire `wrap()` function to avoid `unused-parameter` warning-as-error under macos-13 ``` /Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:23: error: unused parameter 'm' [-Werror,-Wunused-parameter] void wrap(py::module_ m, const char *py_class_name) { ^ /Users/runner/work/pybind11/pybind11/tests/test_class_sh_trampoline_basic.cpp:67:38: error: unused parameter 'py_class_name' [-Werror,-Wunused-parameter] void wrap(py::module_ m, const char *py_class_name) { ^ 2 errors generated. ```
37 lines
896 B
Python
37 lines
896 B
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
import pybind11_tests.class_sh_trampoline_unique_ptr as m
|
|
|
|
if not m.defined_PYBIND11_SMART_HOLDER_ENABLED:
|
|
pytest.skip("smart_holder not available.", allow_module_level=True)
|
|
|
|
|
|
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).
|