Skip to content

Commit 27ddbde

Browse files
rwgkfranzpoeschel
authored andcommitted
Update Pybind to 2.11.1
1 parent 8a7ec61 commit 27ddbde

43 files changed

Lines changed: 2409 additions & 1181 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

share/openPMD/thirdParty/pybind11/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# All rights reserved. Use of this source code is governed by a
66
# BSD-style license that can be found in the LICENSE file.
77

8-
cmake_minimum_required(VERSION 3.4)
8+
cmake_minimum_required(VERSION 3.5)
99

10-
# The `cmake_minimum_required(VERSION 3.4...3.22)` syntax does not work with
10+
# The `cmake_minimum_required(VERSION 3.5...3.26)` syntax does not work with
1111
# some versions of VS that have a patched CMake 3.11. This forces us to emulate
1212
# the behavior using the following workaround:
13-
if(${CMAKE_VERSION} VERSION_LESS 3.22)
13+
if(${CMAKE_VERSION} VERSION_LESS 3.26)
1414
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
1515
else()
16-
cmake_policy(VERSION 3.22)
16+
cmake_policy(VERSION 3.26)
1717
endif()
1818

1919
# Avoid infinite recursion if tests include this as a subdirectory
@@ -126,6 +126,9 @@ set(PYBIND11_HEADERS
126126
include/pybind11/complex.h
127127
include/pybind11/options.h
128128
include/pybind11/eigen.h
129+
include/pybind11/eigen/common.h
130+
include/pybind11/eigen/matrix.h
131+
include/pybind11/eigen/tensor.h
129132
include/pybind11/embed.h
130133
include/pybind11/eval.h
131134
include/pybind11/gil.h
@@ -137,7 +140,8 @@ set(PYBIND11_HEADERS
137140
include/pybind11/pytypes.h
138141
include/pybind11/stl.h
139142
include/pybind11/stl_bind.h
140-
include/pybind11/stl/filesystem.h)
143+
include/pybind11/stl/filesystem.h
144+
include/pybind11/type_caster_pyobject_ptr.h)
141145

142146
# Compare with grep and warn if mismatched
143147
if(PYBIND11_MASTER_PROJECT AND NOT CMAKE_VERSION VERSION_LESS 3.12)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
prune tests
12
recursive-include pybind11/include/pybind11 *.h
23
recursive-include pybind11 *.py
34
recursive-include pybind11 py.typed
45
include pybind11/share/cmake/pybind11/*.cmake
5-
include LICENSE README.rst pyproject.toml setup.py setup.cfg
6+
include LICENSE README.rst SECURITY.md pyproject.toml setup.py setup.cfg

share/openPMD/thirdParty/pybind11/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ This project was created by `Wenzel
135135
Jakob <http://rgl.epfl.ch/people/wjakob>`_. Significant features and/or
136136
improvements to the code were contributed by Jonas Adler, Lori A. Burns,
137137
Sylvain Corlay, Eric Cousineau, Aaron Gokaslan, Ralf Grosse-Kunstleve, Trent Houliston, Axel
138-
Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov Johan Mabille, Tomasz Miąsko,
138+
Huebl, @hulucc, Yannick Jadoul, Sergey Lyskov, Johan Mabille, Tomasz Miąsko,
139139
Dean Moldovan, Ben Pritchard, Jason Rhinelander, Boris Schäling, Pim
140140
Schellart, Henry Schreiner, Ivan Smirnov, Boris Staletic, and Patrick Stewart.
141141

share/openPMD/thirdParty/pybind11/include/pybind11/attr.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ struct is_method {
2626
explicit is_method(const handle &c) : class_(c) {}
2727
};
2828

29+
/// Annotation for setters
30+
struct is_setter {};
31+
2932
/// Annotation for operators
3033
struct is_operator {};
3134

@@ -188,8 +191,8 @@ struct argument_record {
188191
struct function_record {
189192
function_record()
190193
: is_constructor(false), is_new_style_constructor(false), is_stateless(false),
191-
is_operator(false), is_method(false), has_args(false), has_kwargs(false),
192-
prepend(false) {}
194+
is_operator(false), is_method(false), is_setter(false), has_args(false),
195+
has_kwargs(false), prepend(false) {}
193196

194197
/// Function name
195198
char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
@@ -230,6 +233,9 @@ struct function_record {
230233
/// True if this is a method
231234
bool is_method : 1;
232235

236+
/// True if this is a setter
237+
bool is_setter : 1;
238+
233239
/// True if the function has a '*args' argument
234240
bool has_args : 1;
235241

@@ -399,7 +405,7 @@ struct process_attribute<doc> : process_attribute_default<doc> {
399405
template <>
400406
struct process_attribute<const char *> : process_attribute_default<const char *> {
401407
static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
402-
static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); }
408+
static void init(const char *d, type_record *r) { r->doc = d; }
403409
};
404410
template <>
405411
struct process_attribute<char *> : process_attribute<const char *> {};
@@ -426,6 +432,12 @@ struct process_attribute<is_method> : process_attribute_default<is_method> {
426432
}
427433
};
428434

435+
/// Process an attribute which indicates that this function is a setter
436+
template <>
437+
struct process_attribute<is_setter> : process_attribute_default<is_setter> {
438+
static void init(const is_setter &, function_record *r) { r->is_setter = true; }
439+
};
440+
429441
/// Process an attribute which indicates the parent scope of a method
430442
template <>
431443
struct process_attribute<scope> : process_attribute_default<scope> {

share/openPMD/thirdParty/pybind11/include/pybind11/buffer_info.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ inline std::vector<ssize_t> f_strides(const std::vector<ssize_t> &shape, ssize_t
3737
return strides;
3838
}
3939

40+
template <typename T, typename SFINAE = void>
41+
struct compare_buffer_info;
42+
4043
PYBIND11_NAMESPACE_END(detail)
4144

4245
/// Information record describing a Python buffer object
@@ -150,6 +153,17 @@ struct buffer_info {
150153
Py_buffer *view() const { return m_view; }
151154
Py_buffer *&view() { return m_view; }
152155

156+
/* True if the buffer item type is equivalent to `T`. */
157+
// To define "equivalent" by example:
158+
// `buffer_info::item_type_is_equivalent_to<int>(b)` and
159+
// `buffer_info::item_type_is_equivalent_to<long>(b)` may both be true
160+
// on some platforms, but `int` and `unsigned` will never be equivalent.
161+
// For the ground truth, please inspect `detail::compare_buffer_info<>`.
162+
template <typename T>
163+
bool item_type_is_equivalent_to() const {
164+
return detail::compare_buffer_info<T>::compare(*this);
165+
}
166+
153167
private:
154168
struct private_ctr_tag {};
155169

@@ -170,9 +184,10 @@ struct buffer_info {
170184

171185
PYBIND11_NAMESPACE_BEGIN(detail)
172186

173-
template <typename T, typename SFINAE = void>
187+
template <typename T, typename SFINAE>
174188
struct compare_buffer_info {
175189
static bool compare(const buffer_info &b) {
190+
// NOLINTNEXTLINE(bugprone-sizeof-expression) Needed for `PyObject *`
176191
return b.format == format_descriptor<T>::format() && b.itemsize == (ssize_t) sizeof(T);
177192
}
178193
};

share/openPMD/thirdParty/pybind11/include/pybind11/cast.h

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <vector>
3030

3131
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
32+
33+
PYBIND11_WARNING_DISABLE_MSVC(4127)
34+
3235
PYBIND11_NAMESPACE_BEGIN(detail)
3336

3437
template <typename type, typename SFINAE = void>
@@ -88,7 +91,8 @@ public:
8891
template <typename T_, \
8992
::pybind11::detail::enable_if_t< \
9093
std::is_same<type, ::pybind11::detail::remove_cv_t<T_>>::value, \
91-
int> = 0> \
94+
int> \
95+
= 0> \
9296
static ::pybind11::handle cast( \
9397
T_ *src, ::pybind11::return_value_policy policy, ::pybind11::handle parent) { \
9498
if (!src) \
@@ -389,7 +393,7 @@ struct string_caster {
389393

390394
// For UTF-8 we avoid the need for a temporary `bytes` object by using
391395
// `PyUnicode_AsUTF8AndSize`.
392-
if (PYBIND11_SILENCE_MSVC_C4127(UTF_N == 8)) {
396+
if (UTF_N == 8) {
393397
Py_ssize_t size = -1;
394398
const auto *buffer
395399
= reinterpret_cast<const CharT *>(PyUnicode_AsUTF8AndSize(load_src.ptr(), &size));
@@ -416,7 +420,7 @@ struct string_caster {
416420
= reinterpret_cast<const CharT *>(PYBIND11_BYTES_AS_STRING(utfNbytes.ptr()));
417421
size_t length = (size_t) PYBIND11_BYTES_SIZE(utfNbytes.ptr()) / sizeof(CharT);
418422
// Skip BOM for UTF-16/32
419-
if (PYBIND11_SILENCE_MSVC_C4127(UTF_N > 8)) {
423+
if (UTF_N > 8) {
420424
buffer++;
421425
length--;
422426
}
@@ -572,7 +576,7 @@ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {
572576
// figure out how long the first encoded character is in bytes to distinguish between these
573577
// two errors. We also allow want to allow unicode characters U+0080 through U+00FF, as
574578
// those can fit into a single char value.
575-
if (PYBIND11_SILENCE_MSVC_C4127(StringCaster::UTF_N == 8) && str_len > 1 && str_len <= 4) {
579+
if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) {
576580
auto v0 = static_cast<unsigned char>(value[0]);
577581
// low bits only: 0-127
578582
// 0b110xxxxx - start of 2-byte sequence
@@ -598,7 +602,7 @@ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {
598602
// UTF-16 is much easier: we can only have a surrogate pair for values above U+FFFF, thus a
599603
// surrogate pair with total length 2 instantly indicates a range error (but not a "your
600604
// string was too long" error).
601-
else if (PYBIND11_SILENCE_MSVC_C4127(StringCaster::UTF_N == 16) && str_len == 2) {
605+
else if (StringCaster::UTF_N == 16 && str_len == 2) {
602606
one_char = static_cast<CharT>(value[0]);
603607
if (one_char >= 0xD800 && one_char < 0xE000) {
604608
throw value_error("Character code point not in range(0x10000)");
@@ -960,7 +964,7 @@ struct move_always<
960964
enable_if_t<
961965
all_of<move_is_plain_type<T>,
962966
negation<is_copy_constructible<T>>,
963-
std::is_move_constructible<T>,
967+
is_move_constructible<T>,
964968
std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
965969
: std::true_type {};
966970
template <typename T, typename SFINAE = void>
@@ -971,7 +975,7 @@ struct move_if_unreferenced<
971975
enable_if_t<
972976
all_of<move_is_plain_type<T>,
973977
negation<move_always<T>>,
974-
std::is_move_constructible<T>,
978+
is_move_constructible<T>,
975979
std::is_same<decltype(std::declval<make_caster<T>>().operator T &()), T &>>::value>>
976980
: std::true_type {};
977981
template <typename T>
@@ -1013,11 +1017,14 @@ type_caster<T, SFINAE> &load_type(type_caster<T, SFINAE> &conv, const handle &ha
10131017
"Internal error: type_caster should only be used for C++ types");
10141018
if (!conv.load(handle, true)) {
10151019
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1016-
throw cast_error("Unable to cast Python instance to C++ type (#define "
1017-
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1020+
throw cast_error(
1021+
"Unable to cast Python instance of type "
1022+
+ str(type::handle_of(handle)).cast<std::string>()
1023+
+ " to C++ type '?' (#define "
1024+
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
10181025
#else
10191026
throw cast_error("Unable to cast Python instance of type "
1020-
+ (std::string) str(type::handle_of(handle)) + " to C++ type '"
1027+
+ str(type::handle_of(handle)).cast<std::string>() + " to C++ type '"
10211028
+ type_id<T>() + "'");
10221029
#endif
10231030
}
@@ -1034,7 +1041,11 @@ make_caster<T> load_type(const handle &handle) {
10341041
PYBIND11_NAMESPACE_END(detail)
10351042

10361043
// pytype -> C++ type
1037-
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
1044+
template <typename T,
1045+
detail::enable_if_t<!detail::is_pyobject<T>::value
1046+
&& !detail::is_same_ignoring_cvref<T, PyObject *>::value,
1047+
int>
1048+
= 0>
10381049
T cast(const handle &handle) {
10391050
using namespace detail;
10401051
static_assert(!cast_is_temporary_value_reference<T>::value,
@@ -1048,6 +1059,34 @@ T cast(const handle &handle) {
10481059
return T(reinterpret_borrow<object>(handle));
10491060
}
10501061

1062+
// Note that `cast<PyObject *>(obj)` increments the reference count of `obj`.
1063+
// This is necessary for the case that `obj` is a temporary, and could
1064+
// not possibly be different, given
1065+
// 1. the established convention that the passed `handle` is borrowed, and
1066+
// 2. we don't want to force all generic code using `cast<T>()` to special-case
1067+
// handling of `T` = `PyObject *` (to increment the reference count there).
1068+
// It is the responsibility of the caller to ensure that the reference count
1069+
// is decremented.
1070+
template <typename T,
1071+
typename Handle,
1072+
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1073+
&& detail::is_same_ignoring_cvref<Handle, handle>::value,
1074+
int>
1075+
= 0>
1076+
T cast(Handle &&handle) {
1077+
return handle.inc_ref().ptr();
1078+
}
1079+
// To optimize way an inc_ref/dec_ref cycle:
1080+
template <typename T,
1081+
typename Object,
1082+
detail::enable_if_t<detail::is_same_ignoring_cvref<T, PyObject *>::value
1083+
&& detail::is_same_ignoring_cvref<Object, object>::value,
1084+
int>
1085+
= 0>
1086+
T cast(Object &&obj) {
1087+
return obj.release().ptr();
1088+
}
1089+
10511090
// C++ type -> py::object
10521091
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
10531092
object cast(T &&value,
@@ -1081,12 +1120,13 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
10811120
if (obj.ref_count() > 1) {
10821121
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
10831122
throw cast_error(
1084-
"Unable to cast Python instance to C++ rvalue: instance has multiple references"
1085-
" (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1123+
"Unable to cast Python " + str(type::handle_of(obj)).cast<std::string>()
1124+
+ " instance to C++ rvalue: instance has multiple references"
1125+
" (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
10861126
#else
1087-
throw cast_error("Unable to move from Python " + (std::string) str(type::handle_of(obj))
1088-
+ " instance to C++ " + type_id<T>()
1089-
+ " instance: instance has multiple references");
1127+
throw cast_error("Unable to move from Python "
1128+
+ str(type::handle_of(obj)).cast<std::string>() + " instance to C++ "
1129+
+ type_id<T>() + " instance: instance has multiple references");
10901130
#endif
10911131
}
10921132

@@ -1191,9 +1231,10 @@ PYBIND11_NAMESPACE_END(detail)
11911231
// The overloads could coexist, i.e. the #if is not strictly speaking needed,
11921232
// but it is an easy minor optimization.
11931233
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1194-
inline cast_error cast_error_unable_to_convert_call_arg() {
1195-
return cast_error("Unable to convert call argument to Python object (#define "
1196-
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
1234+
inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name) {
1235+
return cast_error("Unable to convert call argument '" + name
1236+
+ "' to Python object (#define "
1237+
"PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)");
11971238
}
11981239
#else
11991240
inline cast_error cast_error_unable_to_convert_call_arg(const std::string &name,
@@ -1216,7 +1257,7 @@ tuple make_tuple(Args &&...args_) {
12161257
for (size_t i = 0; i < args.size(); i++) {
12171258
if (!args[i]) {
12181259
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1219-
throw cast_error_unable_to_convert_call_arg();
1260+
throw cast_error_unable_to_convert_call_arg(std::to_string(i));
12201261
#else
12211262
std::array<std::string, size> argtypes{{type_id<Args>()...}};
12221263
throw cast_error_unable_to_convert_call_arg(std::to_string(i), argtypes[i]);
@@ -1506,7 +1547,7 @@ class unpacking_collector {
15061547
detail::make_caster<T>::cast(std::forward<T>(x), policy, {}));
15071548
if (!o) {
15081549
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1509-
throw cast_error_unable_to_convert_call_arg();
1550+
throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()));
15101551
#else
15111552
throw cast_error_unable_to_convert_call_arg(std::to_string(args_list.size()),
15121553
type_id<T>());
@@ -1538,7 +1579,7 @@ class unpacking_collector {
15381579
}
15391580
if (!a.value) {
15401581
#if !defined(PYBIND11_DETAILED_ERROR_MESSAGES)
1541-
throw cast_error_unable_to_convert_call_arg();
1582+
throw cast_error_unable_to_convert_call_arg(a.name);
15421583
#else
15431584
throw cast_error_unable_to_convert_call_arg(a.name, a.type);
15441585
#endif

share/openPMD/thirdParty/pybind11/include/pybind11/detail/class.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,17 @@ inline void clear_instance(PyObject *self) {
445445
/// Instance destructor function for all pybind11 types. It calls `type_info.dealloc`
446446
/// to destroy the C++ object itself, while the rest is Python bookkeeping.
447447
extern "C" inline void pybind11_object_dealloc(PyObject *self) {
448+
auto *type = Py_TYPE(self);
449+
450+
// If this is a GC tracked object, untrack it first
451+
// Note that the track call is implicitly done by the
452+
// default tp_alloc, which we never override.
453+
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC) != 0) {
454+
PyObject_GC_UnTrack(self);
455+
}
456+
448457
clear_instance(self);
449458

450-
auto *type = Py_TYPE(self);
451459
type->tp_free(self);
452460

453461
#if PY_VERSION_HEX < 0x03080000

0 commit comments

Comments
 (0)