Skip to content

Commit 664cbd0

Browse files
authored
Add missing test_descr_src_loc in CMakeLists.txt (#30137)
* Add missing (for a long time) `test_descr_src_loc` to CMakeLists.txt * Fix bug in test_descr_src_loc.cpp: `!defined(PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY)` * Disable `type_caster` ODR guard for CUDACC and NVCOMPILER: the missing `test_descr_src_loc` in tests/CMakeLists.txt masked that `src_loc` is not reliable. * Fix ruff error (not sure why this passed when testing locally).
1 parent a25d358 commit 664cbd0

6 files changed

Lines changed: 18 additions & 23 deletions

File tree

include/pybind11/detail/descr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ PYBIND11_NAMESPACE_BEGIN(detail)
4242
// * MSVC 193732825 C++17 windows-2020 is failing for unknown reasons.
4343
// * Intel 2021.6.0.20220226 (g++ 9.4 mode) __builtin_LINE() is unreliable
4444
// (line numbers vary between translation units).
45+
// * NVIDIA 12.2.140 (CUDACC) src_loc is unreliable for unknown reasons.
46+
// * NVHPC 23.5.0 (NVCOMPILER) src_loc is unreliable for unknown reasons.
4547
#if defined(PYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE) \
4648
&& !defined(PYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD) && defined(PYBIND11_CPP17) \
47-
&& !defined(__INTEL_COMPILER) \
49+
&& !defined(__INTEL_COMPILER) && !defined(__CUDACC_VER_MAJOR__) \
50+
&& !defined(__NVCOMPILER_MAJOR__) \
4851
&& (!defined(_MSC_VER) \
4952
|| (_MSC_VER >= 1920 /* MSVC 2019 or newer */ \
5053
&& (_MSC_FULL_VER < 193732825 || _MSC_FULL_VER > 193732826 \

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ set(PYBIND11_TEST_FILES
151151
test_copy_move
152152
test_custom_type_casters
153153
test_custom_type_setup
154+
test_descr_src_loc
154155
test_docstring_options
155156
test_eigen_matrix
156157
test_eigen_tensor

tests/test_descr_src_loc.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ TEST_SUBMODULE(descr_src_loc, m) {
110110
ATTR_BLKC(block_const_name, c6)
111111
ATTR_BLKC(block_const_name, c7)
112112

113+
m.attr("defined_PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY") =
114+
# if !defined(PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY)
115+
false;
116+
# else
117+
true;
113118
ATTR_OFFS(block_underscore)
114119
ATTR_BLKC(block_underscore, c0)
115120
ATTR_BLKC(block_underscore, c1)
@@ -119,6 +124,7 @@ TEST_SUBMODULE(descr_src_loc, m) {
119124
ATTR_BLKC(block_underscore, c5)
120125
ATTR_BLKC(block_underscore, c6)
121126
ATTR_BLKC(block_underscore, c7)
127+
# endif
122128

123129
ATTR_OFFS(block_plus)
124130
ATTR_BLKC(block_plus, c0)

tests/test_descr_src_loc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
@pytest.mark.skipif(m.block_descr_offset is None, reason="Not enabled.")
4646
@pytest.mark.parametrize(("block_name", "expected_text_line"), block_parametrize)
4747
def test_block(block_name, expected_text_line):
48+
if (
49+
block_name == "block_underscore"
50+
and not m.defined_PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY
51+
):
52+
pytest.skip("!defined(PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY)")
4853
offset = getattr(m, f"{block_name}_offset")
4954
for ix, (expected_text, expected_line) in enumerate(expected_text_line):
5055
text, file, line = getattr(m, f"{block_name}_c{ix}")

tests/test_type_caster_odr_guard_1.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,4 @@ TEST_SUBMODULE(type_caster_odr_guard_1, m) {
8282
#else
8383
false;
8484
#endif
85-
86-
m.attr("CUDACC") =
87-
#if defined(__CUDACC_VER_MAJOR__)
88-
PYBIND11_TOSTRING(__CUDACC_VER_MAJOR__) "." PYBIND11_TOSTRING(
89-
__CUDACC_VER_MINOR__) "." PYBIND11_TOSTRING(__CUDACC_VER_BUILD__);
90-
#else
91-
py::none();
92-
#endif
93-
m.attr("NVCOMPILER") =
94-
#if defined(__NVCOMPILER_MAJOR__)
95-
PYBIND11_TOSTRING(__NVCOMPILER_MAJOR__) "." PYBIND11_TOSTRING(
96-
__NVCOMPILER_MINOR__) "." PYBIND11_TOSTRING(__NVCOMPILER_PATCHLEVEL__);
97-
#else
98-
py::none();
99-
#endif
10085
}

tests/test_type_caster_odr_guard_1.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ def test_type_caster_odr_violation_detected_counter():
4545
num_violations = m.type_caster_odr_violation_detected_count()
4646
if num_violations is None:
4747
pytest.skip("type_caster_odr_violation_detected_count() is None")
48-
if num_violations == 0:
49-
if m.if_defined__NO_INLINE__:
50-
pytest.skip(_count_0_message("__NO_INLINE__"))
51-
if m.CUDACC is not None:
52-
pytest.skip(_count_0_message(f"CUDACC = {m.CUDACC}"))
53-
if m.NVCOMPILER is not None:
54-
pytest.skip(_count_0_message(f"NVCOMPILER = {m.NVCOMPILER}"))
48+
if num_violations == 0 and m.if_defined__NO_INLINE__:
49+
pytest.skip(_count_0_message("__NO_INLINE__"))
5550
assert num_violations == 1

0 commit comments

Comments
 (0)