Skip to content

Commit 93cbf6c

Browse files
wjakobax3l
authored andcommitted
Internal: pybind11 2.4.3
Update the internal version of pybind11, version 2.4.3. This release includes several fixes, such as - add fix pybind/pybind11#1851 https://github.com/pybind/pybind11/blob/v2.4.3/docs/changelog.rst Modifications from the releases: - remove test dirs - remove wheel packaging (setup.py/cfg) - remove github templates
1 parent dd1fdf1 commit 93cbf6c

File tree

16 files changed

+279
-101
lines changed

16 files changed

+279
-101
lines changed

share/openPMD/thirdParty/pybind11/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ In addition to the core functionality, pybind11 provides some extra goodies:
105105
This project was created by [Wenzel Jakob](http://rgl.epfl.ch/people/wjakob).
106106
Significant features and/or improvements to the code were contributed by
107107
Jonas Adler,
108+
Lori A. Burns,
108109
Sylvain Corlay,
109110
Trent Houliston,
110111
Axel Huebl,
@@ -117,6 +118,7 @@ Ben Pritchard,
117118
Jason Rhinelander,
118119
Boris Schäling,
119120
Pim Schellart,
121+
Henry Schreiner,
120122
Ivan Smirnov, and
121123
Patrick Stewart.
122124

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,9 @@ template <typename T, typename SFINAE = void> struct is_copy_constructible : std
775775
// so, copy constructability depends on whether the value_type is copy constructible.
776776
template <typename Container> struct is_copy_constructible<Container, enable_if_t<all_of<
777777
std::is_copy_constructible<Container>,
778-
std::is_same<typename Container::value_type &, typename Container::reference>
778+
std::is_same<typename Container::value_type &, typename Container::reference>,
779+
// Avoid infinite recursion
780+
negation<std::is_same<Container, typename Container::value_type>>
779781
>::value>> : is_copy_constructible<typename Container::value_type> {};
780782

781783
#if !defined(PYBIND11_CPP17)
@@ -995,9 +997,11 @@ struct type_caster<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
995997
}
996998

997999
bool py_err = py_value == (py_type) -1 && PyErr_Occurred();
1000+
1001+
// Protect std::numeric_limits::min/max with parentheses
9981002
if (py_err || (std::is_integral<T>::value && sizeof(py_type) != sizeof(T) &&
999-
(py_value < (py_type) std::numeric_limits<T>::min() ||
1000-
py_value > (py_type) std::numeric_limits<T>::max()))) {
1003+
(py_value < (py_type) (std::numeric_limits<T>::min)() ||
1004+
py_value > (py_type) (std::numeric_limits<T>::max)()))) {
10011005
bool type_error = py_err && PyErr_ExceptionMatches(
10021006
#if PY_VERSION_HEX < 0x03000000 && !defined(PYPY_VERSION)
10031007
PyExc_SystemError

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,42 @@ template <typename Duration> class type_caster<std::chrono::time_point<std::chro
106106
if (!PyDateTimeAPI) { PyDateTime_IMPORT; }
107107

108108
if (!src) return false;
109+
110+
std::tm cal;
111+
microseconds msecs;
112+
109113
if (PyDateTime_Check(src.ptr())) {
110-
std::tm cal;
111114
cal.tm_sec = PyDateTime_DATE_GET_SECOND(src.ptr());
112115
cal.tm_min = PyDateTime_DATE_GET_MINUTE(src.ptr());
113116
cal.tm_hour = PyDateTime_DATE_GET_HOUR(src.ptr());
114117
cal.tm_mday = PyDateTime_GET_DAY(src.ptr());
115118
cal.tm_mon = PyDateTime_GET_MONTH(src.ptr()) - 1;
116119
cal.tm_year = PyDateTime_GET_YEAR(src.ptr()) - 1900;
117120
cal.tm_isdst = -1;
118-
119-
value = system_clock::from_time_t(std::mktime(&cal)) + microseconds(PyDateTime_DATE_GET_MICROSECOND(src.ptr()));
120-
return true;
121+
msecs = microseconds(PyDateTime_DATE_GET_MICROSECOND(src.ptr()));
122+
} else if (PyDate_Check(src.ptr())) {
123+
cal.tm_sec = 0;
124+
cal.tm_min = 0;
125+
cal.tm_hour = 0;
126+
cal.tm_mday = PyDateTime_GET_DAY(src.ptr());
127+
cal.tm_mon = PyDateTime_GET_MONTH(src.ptr()) - 1;
128+
cal.tm_year = PyDateTime_GET_YEAR(src.ptr()) - 1900;
129+
cal.tm_isdst = -1;
130+
msecs = microseconds(0);
131+
} else if (PyTime_Check(src.ptr())) {
132+
cal.tm_sec = PyDateTime_TIME_GET_SECOND(src.ptr());
133+
cal.tm_min = PyDateTime_TIME_GET_MINUTE(src.ptr());
134+
cal.tm_hour = PyDateTime_TIME_GET_HOUR(src.ptr());
135+
cal.tm_mday = 1; // This date (day, month, year) = (1, 0, 70)
136+
cal.tm_mon = 0; // represents 1-Jan-1970, which is the first
137+
cal.tm_year = 70; // earliest available date for Python's datetime
138+
cal.tm_isdst = -1;
139+
msecs = microseconds(PyDateTime_TIME_GET_MICROSECOND(src.ptr()));
121140
}
122141
else return false;
142+
143+
value = system_clock::from_time_t(std::mktime(&cal)) + msecs;
144+
return true;
123145
}
124146

125147
static handle cast(const std::chrono::time_point<std::chrono::system_clock, Duration> &src, return_value_policy /* policy */, handle /* parent */) {
@@ -128,7 +150,7 @@ template <typename Duration> class type_caster<std::chrono::time_point<std::chro
128150
// Lazy initialise the PyDateTime import
129151
if (!PyDateTimeAPI) { PyDateTime_IMPORT; }
130152

131-
std::time_t tt = system_clock::to_time_t(src);
153+
std::time_t tt = system_clock::to_time_t(time_point_cast<system_clock::duration>(src));
132154
// this function uses static memory so it's best to copy it out asap just in case
133155
// otherwise other code that is using localtime may break this (not just python code)
134156
std::tm localtime = *std::localtime(&tt);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,19 @@ extern "C" inline void pybind11_object_dealloc(PyObject *self) {
350350
auto type = Py_TYPE(self);
351351
type->tp_free(self);
352352

353+
#if PY_VERSION_HEX < 0x03080000
353354
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
354355
// as part of a derived type's dealloc, in which case we're not allowed to decref
355356
// the type here. For cross-module compatibility, we shouldn't compare directly
356357
// with `pybind11_object_dealloc`, but with the common one stashed in internals.
357358
auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
358359
if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
359360
Py_DECREF(type);
361+
#else
362+
// This was not needed before Python 3.8 (Python issue 35810)
363+
// https://github.com/pybind/pybind11/issues/1946
364+
Py_DECREF(type);
365+
#endif
360366
}
361367

362368
/** Create the type which can be used as a common base for all classes. This is
@@ -586,6 +592,9 @@ inline PyObject* make_new_python_type(const type_record &rec) {
586592
type->tp_as_number = &heap_type->as_number;
587593
type->tp_as_sequence = &heap_type->as_sequence;
588594
type->tp_as_mapping = &heap_type->as_mapping;
595+
#if PY_VERSION_HEX >= 0x03050000
596+
type->tp_as_async = &heap_type->as_async;
597+
#endif
589598

590599
/* Flags */
591600
type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
#endif
9494

9595
#define PYBIND11_VERSION_MAJOR 2
96-
#define PYBIND11_VERSION_MINOR 3
97-
#define PYBIND11_VERSION_PATCH 0
96+
#define PYBIND11_VERSION_MINOR 4
97+
#define PYBIND11_VERSION_PATCH 3
9898

9999
/// Include Python header, disable linking to pythonX_d.lib on Windows in debug mode
100100
#if defined(_MSC_VER)
@@ -113,10 +113,6 @@
113113
#include <frameobject.h>
114114
#include <pythread.h>
115115

116-
#if defined(_WIN32) && (defined(min) || defined(max))
117-
# error Macro clash with min and max -- define NOMINMAX when compiling your program on Windows
118-
#endif
119-
120116
#if defined(isalnum)
121117
# undef isalnum
122118
# undef isalpha
@@ -168,7 +164,9 @@
168164
#define PYBIND11_STR_TYPE ::pybind11::str
169165
#define PYBIND11_BOOL_ATTR "__bool__"
170166
#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_bool)
167+
// Providing a separate declaration to make Clang's -Wmissing-prototypes happy
171168
#define PYBIND11_PLUGIN_IMPL(name) \
169+
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name(); \
172170
extern "C" PYBIND11_EXPORT PyObject *PyInit_##name()
173171

174172
#else
@@ -192,8 +190,10 @@
192190
#define PYBIND11_STR_TYPE ::pybind11::bytes
193191
#define PYBIND11_BOOL_ATTR "__nonzero__"
194192
#define PYBIND11_NB_BOOL(ptr) ((ptr)->nb_nonzero)
193+
// Providing a separate PyInit decl to make Clang's -Wmissing-prototypes happy
195194
#define PYBIND11_PLUGIN_IMPL(name) \
196195
static PyObject *pybind11_init_wrapper(); \
196+
extern "C" PYBIND11_EXPORT void init##name(); \
197197
extern "C" PYBIND11_EXPORT void init##name() { \
198198
(void)pybind11_init_wrapper(); \
199199
} \
@@ -673,6 +673,7 @@ PYBIND11_RUNTIME_EXCEPTION(index_error, PyExc_IndexError)
673673
PYBIND11_RUNTIME_EXCEPTION(key_error, PyExc_KeyError)
674674
PYBIND11_RUNTIME_EXCEPTION(value_error, PyExc_ValueError)
675675
PYBIND11_RUNTIME_EXCEPTION(type_error, PyExc_TypeError)
676+
PYBIND11_RUNTIME_EXCEPTION(buffer_error, PyExc_BufferError)
676677
PYBIND11_RUNTIME_EXCEPTION(cast_error, PyExc_RuntimeError) /// Thrown when pybind11::cast or handle::call fail due to a type casting error
677678
PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used internally
678679

@@ -719,10 +720,6 @@ struct error_scope {
719720
/// Dummy destructor wrapper that can be used to expose classes with a private destructor
720721
struct nodelete { template <typename T> void operator()(T*) { } };
721722

722-
// overload_cast requires variable templates: C++14
723-
#if defined(PYBIND11_CPP14)
724-
#define PYBIND11_OVERLOAD_CAST 1
725-
726723
NAMESPACE_BEGIN(detail)
727724
template <typename... Args>
728725
struct overload_cast_impl {
@@ -742,19 +739,23 @@ struct overload_cast_impl {
742739
};
743740
NAMESPACE_END(detail)
744741

742+
// overload_cast requires variable templates: C++14
743+
#if defined(PYBIND11_CPP14)
744+
#define PYBIND11_OVERLOAD_CAST 1
745745
/// Syntax sugar for resolving overloaded function pointers:
746746
/// - regular: static_cast<Return (Class::*)(Arg0, Arg1, Arg2)>(&Class::func)
747747
/// - sweet: overload_cast<Arg0, Arg1, Arg2>(&Class::func)
748748
template <typename... Args>
749749
static constexpr detail::overload_cast_impl<Args...> overload_cast = {};
750750
// MSVC 2015 only accepts this particular initialization syntax for this variable template.
751+
#endif
751752

752753
/// Const member function selector for overload_cast
753754
/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
754755
/// - sweet: overload_cast<Arg>(&Class::func, const_)
755756
static constexpr auto const_ = std::true_type{};
756757

757-
#else // no overload_cast: providing something that static_assert-fails:
758+
#if !defined(PYBIND11_CPP14) // no overload_cast: providing something that static_assert-fails:
758759
template <typename... Args> struct overload_cast {
759760
static_assert(detail::deferred_t<std::false_type, Args...>::value,
760761
"pybind11::overload_cast<...> requires compiling in C++14 mode");

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

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,58 @@ struct type_info {
140140
/// Tracks the `internals` and `type_info` ABI version independent of the main library version
141141
#define PYBIND11_INTERNALS_VERSION 3
142142

143-
#if defined(_DEBUG)
143+
/// On MSVC, debug and release builds are not ABI-compatible!
144+
#if defined(_MSC_VER) && defined(_DEBUG)
144145
# define PYBIND11_BUILD_TYPE "_debug"
145146
#else
146147
# define PYBIND11_BUILD_TYPE ""
147148
#endif
148149

150+
/// Let's assume that different compilers are ABI-incompatible.
151+
#if defined(_MSC_VER)
152+
# define PYBIND11_COMPILER_TYPE "_msvc"
153+
#elif defined(__INTEL_COMPILER)
154+
# define PYBIND11_COMPILER_TYPE "_icc"
155+
#elif defined(__clang__)
156+
# define PYBIND11_COMPILER_TYPE "_clang"
157+
#elif defined(__PGI)
158+
# define PYBIND11_COMPILER_TYPE "_pgi"
159+
#elif defined(__MINGW32__)
160+
# define PYBIND11_COMPILER_TYPE "_mingw"
161+
#elif defined(__CYGWIN__)
162+
# define PYBIND11_COMPILER_TYPE "_gcc_cygwin"
163+
#elif defined(__GNUC__)
164+
# define PYBIND11_COMPILER_TYPE "_gcc"
165+
#else
166+
# define PYBIND11_COMPILER_TYPE "_unknown"
167+
#endif
168+
169+
#if defined(_LIBCPP_VERSION)
170+
# define PYBIND11_STDLIB "_libcpp"
171+
#elif defined(__GLIBCXX__) || defined(__GLIBCPP__)
172+
# define PYBIND11_STDLIB "_libstdcpp"
173+
#else
174+
# define PYBIND11_STDLIB ""
175+
#endif
176+
177+
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility.
178+
#if defined(__GXX_ABI_VERSION)
179+
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION)
180+
#else
181+
# define PYBIND11_BUILD_ABI ""
182+
#endif
183+
149184
#if defined(WITH_THREAD)
150185
# define PYBIND11_INTERNALS_KIND ""
151186
#else
152187
# define PYBIND11_INTERNALS_KIND "_without_thread"
153188
#endif
154189

155190
#define PYBIND11_INTERNALS_ID "__pybind11_internals_v" \
156-
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_BUILD_TYPE "__"
191+
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
157192

158193
#define PYBIND11_MODULE_LOCAL_ID "__pybind11_module_local_v" \
159-
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_BUILD_TYPE "__"
194+
PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
160195

161196
/// Each module locally stores a pointer to the `internals` data. The data
162197
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.
@@ -165,12 +200,48 @@ inline internals **&get_internals_pp() {
165200
return internals_pp;
166201
}
167202

203+
inline void translate_exception(std::exception_ptr p) {
204+
try {
205+
if (p) std::rethrow_exception(p);
206+
} catch (error_already_set &e) { e.restore(); return;
207+
} catch (const builtin_exception &e) { e.set_error(); return;
208+
} catch (const std::bad_alloc &e) { PyErr_SetString(PyExc_MemoryError, e.what()); return;
209+
} catch (const std::domain_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
210+
} catch (const std::invalid_argument &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
211+
} catch (const std::length_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
212+
} catch (const std::out_of_range &e) { PyErr_SetString(PyExc_IndexError, e.what()); return;
213+
} catch (const std::range_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
214+
} catch (const std::exception &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); return;
215+
} catch (...) {
216+
PyErr_SetString(PyExc_RuntimeError, "Caught an unknown exception!");
217+
return;
218+
}
219+
}
220+
221+
#if !defined(__GLIBCXX__)
222+
inline void translate_local_exception(std::exception_ptr p) {
223+
try {
224+
if (p) std::rethrow_exception(p);
225+
} catch (error_already_set &e) { e.restore(); return;
226+
} catch (const builtin_exception &e) { e.set_error(); return;
227+
}
228+
}
229+
#endif
230+
168231
/// Return a reference to the current `internals` data
169232
PYBIND11_NOINLINE inline internals &get_internals() {
170233
auto **&internals_pp = get_internals_pp();
171234
if (internals_pp && *internals_pp)
172235
return **internals_pp;
173236

237+
// Ensure that the GIL is held since we will need to make Python calls.
238+
// Cannot use py::gil_scoped_acquire here since that constructor calls get_internals.
239+
struct gil_scoped_acquire_local {
240+
gil_scoped_acquire_local() : state (PyGILState_Ensure()) {}
241+
~gil_scoped_acquire_local() { PyGILState_Release(state); }
242+
const PyGILState_STATE state;
243+
} gil;
244+
174245
constexpr auto *id = PYBIND11_INTERNALS_ID;
175246
auto builtins = handle(PyEval_GetBuiltins());
176247
if (builtins.contains(id) && isinstance<capsule>(builtins[id])) {
@@ -182,15 +253,7 @@ PYBIND11_NOINLINE inline internals &get_internals() {
182253
//
183254
// libstdc++ doesn't require this (types there are identified only by name)
184255
#if !defined(__GLIBCXX__)
185-
(*internals_pp)->registered_exception_translators.push_front(
186-
[](std::exception_ptr p) -> void {
187-
try {
188-
if (p) std::rethrow_exception(p);
189-
} catch (error_already_set &e) { e.restore(); return;
190-
} catch (const builtin_exception &e) { e.set_error(); return;
191-
}
192-
}
193-
);
256+
(*internals_pp)->registered_exception_translators.push_front(&translate_local_exception);
194257
#endif
195258
} else {
196259
if (!internals_pp) internals_pp = new internals*();
@@ -213,25 +276,7 @@ PYBIND11_NOINLINE inline internals &get_internals() {
213276
internals_ptr->istate = tstate->interp;
214277
#endif
215278
builtins[id] = capsule(internals_pp);
216-
internals_ptr->registered_exception_translators.push_front(
217-
[](std::exception_ptr p) -> void {
218-
try {
219-
if (p) std::rethrow_exception(p);
220-
} catch (error_already_set &e) { e.restore(); return;
221-
} catch (const builtin_exception &e) { e.set_error(); return;
222-
} catch (const std::bad_alloc &e) { PyErr_SetString(PyExc_MemoryError, e.what()); return;
223-
} catch (const std::domain_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
224-
} catch (const std::invalid_argument &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
225-
} catch (const std::length_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
226-
} catch (const std::out_of_range &e) { PyErr_SetString(PyExc_IndexError, e.what()); return;
227-
} catch (const std::range_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return;
228-
} catch (const std::exception &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); return;
229-
} catch (...) {
230-
PyErr_SetString(PyExc_RuntimeError, "Caught an unknown exception!");
231-
return;
232-
}
233-
}
234-
);
279+
internals_ptr->registered_exception_translators.push_front(&translate_exception);
235280
internals_ptr->static_property_type = make_static_property_type();
236281
internals_ptr->default_metaclass = make_default_metaclass();
237282
internals_ptr->instance_base = make_object_base_type(internals_ptr->default_metaclass);

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ struct type_caster<std::function<Return(Args...)>> {
6565
}
6666
};
6767

68-
value = [hfunc = func_handle(std::move(func))](Args... args) -> Return {
69-
gil_scoped_acquire acq;
70-
object retval(hfunc.f(std::forward<Args>(args)...));
71-
/* Visual studio 2015 parser issue: need parentheses around this expression */
72-
return (retval.template cast<Return>());
68+
// to emulate 'move initialization capture' in C++11
69+
struct func_wrapper {
70+
func_handle hfunc;
71+
func_wrapper(func_handle&& hf): hfunc(std::move(hf)) {}
72+
Return operator()(Args... args) const {
73+
gil_scoped_acquire acq;
74+
object retval(hfunc.f(std::forward<Args>(args)...));
75+
/* Visual studio 2015 parser issue: need parentheses around this expression */
76+
return (retval.template cast<Return>());
77+
}
7378
};
79+
80+
value = func_wrapper(func_handle(std::move(func)));
7481
return true;
7582
}
7683

0 commit comments

Comments
 (0)