Skip to content

Commit d85bcd8

Browse files
committed
Merge branch 'master' into sh_merge_master
2 parents 6e81be2 + 6de6191 commit d85bcd8

File tree

11 files changed

+166
-14
lines changed

11 files changed

+166
-14
lines changed

.github/workflows/ci.yml

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
run: brew install boost
8484

8585
- name: Update CMake
86-
uses: jwlawson/actions-setup-cmake@v1.13
86+
uses: jwlawson/actions-setup-cmake@v1.14
8787

8888
- name: Cache wheels
8989
if: runner.os == 'macOS'
@@ -165,7 +165,6 @@ jobs:
165165
-DDOWNLOAD_EIGEN=ON
166166
-DCMAKE_CXX_STANDARD=17
167167
-DPYBIND11_INTERNALS_VERSION=10000000
168-
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
169168
${{ matrix.args }}
170169
171170
- name: Build (unstable ABI)
@@ -209,7 +208,7 @@ jobs:
209208
debug: ${{ matrix.python-debug }}
210209

211210
- name: Update CMake
212-
uses: jwlawson/actions-setup-cmake@v1.13
211+
uses: jwlawson/actions-setup-cmake@v1.14
213212

214213
- name: Valgrind cache
215214
if: matrix.valgrind
@@ -475,7 +474,7 @@ jobs:
475474
run: python3 -m pip install --upgrade pip
476475

477476
- name: Update CMake
478-
uses: jwlawson/actions-setup-cmake@v1.13
477+
uses: jwlawson/actions-setup-cmake@v1.14
479478

480479
- name: Configure
481480
shell: bash
@@ -498,6 +497,24 @@ jobs:
498497
- name: Interface test
499498
run: cmake --build build --target test_cmake_build
500499

500+
- name: Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
501+
if: matrix.gcc == '12'
502+
shell: bash
503+
run: >
504+
cmake -S . -B build_partial
505+
-DPYBIND11_WERROR=ON
506+
-DDOWNLOAD_CATCH=ON
507+
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
508+
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
509+
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
510+
511+
- name: Build - Exercise cmake -DPYBIND11_TEST_OVERRIDE
512+
if: matrix.gcc == '12'
513+
run: cmake --build build_partial -j 2
514+
515+
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
516+
if: matrix.gcc == '12'
517+
run: cmake --build build_partial --target pytest
501518

502519
# Testing on ICC using the oneAPI apt repo
503520
icc:
@@ -764,7 +781,7 @@ jobs:
764781
architecture: x86
765782

766783
- name: Update CMake
767-
uses: jwlawson/actions-setup-cmake@v1.13
784+
uses: jwlawson/actions-setup-cmake@v1.14
768785

769786
- name: Prepare MSVC
770787
uses: ilammy/msvc-dev-cmd@v1.12.1
@@ -817,7 +834,7 @@ jobs:
817834
architecture: x86
818835

819836
- name: Update CMake
820-
uses: jwlawson/actions-setup-cmake@v1.13
837+
uses: jwlawson/actions-setup-cmake@v1.14
821838

822839
- name: Prepare MSVC
823840
uses: ilammy/msvc-dev-cmd@v1.12.1
@@ -868,7 +885,7 @@ jobs:
868885
python3 -m pip install -r tests/requirements.txt
869886
870887
- name: Update CMake
871-
uses: jwlawson/actions-setup-cmake@v1.13
888+
uses: jwlawson/actions-setup-cmake@v1.14
872889

873890
- name: Configure C++20
874891
run: >
@@ -890,6 +907,21 @@ jobs:
890907
- name: Interface test C++20
891908
run: cmake --build build --target test_cmake_build
892909

910+
- name: Configure C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
911+
run: >
912+
cmake -S . -B build_partial
913+
-DPYBIND11_WERROR=ON
914+
-DDOWNLOAD_CATCH=ON
915+
-DDOWNLOAD_EIGEN=ON
916+
-DCMAKE_CXX_STANDARD=20
917+
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
918+
919+
- name: Build C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
920+
run: cmake --build build_partial -j 2
921+
922+
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
923+
run: cmake --build build_partial --target pytest
924+
893925
mingw:
894926
name: "🐍 3 • windows-latest • ${{ matrix.sys }}"
895927
runs-on: windows-latest
@@ -1001,7 +1033,7 @@ jobs:
10011033
python-version: ${{ matrix.python }}
10021034

10031035
- name: Update CMake
1004-
uses: jwlawson/actions-setup-cmake@v1.13
1036+
uses: jwlawson/actions-setup-cmake@v1.14
10051037

10061038
- name: Install ninja-build tool
10071039
uses: seanmiddleditch/gha-setup-ninja@v3
@@ -1071,7 +1103,7 @@ jobs:
10711103
run: clang++ --version
10721104

10731105
- name: Update CMake
1074-
uses: jwlawson/actions-setup-cmake@v1.13
1106+
uses: jwlawson/actions-setup-cmake@v1.14
10751107

10761108
- name: Run pip installs
10771109
run: |
@@ -1106,5 +1138,23 @@ jobs:
11061138
- name: Interface test
11071139
run: cmake --build . --target test_cmake_build -j 2
11081140

1141+
- name: CMake Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
1142+
run: >
1143+
cmake -S . -B build_partial
1144+
-DPYBIND11_WERROR=ON
1145+
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF
1146+
-DDOWNLOAD_CATCH=ON
1147+
-DDOWNLOAD_EIGEN=ON
1148+
-DCMAKE_CXX_COMPILER=clang++
1149+
-DCMAKE_CXX_STANDARD=17
1150+
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
1151+
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
1152+
1153+
- name: Build - Exercise cmake -DPYBIND11_TEST_OVERRIDE
1154+
run: cmake --build build_partial -j 2
1155+
1156+
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
1157+
run: cmake --build build_partial --target pytest -j 2
1158+
11091159
- name: Clean directory
11101160
run: git clean -fdx

.github/workflows/configure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
# An action for adding a specific version of CMake:
5757
# https://github.com/jwlawson/actions-setup-cmake
5858
- name: Setup CMake ${{ matrix.cmake }}
59-
uses: jwlawson/actions-setup-cmake@v1.13
59+
uses: jwlawson/actions-setup-cmake@v1.14
6060
with:
6161
cmake-version: ${{ matrix.cmake }}
6262

.github/workflows/upstream.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: sudo apt-get install libboost-dev
3434

3535
- name: Update CMake
36-
uses: jwlawson/actions-setup-cmake@v1.13
36+
uses: jwlawson/actions-setup-cmake@v1.14
3737

3838
- name: Run pip installs
3939
run: |
@@ -95,7 +95,6 @@ jobs:
9595
-DDOWNLOAD_EIGEN=ON
9696
-DCMAKE_CXX_STANDARD=17
9797
-DPYBIND11_INTERNALS_VERSION=10000000
98-
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
9998
10099
- name: Build (unstable ABI)
101100
run: cmake --build build17max -j 2

docs/classes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ interactive Python session demonstrating this example is shown below:
5858
Static member functions can be bound in the same way using
5959
:func:`class_::def_static`.
6060

61+
.. note::
62+
63+
Binding C++ types in unnamed namespaces (also known as anonymous namespaces)
64+
works reliably on many platforms, but not all. The `XFAIL_CONDITION` in
65+
tests/test_unnamed_namespace_a.py encodes the currently known conditions.
66+
For background see `#4319 <https://github.com/pybind/pybind11/pull/4319>`_.
67+
If portability is a concern, it is therefore not recommended to bind C++
68+
types in unnamed namespaces. It will be safest to manually pick unique
69+
namespace names.
70+
6171
Keyword and default arguments
6272
=============================
6373
It is possible to specify keyword and default arguments using the syntax

include/pybind11/detail/internals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ inline void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value) {
124124
// libstdc++, this doesn't happen: equality and the type_index hash are based on the type name,
125125
// which works. If not under a known-good stl, provide our own name-based hash and equality
126126
// functions that use the type name.
127-
#if defined(__GLIBCXX__)
127+
#if (PYBIND11_INTERNALS_VERSION <= 4 && defined(__GLIBCXX__)) \
128+
|| (PYBIND11_INTERNALS_VERSION >= 5 && !defined(_LIBCPP_VERSION))
128129
inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; }
129130
using type_hash = std::hash<std::type_index>;
130131
using type_equal_to = std::equal_to<std::type_index>;

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ set(PYBIND11_TEST_FILES
178178
test_type_caster_odr_guard_1
179179
test_type_caster_odr_guard_2
180180
test_union
181+
test_unnamed_namespace_a
182+
test_unnamed_namespace_b
181183
test_vector_unique_ptr_member
182184
test_virtual_functions)
183185

tests/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_error_already_set_what_with_happy_exceptions(
319319

320320
@pytest.mark.skipif(
321321
# Intentionally very specific:
322-
"sys.version_info == (3, 12, 0, 'alpha', 6)",
322+
"sys.version_info == (3, 12, 0, 'alpha', 7)",
323323
reason="WIP: https://github.com/python/cpython/issues/102594",
324324
)
325325
@pytest.mark.skipif("env.PYPY", reason="PyErr_NormalizeException Segmentation fault")

tests/test_unnamed_namespace_a.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "pybind11_tests.h"
2+
3+
namespace {
4+
struct any_struct {};
5+
} // namespace
6+
7+
TEST_SUBMODULE(unnamed_namespace_a, m) {
8+
if (py::detail::get_type_info(typeid(any_struct)) == nullptr) {
9+
py::class_<any_struct>(m, "unnamed_namespace_a_any_struct");
10+
} else {
11+
m.attr("unnamed_namespace_a_any_struct") = py::none();
12+
}
13+
m.attr("PYBIND11_INTERNALS_VERSION") = PYBIND11_INTERNALS_VERSION;
14+
m.attr("defined_WIN32_or__WIN32") =
15+
#if defined(WIN32) || defined(_WIN32)
16+
true;
17+
#else
18+
false;
19+
#endif
20+
m.attr("defined___clang__") =
21+
#if defined(__clang__)
22+
true;
23+
#else
24+
false;
25+
#endif
26+
m.attr("defined__LIBCPP_VERSION") =
27+
#if defined(_LIBCPP_VERSION)
28+
true;
29+
#else
30+
false;
31+
#endif
32+
m.attr("defined___GLIBCXX__") =
33+
#if defined(__GLIBCXX__)
34+
true;
35+
#else
36+
false;
37+
#endif
38+
}

tests/test_unnamed_namespace_a.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
3+
from pybind11_tests import unnamed_namespace_a as m
4+
from pybind11_tests import unnamed_namespace_b as mb
5+
6+
XFAIL_CONDITION = (
7+
"(m.PYBIND11_INTERNALS_VERSION <= 4 and (m.defined___clang__ or not m.defined___GLIBCXX__))"
8+
" or "
9+
"(m.PYBIND11_INTERNALS_VERSION >= 5 and not m.defined_WIN32_or__WIN32"
10+
" and "
11+
"(m.defined___clang__ or m.defined__LIBCPP_VERSION))"
12+
)
13+
XFAIL_REASON = "Known issues: https://github.com/pybind/pybind11/pull/4319"
14+
15+
16+
@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=False)
17+
@pytest.mark.parametrize(
18+
"any_struct", [m.unnamed_namespace_a_any_struct, mb.unnamed_namespace_b_any_struct]
19+
)
20+
def test_have_class_any_struct(any_struct):
21+
assert any_struct is not None
22+
23+
24+
def test_have_at_least_one_class_any_struct():
25+
assert (
26+
m.unnamed_namespace_a_any_struct is not None
27+
or mb.unnamed_namespace_b_any_struct is not None
28+
)
29+
30+
31+
@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=True)
32+
def test_have_both_class_any_struct():
33+
assert m.unnamed_namespace_a_any_struct is not None
34+
assert mb.unnamed_namespace_b_any_struct is not None

tests/test_unnamed_namespace_b.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "pybind11_tests.h"
2+
3+
namespace {
4+
struct any_struct {};
5+
} // namespace
6+
7+
TEST_SUBMODULE(unnamed_namespace_b, m) {
8+
if (py::detail::get_type_info(typeid(any_struct)) == nullptr) {
9+
py::class_<any_struct>(m, "unnamed_namespace_b_any_struct");
10+
} else {
11+
m.attr("unnamed_namespace_b_any_struct") = py::none();
12+
}
13+
}

0 commit comments

Comments
 (0)