mirror of
https://github.com/pybind/pybind11.git
synced 2024-12-01 17:37:15 +00:00
9be8d84b1c
* 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. ```
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from pybind11_tests import class_sh_property_non_owning as m
|
|
|
|
if not m.defined_PYBIND11_SMART_HOLDER_ENABLED:
|
|
pytest.skip("smart_holder not available.", allow_module_level=True)
|
|
|
|
|
|
@pytest.mark.parametrize("persistent_holder", [True, False])
|
|
@pytest.mark.parametrize(
|
|
("core_fld", "expected"),
|
|
[
|
|
("core_fld_value_ro", (13, 24)),
|
|
("core_fld_value_rw", (13, 24)),
|
|
("core_fld_shared_ptr_ro", (14, 25)),
|
|
("core_fld_shared_ptr_rw", (14, 25)),
|
|
("core_fld_raw_ptr_ro", (14, 25)),
|
|
("core_fld_raw_ptr_rw", (14, 25)),
|
|
("core_fld_unique_ptr_rw", (15, 26)),
|
|
],
|
|
)
|
|
def test_core_fld_common(core_fld, expected, persistent_holder):
|
|
if persistent_holder:
|
|
h = m.DataFieldsHolder(2)
|
|
for i, exp in enumerate(expected):
|
|
c = getattr(h.vec_at(i), core_fld)
|
|
assert c.int_value == exp
|
|
else:
|
|
for i, exp in enumerate(expected):
|
|
c = getattr(m.DataFieldsHolder(2).vec_at(i), core_fld)
|
|
assert c.int_value == exp
|