mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 23:22:01 +00:00
Merge branch 'pybind:master' into master
This commit is contained in:
commit
0d65ba339c
52
.github/workflows/ci.yml
vendored
52
.github/workflows/ci.yml
vendored
@ -164,7 +164,6 @@ jobs:
|
||||
-DDOWNLOAD_EIGEN=ON
|
||||
-DCMAKE_CXX_STANDARD=17
|
||||
-DPYBIND11_INTERNALS_VERSION=10000000
|
||||
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
|
||||
${{ matrix.args }}
|
||||
|
||||
- name: Build (unstable ABI)
|
||||
@ -497,6 +496,24 @@ jobs:
|
||||
- name: Interface test
|
||||
run: cmake --build build --target test_cmake_build
|
||||
|
||||
- name: Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
if: matrix.gcc == '12'
|
||||
shell: bash
|
||||
run: >
|
||||
cmake -S . -B build_partial
|
||||
-DPYBIND11_WERROR=ON
|
||||
-DDOWNLOAD_CATCH=ON
|
||||
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
|
||||
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
||||
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
|
||||
|
||||
- name: Build - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
if: matrix.gcc == '12'
|
||||
run: cmake --build build_partial -j 2
|
||||
|
||||
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
if: matrix.gcc == '12'
|
||||
run: cmake --build build_partial --target pytest
|
||||
|
||||
# Testing on ICC using the oneAPI apt repo
|
||||
icc:
|
||||
@ -889,6 +906,21 @@ jobs:
|
||||
- name: Interface test C++20
|
||||
run: cmake --build build --target test_cmake_build
|
||||
|
||||
- name: Configure C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: >
|
||||
cmake -S . -B build_partial
|
||||
-DPYBIND11_WERROR=ON
|
||||
-DDOWNLOAD_CATCH=ON
|
||||
-DDOWNLOAD_EIGEN=ON
|
||||
-DCMAKE_CXX_STANDARD=20
|
||||
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
|
||||
|
||||
- name: Build C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: cmake --build build_partial -j 2
|
||||
|
||||
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: cmake --build build_partial --target pytest
|
||||
|
||||
mingw:
|
||||
name: "🐍 3 • windows-latest • ${{ matrix.sys }}"
|
||||
runs-on: windows-latest
|
||||
@ -1105,5 +1137,23 @@ jobs:
|
||||
- name: Interface test
|
||||
run: cmake --build . --target test_cmake_build -j 2
|
||||
|
||||
- name: CMake Configure - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: >
|
||||
cmake -S . -B build_partial
|
||||
-DPYBIND11_WERROR=ON
|
||||
-DPYBIND11_SIMPLE_GIL_MANAGEMENT=OFF
|
||||
-DDOWNLOAD_CATCH=ON
|
||||
-DDOWNLOAD_EIGEN=ON
|
||||
-DCMAKE_CXX_COMPILER=clang++
|
||||
-DCMAKE_CXX_STANDARD=17
|
||||
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
|
||||
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
|
||||
|
||||
- name: Build - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: cmake --build build_partial -j 2
|
||||
|
||||
- name: Python tests - Exercise cmake -DPYBIND11_TEST_OVERRIDE
|
||||
run: cmake --build build_partial --target pytest -j 2
|
||||
|
||||
- name: Clean directory
|
||||
run: git clean -fdx
|
||||
|
1
.github/workflows/upstream.yml
vendored
1
.github/workflows/upstream.yml
vendored
@ -95,7 +95,6 @@ jobs:
|
||||
-DDOWNLOAD_EIGEN=ON
|
||||
-DCMAKE_CXX_STANDARD=17
|
||||
-DPYBIND11_INTERNALS_VERSION=10000000
|
||||
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"
|
||||
|
||||
- name: Build (unstable ABI)
|
||||
run: cmake --build build17max -j 2
|
||||
|
@ -58,6 +58,16 @@ interactive Python session demonstrating this example is shown below:
|
||||
Static member functions can be bound in the same way using
|
||||
:func:`class_::def_static`.
|
||||
|
||||
.. note::
|
||||
|
||||
Binding C++ types in unnamed namespaces (also known as anonymous namespaces)
|
||||
works reliably on many platforms, but not all. The `XFAIL_CONDITION` in
|
||||
tests/test_unnamed_namespace_a.py encodes the currently known conditions.
|
||||
For background see `#4319 <https://github.com/pybind/pybind11/pull/4319>`_.
|
||||
If portability is a concern, it is therefore not recommended to bind C++
|
||||
types in unnamed namespaces. It will be safest to manually pick unique
|
||||
namespace names.
|
||||
|
||||
Keyword and default arguments
|
||||
=============================
|
||||
It is possible to specify keyword and default arguments using the syntax
|
||||
|
@ -123,7 +123,8 @@ inline void tls_replace_value(PYBIND11_TLS_KEY_REF key, void *value) {
|
||||
// libstdc++, this doesn't happen: equality and the type_index hash are based on the type name,
|
||||
// which works. If not under a known-good stl, provide our own name-based hash and equality
|
||||
// functions that use the type name.
|
||||
#if defined(__GLIBCXX__)
|
||||
#if (PYBIND11_INTERNALS_VERSION <= 4 && defined(__GLIBCXX__)) \
|
||||
|| (PYBIND11_INTERNALS_VERSION >= 5 && !defined(_LIBCPP_VERSION))
|
||||
inline bool same_type(const std::type_info &lhs, const std::type_info &rhs) { return lhs == rhs; }
|
||||
using type_hash = std::hash<std::type_index>;
|
||||
using type_equal_to = std::equal_to<std::type_index>;
|
||||
|
@ -156,6 +156,8 @@ set(PYBIND11_TEST_FILES
|
||||
test_tagbased_polymorphic
|
||||
test_thread
|
||||
test_union
|
||||
test_unnamed_namespace_a
|
||||
test_unnamed_namespace_b
|
||||
test_vector_unique_ptr_member
|
||||
test_virtual_functions)
|
||||
|
||||
|
@ -319,7 +319,7 @@ def test_error_already_set_what_with_happy_exceptions(
|
||||
|
||||
@pytest.mark.skipif(
|
||||
# Intentionally very specific:
|
||||
"sys.version_info == (3, 12, 0, 'alpha', 6)",
|
||||
"sys.version_info == (3, 12, 0, 'alpha', 7)",
|
||||
reason="WIP: https://github.com/python/cpython/issues/102594",
|
||||
)
|
||||
@pytest.mark.skipif("env.PYPY", reason="PyErr_NormalizeException Segmentation fault")
|
||||
|
38
tests/test_unnamed_namespace_a.cpp
Normal file
38
tests/test_unnamed_namespace_a.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "pybind11_tests.h"
|
||||
|
||||
namespace {
|
||||
struct any_struct {};
|
||||
} // namespace
|
||||
|
||||
TEST_SUBMODULE(unnamed_namespace_a, m) {
|
||||
if (py::detail::get_type_info(typeid(any_struct)) == nullptr) {
|
||||
py::class_<any_struct>(m, "unnamed_namespace_a_any_struct");
|
||||
} else {
|
||||
m.attr("unnamed_namespace_a_any_struct") = py::none();
|
||||
}
|
||||
m.attr("PYBIND11_INTERNALS_VERSION") = PYBIND11_INTERNALS_VERSION;
|
||||
m.attr("defined_WIN32_or__WIN32") =
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
m.attr("defined___clang__") =
|
||||
#if defined(__clang__)
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
m.attr("defined__LIBCPP_VERSION") =
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
m.attr("defined___GLIBCXX__") =
|
||||
#if defined(__GLIBCXX__)
|
||||
true;
|
||||
#else
|
||||
false;
|
||||
#endif
|
||||
}
|
34
tests/test_unnamed_namespace_a.py
Normal file
34
tests/test_unnamed_namespace_a.py
Normal file
@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from pybind11_tests import unnamed_namespace_a as m
|
||||
from pybind11_tests import unnamed_namespace_b as mb
|
||||
|
||||
XFAIL_CONDITION = (
|
||||
"(m.PYBIND11_INTERNALS_VERSION <= 4 and (m.defined___clang__ or not m.defined___GLIBCXX__))"
|
||||
" or "
|
||||
"(m.PYBIND11_INTERNALS_VERSION >= 5 and not m.defined_WIN32_or__WIN32"
|
||||
" and "
|
||||
"(m.defined___clang__ or m.defined__LIBCPP_VERSION))"
|
||||
)
|
||||
XFAIL_REASON = "Known issues: https://github.com/pybind/pybind11/pull/4319"
|
||||
|
||||
|
||||
@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=False)
|
||||
@pytest.mark.parametrize(
|
||||
"any_struct", [m.unnamed_namespace_a_any_struct, mb.unnamed_namespace_b_any_struct]
|
||||
)
|
||||
def test_have_class_any_struct(any_struct):
|
||||
assert any_struct is not None
|
||||
|
||||
|
||||
def test_have_at_least_one_class_any_struct():
|
||||
assert (
|
||||
m.unnamed_namespace_a_any_struct is not None
|
||||
or mb.unnamed_namespace_b_any_struct is not None
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=True)
|
||||
def test_have_both_class_any_struct():
|
||||
assert m.unnamed_namespace_a_any_struct is not None
|
||||
assert mb.unnamed_namespace_b_any_struct is not None
|
13
tests/test_unnamed_namespace_b.cpp
Normal file
13
tests/test_unnamed_namespace_b.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "pybind11_tests.h"
|
||||
|
||||
namespace {
|
||||
struct any_struct {};
|
||||
} // namespace
|
||||
|
||||
TEST_SUBMODULE(unnamed_namespace_b, m) {
|
||||
if (py::detail::get_type_info(typeid(any_struct)) == nullptr) {
|
||||
py::class_<any_struct>(m, "unnamed_namespace_b_any_struct");
|
||||
} else {
|
||||
m.attr("unnamed_namespace_b_any_struct") = py::none();
|
||||
}
|
||||
}
|
5
tests/test_unnamed_namespace_b.py
Normal file
5
tests/test_unnamed_namespace_b.py
Normal file
@ -0,0 +1,5 @@
|
||||
from pybind11_tests import unnamed_namespace_b as m
|
||||
|
||||
|
||||
def test_have_attr_any_struct():
|
||||
assert hasattr(m, "unnamed_namespace_b_any_struct")
|
Loading…
Reference in New Issue
Block a user