mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-15 01:44:44 +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. ```
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from pybind11_tests import class_sh_inheritance as m
|
|
|
|
if not m.defined_PYBIND11_SMART_HOLDER_ENABLED:
|
|
pytest.skip("smart_holder not available.", allow_module_level=True)
|
|
|
|
|
|
def test_rtrn_mptr_drvd_pass_cptr_base():
|
|
d = m.rtrn_mptr_drvd()
|
|
i = m.pass_cptr_base(d) # load_impl Case 2a
|
|
assert i == 2 * 100 + 11
|
|
|
|
|
|
def test_rtrn_shmp_drvd_pass_shcp_base():
|
|
d = m.rtrn_shmp_drvd()
|
|
i = m.pass_shcp_base(d) # load_impl Case 2a
|
|
assert i == 2 * 100 + 21
|
|
|
|
|
|
def test_rtrn_mptr_drvd_up_cast_pass_cptr_drvd():
|
|
b = m.rtrn_mptr_drvd_up_cast()
|
|
# the base return is down-cast immediately.
|
|
assert b.__class__.__name__ == "drvd"
|
|
i = m.pass_cptr_drvd(b)
|
|
assert i == 2 * 100 + 12
|
|
|
|
|
|
def test_rtrn_shmp_drvd_up_cast_pass_shcp_drvd():
|
|
b = m.rtrn_shmp_drvd_up_cast()
|
|
# the base return is down-cast immediately.
|
|
assert b.__class__.__name__ == "drvd"
|
|
i = m.pass_shcp_drvd(b)
|
|
assert i == 2 * 100 + 22
|
|
|
|
|
|
def test_rtrn_mptr_drvd2_pass_cptr_bases():
|
|
d = m.rtrn_mptr_drvd2()
|
|
i1 = m.pass_cptr_base1(d) # load_impl Case 2c
|
|
assert i1 == 3 * 110 + 4 * 120 + 21
|
|
i2 = m.pass_cptr_base2(d)
|
|
assert i2 == 3 * 110 + 4 * 120 + 22
|
|
|
|
|
|
def test_rtrn_mptr_drvd2_up_casts_pass_cptr_drvd2():
|
|
b1 = m.rtrn_mptr_drvd2_up_cast1()
|
|
assert b1.__class__.__name__ == "drvd2"
|
|
i1 = m.pass_cptr_drvd2(b1)
|
|
assert i1 == 3 * 110 + 4 * 120 + 23
|
|
b2 = m.rtrn_mptr_drvd2_up_cast2()
|
|
assert b2.__class__.__name__ == "drvd2"
|
|
i2 = m.pass_cptr_drvd2(b2)
|
|
assert i2 == 3 * 110 + 4 * 120 + 23
|
|
|
|
|
|
def test_python_drvd2():
|
|
class Drvd2(m.base1, m.base2):
|
|
def __init__(self):
|
|
m.base1.__init__(self)
|
|
m.base2.__init__(self)
|
|
|
|
d = Drvd2()
|
|
i1 = m.pass_cptr_base1(d) # load_impl Case 2b
|
|
assert i1 == 110 + 21
|
|
i2 = m.pass_cptr_base2(d)
|
|
assert i2 == 120 + 22
|