Skip to content

Commit 52d88c3

Browse files
committed
Merge branch 'master' of https://github.com/pybind/pybind11 into set_interpreter_argv
2 parents 912e1c9 + 4f29b8a commit 52d88c3

File tree

8 files changed

+98
-90
lines changed

8 files changed

+98
-90
lines changed

.github/workflows/ci.yml

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -861,32 +861,85 @@ jobs:
861861
run: cmake --build build -t check
862862

863863
mingw:
864+
name: "🐍 3 • windows-latest • ${{ matrix.sys }}"
864865
runs-on: windows-latest
865866
defaults:
866867
run:
867868
shell: msys2 {0}
869+
strategy:
870+
fail-fast: false
871+
matrix:
872+
include:
873+
- { sys: mingw64, env: x86_64 }
874+
- { sys: mingw32, env: i686 }
868875
steps:
869876
- uses: msys2/setup-msys2@v2
870877
with:
878+
msystem: ${{matrix.sys}}
871879
install: >-
872-
mingw-w64-x86_64-gcc
873-
mingw-w64-x86_64-python-pip
874-
mingw-w64-x86_64-cmake
875-
mingw-w64-x86_64-make
876-
mingw-w64-x86_64-python-pytest
877-
mingw-w64-x86_64-eigen3
878-
mingw-w64-x86_64-boost
879-
mingw-w64-x86_64-catch
880+
git
881+
mingw-w64-${{matrix.env}}-gcc
882+
mingw-w64-${{matrix.env}}-python-pip
883+
mingw-w64-${{matrix.env}}-python-numpy
884+
mingw-w64-${{matrix.env}}-python-scipy
885+
mingw-w64-${{matrix.env}}-cmake
886+
mingw-w64-${{matrix.env}}-make
887+
mingw-w64-${{matrix.env}}-python-pytest
888+
mingw-w64-${{matrix.env}}-eigen3
889+
mingw-w64-${{matrix.env}}-boost
890+
mingw-w64-${{matrix.env}}-catch
880891
881-
- uses: actions/checkout@v1
892+
- uses: actions/checkout@v2
882893

883-
- name: Configure
894+
- name: Configure C++11
884895
# LTO leads to many undefined reference like
885896
# `pybind11::detail::function_call::function_call(pybind11::detail::function_call&&)
886-
run: cmake -G "MinGW Makefiles" -S . -B build
897+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=11 -S . -B build
887898

888-
- name: Build
899+
- name: Build C++11
889900
run: cmake --build build -j 2
890901

891-
- name: Python tests
892-
run: cmake --build build --target pytest
902+
- name: Python tests C++11
903+
run: cmake --build build --target pytest -j 2
904+
905+
- name: C++11 tests
906+
run: cmake --build build --target cpptest -j 2
907+
908+
- name: Interface test C++11
909+
run: cmake --build build --target test_cmake_build
910+
911+
- name: Clean directory
912+
run: git clean -fdx
913+
914+
- name: Configure C++14
915+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=14 -S . -B build2
916+
917+
- name: Build C++14
918+
run: cmake --build build2 -j 2
919+
920+
- name: Python tests C++14
921+
run: cmake --build build2 --target pytest -j 2
922+
923+
- name: C++14 tests
924+
run: cmake --build build2 --target cpptest -j 2
925+
926+
- name: Interface test C++14
927+
run: cmake --build build2 --target test_cmake_build
928+
929+
- name: Clean directory
930+
run: git clean -fdx
931+
932+
- name: Configure C++17
933+
run: cmake -G "MinGW Makefiles" -DCMAKE_CXX_STANDARD=17 -S . -B build3
934+
935+
- name: Build C++17
936+
run: cmake --build build3 -j 2
937+
938+
- name: Python tests C++17
939+
run: cmake --build build3 --target pytest -j 2
940+
941+
- name: C++17 tests
942+
run: cmake --build build3 --target cpptest -j 2
943+
944+
- name: Interface test C++17
945+
run: cmake --build build3 --target test_cmake_build

include/pybind11/detail/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ inline void silence_unused_warnings(Args &&...) {}
968968
// warning C4127: Conditional expression is constant
969969
constexpr inline bool silence_msvc_c4127(bool cond) { return cond; }
970970

971-
# define PYBIND11_SILENCE_MSVC_C4127(...) detail::silence_msvc_c4127(__VA_ARGS__)
971+
# define PYBIND11_SILENCE_MSVC_C4127(...) ::pybind11::detail::silence_msvc_c4127(__VA_ARGS__)
972972

973973
#else
974974
# define PYBIND11_SILENCE_MSVC_C4127(...) __VA_ARGS__

include/pybind11/eigen.h

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,13 @@
99

1010
#pragma once
1111

12-
#include "numpy.h"
13-
14-
#if defined(__INTEL_COMPILER)
15-
# pragma warning(disable: 1682) // implicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem)
16-
#elif defined(__GNUG__) || defined(__clang__)
17-
# pragma GCC diagnostic push
18-
# pragma GCC diagnostic ignored "-Wconversion"
19-
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
20-
# ifdef __clang__
21-
// Eigen generates a bunch of implicit-copy-constructor-is-deprecated warnings with -Wdeprecated
22-
// under Clang, so disable that warning here:
23-
# pragma GCC diagnostic ignored "-Wdeprecated"
24-
# endif
25-
# if __GNUC__ >= 7
26-
# pragma GCC diagnostic ignored "-Wint-in-bool-context"
27-
# endif
28-
#endif
12+
/* HINT: To suppress warnings originating from the Eigen headers, use -isystem.
13+
See also:
14+
https://stackoverflow.com/questions/2579576/i-dir-vs-isystem-dir
15+
https://stackoverflow.com/questions/1741816/isystem-for-ms-visual-studio-c-compiler
16+
*/
2917

30-
#if defined(_MSC_VER)
31-
# pragma warning(push)
32-
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
33-
# pragma warning(disable: 4996) // warning C4996: std::unary_negate is deprecated in C++17
34-
#endif
18+
#include "numpy.h"
3519

3620
#include <Eigen/Core>
3721
#include <Eigen/SparseCore>
@@ -153,7 +137,8 @@ template <typename Type_> struct EigenProps {
153137
np_cols = a.shape(1),
154138
np_rstride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar)),
155139
np_cstride = a.strides(1) / static_cast<ssize_t>(sizeof(Scalar));
156-
if ((fixed_rows && np_rows != rows) || (fixed_cols && np_cols != cols))
140+
if ((PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && np_rows != rows) ||
141+
(PYBIND11_SILENCE_MSVC_C4127(fixed_cols) && np_cols != cols))
157142
return false;
158143

159144
return {np_rows, np_cols, np_rstride, np_cstride};
@@ -165,7 +150,7 @@ template <typename Type_> struct EigenProps {
165150
stride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar));
166151

167152
if (vector) { // Eigen type is a compile-time vector
168-
if (fixed && size != n)
153+
if (PYBIND11_SILENCE_MSVC_C4127(fixed) && size != n)
169154
return false; // Vector size mismatch
170155
return {rows == 1 ? 1 : n, cols == 1 ? 1 : n, stride};
171156
}
@@ -179,7 +164,7 @@ template <typename Type_> struct EigenProps {
179164
if (cols != n) return false;
180165
return {1, n, stride};
181166
} // Otherwise it's either fully dynamic, or column dynamic; both become a column vector
182-
if (fixed_rows && rows != n) return false;
167+
if (PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && rows != n) return false;
183168
return {n, 1, stride};
184169
}
185170

@@ -596,9 +581,3 @@ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
596581

597582
PYBIND11_NAMESPACE_END(detail)
598583
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
599-
600-
#if defined(__GNUG__) || defined(__clang__)
601-
# pragma GCC diagnostic pop
602-
#elif defined(_MSC_VER)
603-
# pragma warning(pop)
604-
#endif

include/pybind11/numpy.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
#include <vector>
2626
#include <typeindex>
2727

28-
#if defined(_MSC_VER)
29-
# pragma warning(push)
30-
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
31-
#endif
32-
3328
/* This will be true on all flat address space platforms and allows us to reduce the
3429
whole npy_intp / ssize_t / Py_intptr_t business down to just ssize_t for all size
3530
and dimension types (e.g. shape, strides, indexing), instead of inflicting this
@@ -747,7 +742,7 @@ class array : public buffer {
747742
* and the caller must take care not to access invalid dimensions or dimension indices.
748743
*/
749744
template <typename T, ssize_t Dims = -1> detail::unchecked_mutable_reference<T, Dims> mutable_unchecked() & {
750-
if (Dims >= 0 && ndim() != Dims)
745+
if (PYBIND11_SILENCE_MSVC_C4127(Dims >= 0) && ndim() != Dims)
751746
throw std::domain_error("array has incorrect number of dimensions: " + std::to_string(ndim()) +
752747
"; expected " + std::to_string(Dims));
753748
return detail::unchecked_mutable_reference<T, Dims>(mutable_data(), shape(), strides(), ndim());
@@ -761,7 +756,7 @@ class array : public buffer {
761756
* invalid dimensions or dimension indices.
762757
*/
763758
template <typename T, ssize_t Dims = -1> detail::unchecked_reference<T, Dims> unchecked() const & {
764-
if (Dims >= 0 && ndim() != Dims)
759+
if (PYBIND11_SILENCE_MSVC_C4127(Dims >= 0) && ndim() != Dims)
765760
throw std::domain_error("array has incorrect number of dimensions: " + std::to_string(ndim()) +
766761
"; expected " + std::to_string(Dims));
767762
return detail::unchecked_reference<T, Dims>(data(), shape(), strides(), ndim());
@@ -1708,7 +1703,3 @@ Helper vectorize(Return (Class::*f)(Args...) const) {
17081703
}
17091704

17101705
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
1711-
1712-
#if defined(_MSC_VER)
1713-
#pragma warning(pop)
1714-
#endif

include/pybind11/operators.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@
1111

1212
#include "pybind11.h"
1313

14-
#if defined(__clang__) && !defined(__INTEL_COMPILER)
15-
# pragma clang diagnostic ignored "-Wunsequenced" // multiple unsequenced modifications to 'self' (when using def(py::self OP Type()))
16-
#elif defined(_MSC_VER)
17-
# pragma warning(push)
18-
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
19-
#endif
20-
2114
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
2215
PYBIND11_NAMESPACE_BEGIN(detail)
2316

@@ -58,7 +51,8 @@ template <op_id id, op_type ot, typename L, typename R> struct op_ {
5851
using op = op_impl<id, ot, Base, L_type, R_type>;
5952
cl.def(op::name(), &op::execute, is_operator(), extra...);
6053
#if PY_MAJOR_VERSION < 3
61-
if (id == op_truediv || id == op_itruediv)
54+
if (PYBIND11_SILENCE_MSVC_C4127(id == op_truediv) ||
55+
PYBIND11_SILENCE_MSVC_C4127(id == op_itruediv))
6256
cl.def(id == op_itruediv ? "__idiv__" : ot == op_l ? "__div__" : "__rdiv__",
6357
&op::execute, is_operator(), extra...);
6458
#endif
@@ -167,7 +161,3 @@ using detail::self;
167161
using detail::hash;
168162

169163
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
170-
171-
#if defined(_MSC_VER)
172-
# pragma warning(pop)
173-
#endif

include/pybind11/stl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
#include <deque>
2020
#include <valarray>
2121

22-
#if defined(_MSC_VER)
23-
#pragma warning(push)
24-
#pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
25-
#endif
26-
2722
#ifdef __has_include
2823
// std::optional (but including it in c++14 mode isn't allowed)
2924
# if defined(PYBIND11_CPP17) && __has_include(<optional>)
@@ -390,7 +385,3 @@ inline std::ostream &operator<<(std::ostream &os, const handle &obj) {
390385
}
391386

392387
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
393-
394-
#if defined(_MSC_VER)
395-
#pragma warning(pop)
396-
#endif

tests/test_builtin_casters.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#include "pybind11_tests.h"
1111
#include <pybind11/complex.h>
1212

13-
#if defined(_MSC_VER)
14-
# pragma warning(push)
15-
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
16-
#endif
17-
1813
struct ConstRefCasted {
1914
int tag;
2015
};
@@ -73,7 +68,7 @@ TEST_SUBMODULE(builtin_casters, m) {
7368
std::wstring wstr;
7469
wstr.push_back(0x61); // a
7570
wstr.push_back(0x2e18); //
76-
if (sizeof(wchar_t) == 2) { wstr.push_back(mathbfA16_1); wstr.push_back(mathbfA16_2); } // 𝐀, utf16
71+
if (PYBIND11_SILENCE_MSVC_C4127(sizeof(wchar_t) == 2)) { wstr.push_back(mathbfA16_1); wstr.push_back(mathbfA16_2); } // 𝐀, utf16
7772
else { wstr.push_back((wchar_t) mathbfA32); } // 𝐀, utf32
7873
wstr.push_back(0x7a); // z
7974

@@ -83,11 +78,12 @@ TEST_SUBMODULE(builtin_casters, m) {
8378
m.def("good_wchar_string", [=]() { return wstr; }); // a‽𝐀z
8479
m.def("bad_utf8_string", []() { return std::string("abc\xd0" "def"); });
8580
m.def("bad_utf16_string", [=]() { return std::u16string({ b16, char16_t(0xd800), z16 }); });
81+
#if PY_MAJOR_VERSION >= 3
8682
// Under Python 2.7, invalid unicode UTF-32 characters don't appear to trigger UnicodeDecodeError
87-
if (PY_MAJOR_VERSION >= 3)
88-
m.def("bad_utf32_string", [=]() { return std::u32string({ a32, char32_t(0xd800), z32 }); });
89-
if (PY_MAJOR_VERSION >= 3 || sizeof(wchar_t) == 2)
83+
m.def("bad_utf32_string", [=]() { return std::u32string({ a32, char32_t(0xd800), z32 }); });
84+
if (PYBIND11_SILENCE_MSVC_C4127(sizeof(wchar_t) == 2))
9085
m.def("bad_wchar_string", [=]() { return std::wstring({ wchar_t(0x61), wchar_t(0xd800) }); });
86+
#endif
9187
m.def("u8_Z", []() -> char { return 'Z'; });
9288
m.def("u8_eacute", []() -> char { return '\xe9'; });
9389
m.def("u16_ibang", [=]() -> char16_t { return ib16; });

tests/test_numpy_dtypes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,20 @@ def partial_ld_offset():
6363
def partial_dtype_fmt():
6464
ld = np.dtype("longdouble")
6565
partial_ld_off = partial_ld_offset()
66-
return dt_fmt().format(ld.itemsize, partial_ld_off, partial_ld_off + ld.itemsize)
66+
partial_size = partial_ld_off + ld.itemsize
67+
partial_end_padding = partial_size % np.dtype("uint64").alignment
68+
return dt_fmt().format(
69+
ld.itemsize, partial_ld_off, partial_size + partial_end_padding
70+
)
6771

6872

6973
def partial_nested_fmt():
7074
ld = np.dtype("longdouble")
7175
partial_nested_off = 8 + 8 * (ld.alignment > 8)
7276
partial_ld_off = partial_ld_offset()
73-
partial_nested_size = partial_nested_off * 2 + partial_ld_off + ld.itemsize
77+
partial_size = partial_ld_off + ld.itemsize
78+
partial_end_padding = partial_size % np.dtype("uint64").alignment
79+
partial_nested_size = partial_nested_off * 2 + partial_size + partial_end_padding
7480
return "{{'names':['a'], 'formats':[{}], 'offsets':[{}], 'itemsize':{}}}".format(
7581
partial_dtype_fmt(), partial_nested_off, partial_nested_size
7682
)
@@ -91,10 +97,12 @@ def test_format_descriptors():
9197
ldbl_fmt = ("4x" if ld.alignment > 4 else "") + ld.char
9298
ss_fmt = "^T{?:bool_:3xI:uint_:f:float_:" + ldbl_fmt + ":ldbl_:}"
9399
dbl = np.dtype("double")
100+
end_padding = ld.itemsize % np.dtype("uint64").alignment
94101
partial_fmt = (
95102
"^T{?:bool_:3xI:uint_:f:float_:"
96103
+ str(4 * (dbl.alignment > 4) + dbl.itemsize + 8 * (ld.alignment > 8))
97-
+ "xg:ldbl_:}"
104+
+ "xg:ldbl_:"
105+
+ (str(end_padding) + "x}" if end_padding > 0 else "}")
98106
)
99107
nested_extra = str(max(8, ld.alignment))
100108
assert m.print_format_descriptors() == [

0 commit comments

Comments
 (0)