Skip to content

Commit

Permalink
Merge branch 'smart_holder' into pybind11k_merge_sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 2, 2024
2 parents b6032da + 64c886d commit ad48302
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ jobs:
- { gcc: 7, std: 17 }
- { gcc: 8, std: 14 }
- { gcc: 8, std: 17 }
- { gcc: 9, std: 20 }
- { gcc: 10, std: 17 }
- { gcc: 10, std: 20 }
- { gcc: 11, std: 20 }
- { gcc: 12, std: 20 }
- { gcc: 13, std: 20 }
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci_sh_def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ jobs:
- { gcc: 7, std: 17 }
- { gcc: 8, std: 14 }
- { gcc: 8, std: 17 }
- { gcc: 9, std: 20 }
- { gcc: 10, std: 17 }
- { gcc: 10, std: 20 }
- { gcc: 11, std: 20 }
- { gcc: 12, std: 20 }
- { gcc: 13, std: 20 }
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/ci_sh_def.yml.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- ci.yml 2024-06-21 22:56:01.205982412 -0700
+++ ci_sh_def.yml 2024-06-21 22:57:45.189902320 -0700
--- ci.yml 2024-07-01 20:26:45.034547517 -0700
+++ ci_sh_def.yml 2024-07-01 20:27:32.110506039 -0700
@@ -1,4 +1,16 @@
-name: CI
+# PLEASE KEEP THIS GROUP OF FILES IN SYNC AT ALL TIMES:
Expand Down Expand Up @@ -93,127 +93,127 @@
-DPYBIND11_TEST_FILTER="test_smart_ptr.cpp"

- name: Build
@@ -529,6 +547,7 @@
@@ -531,6 +549,7 @@
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")

- name: Build
@@ -551,6 +570,7 @@
@@ -553,6 +572,7 @@
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DCMAKE_CXX_STANDARD=${{ matrix.std }}
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"

@@ -600,6 +620,7 @@
@@ -602,6 +622,7 @@
-DDOWNLOAD_CATCH=ON \
-DDOWNLOAD_EIGEN=OFF \
-DCMAKE_CXX_STANDARD=11 \
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" \
-DCMAKE_CXX_COMPILER=$(which icpc) \
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")

@@ -632,6 +653,7 @@
@@ -634,6 +655,7 @@
-DDOWNLOAD_CATCH=ON \
-DDOWNLOAD_EIGEN=OFF \
-DCMAKE_CXX_STANDARD=17 \
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT" \
-DCMAKE_CXX_COMPILER=$(which icpc) \
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")

@@ -703,6 +725,7 @@
@@ -705,6 +727,7 @@
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=11
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")

- name: Build
@@ -753,6 +776,7 @@
@@ -755,6 +778,7 @@
cmake ../pybind11-tests
-DDOWNLOAD_CATCH=ON
-DPYBIND11_WERROR=ON
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")
working-directory: /build-tests

@@ -856,6 +880,7 @@
@@ -858,6 +882,7 @@
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
${{ matrix.args }}
- name: Build C++11
run: cmake --build build -j 2
@@ -910,6 +935,7 @@
@@ -912,6 +937,7 @@
-DPYBIND11_WERROR=ON
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
${{ matrix.args }}
- name: Build C++11
run: cmake --build build --config Debug -j 2
@@ -952,6 +978,7 @@
@@ -954,6 +980,7 @@
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=20
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"

- name: Build C++20
run: cmake --build build -j 2
@@ -972,6 +999,7 @@
@@ -974,6 +1001,7 @@
-DDOWNLOAD_CATCH=ON
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_STANDARD=20
+ -DCMAKE_CXX_FLAGS="/GR /EHsc /DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
"-DPYBIND11_TEST_OVERRIDE=test_call_policies.cpp;test_gil_scoped.cpp;test_thread.cpp"

- name: Build C++20 - Exercise cmake -DPYBIND11_TEST_OVERRIDE
@@ -1024,6 +1052,7 @@
@@ -1026,6 +1054,7 @@
run: >-
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-S . -B build

- name: Build C++11
@@ -1045,6 +1074,7 @@
@@ -1047,6 +1076,7 @@
run: >-
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-S . -B build2

- name: Build C++14
@@ -1066,6 +1096,7 @@
@@ -1068,6 +1098,7 @@
run: >-
cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON
-DPYTHON_EXECUTABLE=$(python -c "import sys; print(sys.executable)")
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-S . -B build3

- name: Build C++17
@@ -1133,6 +1164,7 @@
@@ -1135,6 +1166,7 @@
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_STANDARD=17
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"

- name: Build
run: cmake --build . -j 2
@@ -1198,6 +1230,7 @@
@@ -1200,6 +1232,7 @@
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_STANDARD=17
+ -DCMAKE_CXX_FLAGS="-DPYBIND11_USE_SMART_HOLDER_AS_DEFAULT"
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)")

- name: Build
@@ -1221,6 +1254,7 @@
@@ -1223,6 +1256,7 @@
-DDOWNLOAD_EIGEN=ON
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_CXX_STANDARD=17
Expand Down
7 changes: 7 additions & 0 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,13 @@ class type_caster<std::pair<T1, T2>> : public tuple_caster<std::pair, T1, T2> {}
template <typename... Ts>
class type_caster<std::tuple<Ts...>> : public tuple_caster<std::tuple, Ts...> {};

template <>
class type_caster<std::tuple<>> : public tuple_caster<std::tuple> {
public:
// PEP 484 specifies this syntax for an empty tuple
static constexpr auto name = const_name("tuple[()]");
};

/// Helper class which abstracts away certain actions. Users can provide specializations for
/// custom holders, but it's only necessary if the type has a non-standard interface.
template <typename T>
Expand Down
1 change: 0 additions & 1 deletion include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ void construct(value_and_holder &v_h, Cpp<Class> *ptr, bool need_alias) {
// the holder and destruction happens when we leave the C++ scope, and the holder
// class gets to handle the destruction however it likes.
v_h.value_ptr() = ptr;
v_h.set_instance_registered(true); // To prevent init_instance from registering it
v_h.set_instance_registered(true); // SHORTCUT To prevent init_instance from registering it
// DANGER ZONE BEGIN: exceptions will leave v_h in an invalid state.
v_h.type->init_instance(v_h.inst, nullptr); // Set up the holder
Expand Down
9 changes: 7 additions & 2 deletions include/pybind11/typing.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "cast.h"
#include "pytypes.h"

#include <algorithm>

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(typing)

Expand Down Expand Up @@ -98,7 +100,10 @@ class Never : public none {
using none::none;
};

#if defined(__cpp_nontype_template_parameter_class)
#if defined(__cpp_nontype_template_parameter_class) \
&& (/* See #5201 */ !defined(__GNUC__) \
|| (__GNUC__ > 10 || (__GNUC__ == 10 && __GNUC_MINOR__ >= 3)))
# define PYBIND11_TYPING_H_HAS_STRING_LITERAL
template <size_t N>
struct StringLiteral {
constexpr StringLiteral(const char (&str)[N]) { std::copy_n(str, N, name); }
Expand Down Expand Up @@ -222,7 +227,7 @@ struct handle_type_name<typing::Never> {
static constexpr auto name = const_name("Never");
};

#if defined(__cpp_nontype_template_parameter_class)
#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL)
template <typing::StringLiteral... Literals>
struct handle_type_name<typing::Literal<Literals...>> {
static constexpr auto name = const_name("Literal[")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ def test_tuple(doc):
"""
)

assert doc(m.empty_tuple) == """empty_tuple() -> tuple[()]"""

assert m.rvalue_pair() == ("rvalue", "rvalue")
assert m.lvalue_pair() == ("lvalue", "lvalue")
assert m.rvalue_tuple() == ("rvalue", "rvalue", "rvalue")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void m_defs(py::module_ &m) {

} // namespace handle_from_move_only_type_with_operator_PyObject

#if defined(__cpp_nontype_template_parameter_class)
#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL)
namespace literals {
enum Color { RED = 0, BLUE = 1 };

Expand Down Expand Up @@ -905,7 +905,7 @@ TEST_SUBMODULE(pytypes, m) {
m.def("annotate_optional_to_object",
[](py::typing::Optional<int> &o) -> py::object { return o; });

#if defined(__cpp_nontype_template_parameter_class)
#if defined(PYBIND11_TYPING_H_HAS_STRING_LITERAL)
py::enum_<literals::Color>(m, "Color")
.value("RED", literals::Color::RED)
.value("BLUE", literals::Color::BLUE);
Expand All @@ -919,8 +919,8 @@ TEST_SUBMODULE(pytypes, m) {
m.def("annotate_listT_to_T",
[](const py::typing::List<typevar::TypeVarT> &l) -> typevar::TypeVarT { return l[0]; });
m.def("annotate_object_to_T", [](const py::object &o) -> typevar::TypeVarT { return o; });
m.attr("if_defined__cpp_nontype_template_parameter_class") = true;
m.attr("defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL") = true;
#else
m.attr("if_defined__cpp_nontype_template_parameter_class") = false;
m.attr("defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL") = false;
#endif
}
4 changes: 2 additions & 2 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ def test_optional_object_annotations(doc):


@pytest.mark.skipif(
not m.if_defined__cpp_nontype_template_parameter_class,
not m.defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL,
reason="C++20 feature not available.",
)
def test_literal(doc):
Expand All @@ -1036,7 +1036,7 @@ def test_literal(doc):


@pytest.mark.skipif(
not m.if_defined__cpp_nontype_template_parameter_class,
not m.defined_PYBIND11_TYPING_H_HAS_STRING_LITERAL,
reason="C++20 feature not available.",
)
def test_typevar(doc):
Expand Down
2 changes: 1 addition & 1 deletion tools/pybind11Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function(_pybind11_generate_lto target prefer_thin_lto)
set(PYBIND11_LTO_LINKER_FLAGS "-flto${thin}${linker_append}")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
_pybind11_return_if_cxx_and_linker_flags_work(
HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto=${thin}${linker_append}"
HAS_FLTO_THIN "-flto${thin}${cxx_append}" "-flto${thin}${linker_append}"
PYBIND11_LTO_CXX_FLAGS PYBIND11_LTO_LINKER_FLAGS)
endif()
if(NOT HAS_FLTO_THIN)
Expand Down

0 comments on commit ad48302

Please sign in to comment.