Skip to content

Commit a6287fc

Browse files
ax3lwjakob
andauthored
pybind11: v2.4.3+ (#821)
* Doc: pybind11 2.4.3+ * 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 Co-authored-by: Wenzel Jakob <[email protected]>
1 parent f25e7dc commit a6287fc

21 files changed

+290
-112
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ if(openPMD_USE_PYTHON STREQUAL AUTO)
252252
if(openPMD_USE_INTERNAL_PYBIND11)
253253
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11")
254254
set(openPMD_HAVE_PYTHON TRUE)
255-
message(STATUS "pybind11: Using INTERNAL version 2.3.0")
255+
message(STATUS "pybind11: Using INTERNAL version 2.4.3")
256256
else()
257-
find_package(pybind11 2.3.0 CONFIG)
257+
find_package(pybind11 2.4.3 CONFIG)
258258
if(pybind11_FOUND)
259259
set(openPMD_HAVE_PYTHON TRUE)
260260
message(STATUS "pybind11: Found version '${pybind11_VERSION}'")
@@ -275,9 +275,9 @@ elseif(openPMD_USE_PYTHON)
275275
if(openPMD_USE_INTERNAL_PYBIND11)
276276
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11")
277277
set(openPMD_HAVE_PYTHON TRUE)
278-
message(STATUS "pybind11: Using INTERNAL version 2.3.0")
278+
message(STATUS "pybind11: Using INTERNAL version 2.4.3")
279279
else()
280-
find_package(pybind11 2.3.0 REQUIRED CONFIG)
280+
find_package(pybind11 2.4.3 REQUIRED CONFIG)
281281
set(openPMD_HAVE_PYTHON TRUE)
282282
message(STATUS "pybind11: Found version '${pybind11_VERSION}'")
283283
endif()

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Required:
105105
Shipped internally in `share/openPMD/thirdParty/`:
106106
* [MPark.Variant](https://github.com/mpark/variant) 1.4.0+ ([BSL-1.0](https://github.com/mpark/variant/blob/master/LICENSE.md))
107107
* [Catch2](https://github.com/catchorg/Catch2) 2.6.1+ ([BSL-1.0](https://github.com/catchorg/Catch2/blob/master/LICENSE.txt))
108-
* [pybind11](https://github.com/pybind/pybind11) 2.3.0+ ([new BSD](https://github.com/pybind/pybind11/blob/master/LICENSE))
108+
* [pybind11](https://github.com/pybind/pybind11) 2.4.3+ ([new BSD](https://github.com/pybind/pybind11/blob/master/LICENSE))
109109
* [NLohmann-JSON](https://github.com/nlohmann/json) 3.7.0+ ([MIT](https://github.com/nlohmann/json/blob/develop/LICENSE.MIT))
110110

111111
I/O backends:
@@ -120,7 +120,7 @@ while those can be built either with or without:
120120
Optional language bindings:
121121
* Python:
122122
* Python 3.5 - 3.8
123-
* pybind 2.3.0+
123+
* pybind 2.4.3+
124124
* numpy 1.15+
125125
* mpi4py 2.1+
126126

@@ -260,7 +260,7 @@ The following options allow to switch to external installs:
260260
|---------------------------------|------------|---------------|---------|
261261
| `openPMD_USE_INTERNAL_VARIANT` | **ON**/OFF | MPark.Variant | 1.4.0+ |
262262
| `openPMD_USE_INTERNAL_CATCH` | **ON**/OFF | Catch2 | 2.6.1+ |
263-
| `openPMD_USE_INTERNAL_PYBIND11` | **ON**/OFF | pybind11 | 2.3.0+ |
263+
| `openPMD_USE_INTERNAL_PYBIND11` | **ON**/OFF | pybind11 | 2.4.3+ |
264264
| `openPMD_USE_INTERNAL_JSON` | **ON**/OFF | NLohmann-JSON | 3.7.0+ |
265265

266266
By default, this will build as a shared library (`libopenPMD.[so|dylib|dll]`) and installs also its headers.

docs/source/dev/buildoptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ CMake Option Values Installs Library Version
6969
================================= =========== ======== ============= ========
7070
``openPMD_USE_INTERNAL_VARIANT`` **ON**/OFF Yes MPark.Variant 1.4.0+
7171
``openPMD_USE_INTERNAL_CATCH`` **ON**/OFF No Catch2 2.6.1+
72-
``openPMD_USE_INTERNAL_PYBIND11`` **ON**/OFF No pybind11 2.3.0+
72+
``openPMD_USE_INTERNAL_PYBIND11`` **ON**/OFF No pybind11 2.4.3+
7373
``openPMD_USE_INTERNAL_JSON`` **ON**/OFF No NLohmann-JSON 3.7.0+
7474
================================= =========== ======== ============= ========
7575

docs/source/dev/dependencies.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The following libraries are shipped internally in ``share/openPMD/thirdParty/``
1919

2020
* `MPark.Variant <https://github.com/mpark/variant>`_ 1.4.0+ (`BSL-1.0 <https://github.com/mpark/variant/blob/master/LICENSE.md>`_)
2121
* `Catch2 <https://github.com/catchorg/Catch2>`_ 2.6.1+ (`BSL-1.0 <https://github.com/catchorg/Catch2/blob/master/LICENSE.txt>`__)
22-
* `pybind11 <https://github.com/pybind/pybind11>`_ 2.3.0+ (`new BSD <https://github.com/pybind/pybind11/blob/master/LICENSE>`_)
22+
* `pybind11 <https://github.com/pybind/pybind11>`_ 2.4.3+ (`new BSD <https://github.com/pybind/pybind11/blob/master/LICENSE>`_)
2323
* `NLohmann-JSON <https://github.com/nlohmann/json>`_ 3.7.0+ (`MIT <https://github.com/nlohmann/json/blob/develop/LICENSE.MIT>`_)
2424

2525
Optional: I/O backends
@@ -40,7 +40,7 @@ Optional: language bindings
4040
* Python:
4141

4242
* Python 3.5 - 3.8
43-
* pybind11 2.3.0+
43+
* pybind11 2.4.3+
4444
* numpy 1.15+
4545
* mpi4py 2.1+
4646

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build-system]
2-
requires = ["setuptools>38.6", "wheel", "cmake>=3.12.0,<4.0.0", "pybind11>=2.3.0,<3.0.0"]
2+
requires = ["setuptools>38.6", "wheel", "cmake>=3.12.0,<4.0.0", "pybind11>=2.4.3,<3.0.0"]

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");

0 commit comments

Comments
 (0)