mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 17:56:02 +00:00
* tests: add regressions for shared_ptr reference_internal fallback * fix: avoid copy constructor instantiation in shared_ptr fallback cast * Remove stray empty line * tests: rename PyTorch shared_ptr regression test files * refactor: add cast_non_owning helper for reference-like casts Name the non-owning generic cast path so callers do not have to rediscover that reference-like policies must pass null copy/move constructor callbacks. This keeps the shared_ptr reference_internal fallback self-documenting and points future maintainers toward the safe API. Made-with: Cursor * tests: guard deprecated-copy warning probes with __has_warning Use __has_warning for the Clang-only regression test so older compiler jobs skip unsupported warning groups instead of failing with -Wunknown-warning-option. A simple __clang_major__ >= 13 guard would be shorter, but it bakes in a version cutoff; __has_warning is slightly more verbose while being more robust to vendor builds, backports, and future packaging differences. Made-with: Cursor --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
26 lines
598 B
Python
26 lines
598 B
Python
from __future__ import annotations
|
|
|
|
from pybind11_tests import pybind11_pytorch_regressions as m
|
|
|
|
|
|
def test_pytorch_like_get_tracing_state_aliases_singleton_shared_ptr():
|
|
a = m._get_tracing_state()
|
|
b = m._get_tracing_state()
|
|
|
|
a.value = 17
|
|
|
|
assert b.value == 17
|
|
assert m._get_tracing_state().value == 17
|
|
|
|
|
|
def test_pytorch_like_compilation_unit_get_interface_aliases_member_shared_ptr():
|
|
cu = m.CompilationUnit()
|
|
|
|
a = cu.get_interface("iface")
|
|
b = cu.get_interface("iface")
|
|
|
|
a.value = 23
|
|
|
|
assert b.value == 23
|
|
assert cu.get_interface("iface").value == 23
|