From a85bac82b10ee556f6fedb4eb43eb67f94559e73 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 7 Jul 2022 18:02:35 -0700 Subject: [PATCH 1/8] Add test_namespace_visibility To probe environment/toolchain/platform-specific behavior under the exact same conditions as normal tests. (An earlier version of this code was used to inform PR #4043.) --- tests/CMakeLists.txt | 9 +++++-- tests/namespace_visibility.h | 31 +++++++++++++++++++++ tests/namespace_visibility_1.cpp | 24 +++++++++++++++++ tests/namespace_visibility_1s.cpp | 17 ++++++++++++ tests/namespace_visibility_2.cpp | 17 ++++++++++++ tests/test_namespace_visibility.py | 43 ++++++++++++++++++++++++++++++ 6 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 tests/namespace_visibility.h create mode 100644 tests/namespace_visibility_1.cpp create mode 100644 tests/namespace_visibility_1s.cpp create mode 100644 tests/namespace_visibility_2.cpp create mode 100644 tests/test_namespace_visibility.py diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4769ea6776..5cfc58d68f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -157,6 +157,7 @@ set(PYBIND11_TEST_FILES test_methods_and_attributes test_modules test_multiple_inheritance + test_namespace_visibility.py test_numpy_array test_numpy_dtypes test_numpy_vectorize @@ -236,6 +237,7 @@ tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils") tests_extra_targets("test_class_sh_module_local.py" "class_sh_module_local_0;class_sh_module_local_1;class_sh_module_local_2") +tests_extra_targets("test_namespace_visibility.py" "namespace_visibility_1;namespace_visibility_2") set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git" @@ -426,8 +428,11 @@ if(PYBIND11_CUDA_TESTS) endif() foreach(target ${test_targets}) - set(test_files ${PYBIND11_TEST_FILES}) - if(NOT "${target}" STREQUAL "pybind11_tests") + if("${target}" STREQUAL "pybind11_tests") + set(test_files ${PYBIND11_TEST_FILES}) + elseif("${target}" STREQUAL "namespace_visibility_1") + set(test_files namespace_visibility_1s.cpp) + else() set(test_files "") endif() diff --git a/tests/namespace_visibility.h b/tests/namespace_visibility.h new file mode 100644 index 0000000000..9ff407a53d --- /dev/null +++ b/tests/namespace_visibility.h @@ -0,0 +1,31 @@ +// Copyright (c) 2022 The Pybind Development Team. +// All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#pragma once + +#include + +#ifdef __GNUG__ +# define PYBIND11_NS_VIS_U /* unspecified */ +# define PYBIND11_NS_VIS_H __attribute__((visibility("hidden"))) +#else +# define PYBIND11_NS_VIS_U +# define PYBIND11_NS_VIS_H +#endif + +#define PYBIND11_NS_VIS_FUNC \ + inline std::ptrdiff_t func() { \ + static std::ptrdiff_t value = 0; \ + return reinterpret_cast(&value); \ + } + +#define PYBIND11_NS_VIS_DEFS \ + m.def("ns_vis_uuu_func", pybind11_ns_vis_uuu::func); \ + m.def("ns_vis_uuh_func", pybind11_ns_vis_uuh::func); \ + m.def("ns_vis_uhu_func", pybind11_ns_vis_uhu::func); \ + m.def("ns_vis_uhh_func", pybind11_ns_vis_uhh::func); \ + m.def("ns_vis_huu_func", pybind11_ns_vis_huu::func); \ + m.def("ns_vis_huh_func", pybind11_ns_vis_huh::func); \ + m.def("ns_vis_hhu_func", pybind11_ns_vis_hhu::func); \ + m.def("ns_vis_hhh_func", pybind11_ns_vis_hhh::func); diff --git a/tests/namespace_visibility_1.cpp b/tests/namespace_visibility_1.cpp new file mode 100644 index 0000000000..43c50c0a16 --- /dev/null +++ b/tests/namespace_visibility_1.cpp @@ -0,0 +1,24 @@ +#include "pybind11/pybind11.h" +#include "namespace_visibility.h" + +// clang-format off +namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +// ^ ^ +// bit used .............. here +// clang-format on + +void namespace_visibility_1s(pybind11::module_ &m); + +PYBIND11_MODULE(namespace_visibility_1, m) { + PYBIND11_NS_VIS_DEFS + + auto sm = m.def_submodule("submodule"); + namespace_visibility_1s(sm); +} diff --git a/tests/namespace_visibility_1s.cpp b/tests/namespace_visibility_1s.cpp new file mode 100644 index 0000000000..5e5a0a625d --- /dev/null +++ b/tests/namespace_visibility_1s.cpp @@ -0,0 +1,17 @@ +#include "pybind11/pybind11.h" +#include "namespace_visibility.h" + +// clang-format off +namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +// ^ ^ +// bit used ............. here +// clang-format on + +void namespace_visibility_1s(pybind11::module_ &m) { PYBIND11_NS_VIS_DEFS } diff --git a/tests/namespace_visibility_2.cpp b/tests/namespace_visibility_2.cpp new file mode 100644 index 0000000000..178221c25d --- /dev/null +++ b/tests/namespace_visibility_2.cpp @@ -0,0 +1,17 @@ +#include "pybind11/pybind11.h" +#include "namespace_visibility.h" + +// clang-format off +namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } +namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } +// ^ ^ +// bit used ............ here +// clang-format on + +PYBIND11_MODULE(namespace_visibility_2, m) { PYBIND11_NS_VIS_DEFS } diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py new file mode 100644 index 0000000000..b90a6f4357 --- /dev/null +++ b/tests/test_namespace_visibility.py @@ -0,0 +1,43 @@ +# This is not really a unit test, but probing environment/toolchain/platform-specific +# behavior under the exact same conditions as normal tests. +# The results are useful to understanding the effects of, e.g., removing +# `-fvisibility=hidden` or `__attribute__((visibility("hidden")))`, or linking +# extensions statically with the core Python interpreter. + +import itertools + +import namespace_visibility_1 +import namespace_visibility_2 +import pytest + + +def test_namespace_visibility(): + modules = ( + namespace_visibility_1, + namespace_visibility_1.submodule, + namespace_visibility_2, + ) + unique_pointer_labels = "ABC" + unique_pointers_observed = [] + # u = visibility unspecified + # h = visibility hidden + for visibility in itertools.product(*([("u", "h")] * len(modules))): + # See functions in namespace_visibility_*.cpp + func = "ns_vis_" + "".join(visibility) + "_func" + ptrs = [] + uq_ptrs_obs = "" + for vis, m in zip(visibility, modules): + ptr = getattr(m, func)() + ptrs.append(ptr) + lbl = unique_pointer_labels[ptrs.index(ptr)] + if vis == "h": + # Encode u/h info as upper/lower case to make the final result + # as compact as possible. + lbl = lbl.lower() + uq_ptrs_obs += lbl + unique_pointers_observed.append(uq_ptrs_obs) + all_unique_pointers_observed = ":".join(unique_pointers_observed) + if all_unique_pointers_observed != "AAC:AAc:AaC:Aac:aAC:aAc:aaC:aac": + pytest.skip( + f"UNUSUAL all_unique_pointers_observed: {all_unique_pointers_observed}" + ) From c28535748c9ca2f07b5f8d72dd76b2f62cf814fb Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 10:50:04 -0700 Subject: [PATCH 2/8] Disable flake8 in ubench/holder_comparison_*.py, to suppress new & useless diagnostics. --- ubench/holder_comparison.py | 4 ++++ ubench/holder_comparison_extract_sheet_data.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ubench/holder_comparison.py b/ubench/holder_comparison.py index f74f4a2826..46b96ad4de 100644 --- a/ubench/holder_comparison.py +++ b/ubench/holder_comparison.py @@ -1,5 +1,9 @@ """Simple comparison of holder performances, relative to unique_ptr holder.""" +# Targeting B023, but there does not seem to be a way to globally suppress just +# that one diagnostic. +# flake8: noqa + import collections import sys import time diff --git a/ubench/holder_comparison_extract_sheet_data.py b/ubench/holder_comparison_extract_sheet_data.py index 27089a9943..3cfa2da6be 100644 --- a/ubench/holder_comparison_extract_sheet_data.py +++ b/ubench/holder_comparison_extract_sheet_data.py @@ -1,5 +1,8 @@ """Extract mean ratios from holder_comparison.py output.""" +# Targeting B023, but there does not seem to be a way to globally suppress just +# that one diagnostic. +# flake8: noqa import sys from typing import List, Optional From bbc1f9b40498cc8975bd1ebdc55b6788f2f12bef Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 11:13:55 -0700 Subject: [PATCH 3/8] Disable namespace_visibility_1s.cpp (tosee if that resolves the MSVC and CUDA `test_cross_module_exception_translator` failures). --- tests/CMakeLists.txt | 4 ++-- tests/namespace_visibility_1.cpp | 6 +++--- tests/test_namespace_visibility.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5cfc58d68f..b48eb68168 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -430,8 +430,8 @@ endif() foreach(target ${test_targets}) if("${target}" STREQUAL "pybind11_tests") set(test_files ${PYBIND11_TEST_FILES}) - elseif("${target}" STREQUAL "namespace_visibility_1") - set(test_files namespace_visibility_1s.cpp) + # elseif("${target}" STREQUAL "namespace_visibility_1") + # set(test_files namespace_visibility_1s.cpp) else() set(test_files "") endif() diff --git a/tests/namespace_visibility_1.cpp b/tests/namespace_visibility_1.cpp index 43c50c0a16..1490c99156 100644 --- a/tests/namespace_visibility_1.cpp +++ b/tests/namespace_visibility_1.cpp @@ -14,11 +14,11 @@ namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } // bit used .............. here // clang-format on -void namespace_visibility_1s(pybind11::module_ &m); +// void namespace_visibility_1s(pybind11::module_ &m); PYBIND11_MODULE(namespace_visibility_1, m) { PYBIND11_NS_VIS_DEFS - auto sm = m.def_submodule("submodule"); - namespace_visibility_1s(sm); + // auto sm = m.def_submodule("submodule"); + // namespace_visibility_1s(sm); } diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py index b90a6f4357..c75cf959d2 100644 --- a/tests/test_namespace_visibility.py +++ b/tests/test_namespace_visibility.py @@ -14,7 +14,7 @@ def test_namespace_visibility(): modules = ( namespace_visibility_1, - namespace_visibility_1.submodule, + namespace_visibility_1, # .submodule, namespace_visibility_2, ) unique_pointer_labels = "ABC" From c4d3e4ad4a4399df9ab5ac36fd424678bec94057 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 11:34:31 -0700 Subject: [PATCH 4/8] Turn off flake8 completely for ubench (the Strip unnecessary `# noqa`s action un-helpfully removed the added noqa). --- .pre-commit-config.yaml | 2 +- ubench/holder_comparison.py | 4 ---- ubench/holder_comparison_extract_sheet_data.py | 3 --- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 86f71def88..fd07b2b008 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -105,7 +105,7 @@ repos: rev: "4.0.1" hooks: - id: flake8 - exclude: ^(docs/.*|tools/.*)$ + exclude: ^(docs/.*|tools/.*|ubench/.*)$ additional_dependencies: *flake8_dependencies # PyLint has native support - not always usable, but works for us diff --git a/ubench/holder_comparison.py b/ubench/holder_comparison.py index 46b96ad4de..f74f4a2826 100644 --- a/ubench/holder_comparison.py +++ b/ubench/holder_comparison.py @@ -1,9 +1,5 @@ """Simple comparison of holder performances, relative to unique_ptr holder.""" -# Targeting B023, but there does not seem to be a way to globally suppress just -# that one diagnostic. -# flake8: noqa - import collections import sys import time diff --git a/ubench/holder_comparison_extract_sheet_data.py b/ubench/holder_comparison_extract_sheet_data.py index 3cfa2da6be..27089a9943 100644 --- a/ubench/holder_comparison_extract_sheet_data.py +++ b/ubench/holder_comparison_extract_sheet_data.py @@ -1,8 +1,5 @@ """Extract mean ratios from holder_comparison.py output.""" -# Targeting B023, but there does not seem to be a way to globally suppress just -# that one diagnostic. -# flake8: noqa import sys from typing import List, Optional From c805bdb94c6c81020a0c17230b19f57ce84ec122 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 11:44:10 -0700 Subject: [PATCH 5/8] Disable test_namespace_visibility completely. Just keep the two .cpp files, only setting the module docstring and doing nothing else. --- tests/namespace_visibility_1.cpp | 6 +++++- tests/namespace_visibility_2.cpp | 8 +++++++- tests/test_namespace_visibility.py | 3 +++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/namespace_visibility_1.cpp b/tests/namespace_visibility_1.cpp index 1490c99156..8a3e29d53c 100644 --- a/tests/namespace_visibility_1.cpp +++ b/tests/namespace_visibility_1.cpp @@ -1,6 +1,7 @@ #include "pybind11/pybind11.h" #include "namespace_visibility.h" +#ifdef NEVER_DEFINED // clang-format off namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } @@ -13,11 +14,14 @@ namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } // ^ ^ // bit used .............. here // clang-format on +#endif // void namespace_visibility_1s(pybind11::module_ &m); PYBIND11_MODULE(namespace_visibility_1, m) { - PYBIND11_NS_VIS_DEFS + m.doc() = "DISABLED"; + + // PYBIND11_NS_VIS_DEFS // auto sm = m.def_submodule("submodule"); // namespace_visibility_1s(sm); diff --git a/tests/namespace_visibility_2.cpp b/tests/namespace_visibility_2.cpp index 178221c25d..dccc336892 100644 --- a/tests/namespace_visibility_2.cpp +++ b/tests/namespace_visibility_2.cpp @@ -1,6 +1,7 @@ #include "pybind11/pybind11.h" #include "namespace_visibility.h" +#ifdef NEVER_DEFINED // clang-format off namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } @@ -13,5 +14,10 @@ namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } // ^ ^ // bit used ............ here // clang-format on +#endif -PYBIND11_MODULE(namespace_visibility_2, m) { PYBIND11_NS_VIS_DEFS } +PYBIND11_MODULE(namespace_visibility_2, m) { + m.doc() = "DISABLED"; + + // PYBIND11_NS_VIS_DEFS +} diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py index c75cf959d2..bc70373bf5 100644 --- a/tests/test_namespace_visibility.py +++ b/tests/test_namespace_visibility.py @@ -11,6 +11,9 @@ import pytest +@pytest.mark.skipif( + namespace_visibility_1.__doc__ == "DISABLED", reason="DISABLED for debugging" +) def test_namespace_visibility(): modules = ( namespace_visibility_1, From 5ce9cdecdbea6613700adda472b3c6a8d2edefe3 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 12:11:03 -0700 Subject: [PATCH 6/8] Stripping down even further. --- tests/CMakeLists.txt | 2 -- tests/namespace_visibility.h | 31 ------------------------ tests/namespace_visibility_1.cpp | 27 +-------------------- tests/namespace_visibility_1s.cpp | 17 ------------- tests/namespace_visibility_2.cpp | 22 +---------------- tests/test_namespace_visibility.py | 39 +++--------------------------- 6 files changed, 5 insertions(+), 133 deletions(-) delete mode 100644 tests/namespace_visibility.h delete mode 100644 tests/namespace_visibility_1s.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b48eb68168..70209575a2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -430,8 +430,6 @@ endif() foreach(target ${test_targets}) if("${target}" STREQUAL "pybind11_tests") set(test_files ${PYBIND11_TEST_FILES}) - # elseif("${target}" STREQUAL "namespace_visibility_1") - # set(test_files namespace_visibility_1s.cpp) else() set(test_files "") endif() diff --git a/tests/namespace_visibility.h b/tests/namespace_visibility.h deleted file mode 100644 index 9ff407a53d..0000000000 --- a/tests/namespace_visibility.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2022 The Pybind Development Team. -// All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -#pragma once - -#include - -#ifdef __GNUG__ -# define PYBIND11_NS_VIS_U /* unspecified */ -# define PYBIND11_NS_VIS_H __attribute__((visibility("hidden"))) -#else -# define PYBIND11_NS_VIS_U -# define PYBIND11_NS_VIS_H -#endif - -#define PYBIND11_NS_VIS_FUNC \ - inline std::ptrdiff_t func() { \ - static std::ptrdiff_t value = 0; \ - return reinterpret_cast(&value); \ - } - -#define PYBIND11_NS_VIS_DEFS \ - m.def("ns_vis_uuu_func", pybind11_ns_vis_uuu::func); \ - m.def("ns_vis_uuh_func", pybind11_ns_vis_uuh::func); \ - m.def("ns_vis_uhu_func", pybind11_ns_vis_uhu::func); \ - m.def("ns_vis_uhh_func", pybind11_ns_vis_uhh::func); \ - m.def("ns_vis_huu_func", pybind11_ns_vis_huu::func); \ - m.def("ns_vis_huh_func", pybind11_ns_vis_huh::func); \ - m.def("ns_vis_hhu_func", pybind11_ns_vis_hhu::func); \ - m.def("ns_vis_hhh_func", pybind11_ns_vis_hhh::func); diff --git a/tests/namespace_visibility_1.cpp b/tests/namespace_visibility_1.cpp index 8a3e29d53c..96e602e38e 100644 --- a/tests/namespace_visibility_1.cpp +++ b/tests/namespace_visibility_1.cpp @@ -1,28 +1,3 @@ #include "pybind11/pybind11.h" -#include "namespace_visibility.h" -#ifdef NEVER_DEFINED -// clang-format off -namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -// ^ ^ -// bit used .............. here -// clang-format on -#endif - -// void namespace_visibility_1s(pybind11::module_ &m); - -PYBIND11_MODULE(namespace_visibility_1, m) { - m.doc() = "DISABLED"; - - // PYBIND11_NS_VIS_DEFS - - // auto sm = m.def_submodule("submodule"); - // namespace_visibility_1s(sm); -} +PYBIND11_MODULE(namespace_visibility_1, m) { m.doc() = "ns_vis_1"; } diff --git a/tests/namespace_visibility_1s.cpp b/tests/namespace_visibility_1s.cpp deleted file mode 100644 index 5e5a0a625d..0000000000 --- a/tests/namespace_visibility_1s.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "pybind11/pybind11.h" -#include "namespace_visibility.h" - -// clang-format off -namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -// ^ ^ -// bit used ............. here -// clang-format on - -void namespace_visibility_1s(pybind11::module_ &m) { PYBIND11_NS_VIS_DEFS } diff --git a/tests/namespace_visibility_2.cpp b/tests/namespace_visibility_2.cpp index dccc336892..b596cd3693 100644 --- a/tests/namespace_visibility_2.cpp +++ b/tests/namespace_visibility_2.cpp @@ -1,23 +1,3 @@ #include "pybind11/pybind11.h" -#include "namespace_visibility.h" -#ifdef NEVER_DEFINED -// clang-format off -namespace pybind11_ns_vis_uuu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uuh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_uhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_huh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhu PYBIND11_NS_VIS_U { PYBIND11_NS_VIS_FUNC } -namespace pybind11_ns_vis_hhh PYBIND11_NS_VIS_H { PYBIND11_NS_VIS_FUNC } -// ^ ^ -// bit used ............ here -// clang-format on -#endif - -PYBIND11_MODULE(namespace_visibility_2, m) { - m.doc() = "DISABLED"; - - // PYBIND11_NS_VIS_DEFS -} +PYBIND11_MODULE(namespace_visibility_2, m) { m.doc() = "ns_vis_2"; } diff --git a/tests/test_namespace_visibility.py b/tests/test_namespace_visibility.py index bc70373bf5..e641449177 100644 --- a/tests/test_namespace_visibility.py +++ b/tests/test_namespace_visibility.py @@ -1,46 +1,13 @@ -# This is not really a unit test, but probing environment/toolchain/platform-specific -# behavior under the exact same conditions as normal tests. -# The results are useful to understanding the effects of, e.g., removing -# `-fvisibility=hidden` or `__attribute__((visibility("hidden")))`, or linking -# extensions statically with the core Python interpreter. - -import itertools - import namespace_visibility_1 import namespace_visibility_2 import pytest -@pytest.mark.skipif( - namespace_visibility_1.__doc__ == "DISABLED", reason="DISABLED for debugging" -) def test_namespace_visibility(): modules = ( namespace_visibility_1, - namespace_visibility_1, # .submodule, namespace_visibility_2, ) - unique_pointer_labels = "ABC" - unique_pointers_observed = [] - # u = visibility unspecified - # h = visibility hidden - for visibility in itertools.product(*([("u", "h")] * len(modules))): - # See functions in namespace_visibility_*.cpp - func = "ns_vis_" + "".join(visibility) + "_func" - ptrs = [] - uq_ptrs_obs = "" - for vis, m in zip(visibility, modules): - ptr = getattr(m, func)() - ptrs.append(ptr) - lbl = unique_pointer_labels[ptrs.index(ptr)] - if vis == "h": - # Encode u/h info as upper/lower case to make the final result - # as compact as possible. - lbl = lbl.lower() - uq_ptrs_obs += lbl - unique_pointers_observed.append(uq_ptrs_obs) - all_unique_pointers_observed = ":".join(unique_pointers_observed) - if all_unique_pointers_observed != "AAC:AAc:AaC:Aac:aAC:aAc:aaC:aac": - pytest.skip( - f"UNUSUAL all_unique_pointers_observed: {all_unique_pointers_observed}" - ) + for m in modules: + if m.__doc__ != "ns_vis_1": + pytest.skip(f"Not surprised: {m.__doc__}") From f572bdfc0af94af8f6f5f0d2659915c357a37349 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 12:35:03 -0700 Subject: [PATCH 7/8] Undo if-else change in CMakeLists.txt --- tests/CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 70209575a2..f25d38cdbc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -428,9 +428,8 @@ if(PYBIND11_CUDA_TESTS) endif() foreach(target ${test_targets}) - if("${target}" STREQUAL "pybind11_tests") - set(test_files ${PYBIND11_TEST_FILES}) - else() + set(test_files ${PYBIND11_TEST_FILES}) + if(NOT "${target}" STREQUAL "pybind11_tests") set(test_files "") endif() From 6c87f26d1c3a3811f6f3d1bbc2004619e50e8995 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 8 Jul 2022 13:25:07 -0700 Subject: [PATCH 8/8] Undo all changes in CMakeLists.txt (just keep the extra .cpp and .py files). --- tests/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f25d38cdbc..4769ea6776 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -157,7 +157,6 @@ set(PYBIND11_TEST_FILES test_methods_and_attributes test_modules test_multiple_inheritance - test_namespace_visibility.py test_numpy_array test_numpy_dtypes test_numpy_vectorize @@ -237,7 +236,6 @@ tests_extra_targets("test_exceptions.py" "cross_module_interleaved_error_already tests_extra_targets("test_gil_scoped.py" "cross_module_gil_utils") tests_extra_targets("test_class_sh_module_local.py" "class_sh_module_local_0;class_sh_module_local_1;class_sh_module_local_2") -tests_extra_targets("test_namespace_visibility.py" "namespace_visibility_1;namespace_visibility_2") set(PYBIND11_EIGEN_REPO "https://gitlab.com/libeigen/eigen.git"