Skip to content

Commit 9f7bed6

Browse files
Merge 'upstream/master' (07e2259) from previous merge-base (12e8774)
# Conflicts: # include/pybind11/cast.h # include/pybind11/pybind11.h
2 parents 965af15 + 07e2259 commit 9f7bed6

35 files changed

+620
-146
lines changed

.travis.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ matrix:
1616
- PY_CMD=python3
1717
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
1818
install:
19-
- $PY_CMD -m pip install --user --upgrade sphinx sphinx_rtd_theme breathe flake8 pep8-naming pytest
19+
# breathe 4.14 doesn't work with bit fields. See https://github.com/michaeljones/breathe/issues/462
20+
- $PY_CMD -m pip install --user --upgrade sphinx sphinx_rtd_theme breathe==4.13.1 flake8 pep8-naming pytest
2021
- curl -fsSL https://sourceforge.net/projects/doxygen/files/rel-1.8.15/doxygen-1.8.15.linux.bin.tar.gz/download | tar xz
2122
- export PATH="$PWD/doxygen-1.8.15/bin:$PATH"
2223
script:
@@ -33,8 +34,7 @@ matrix:
3334
- |
3435
# Barebones build
3536
cmake -DCMAKE_BUILD_TYPE=Debug -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(which $PY_CMD) .
36-
make pytest -j 2
37-
make cpptest -j 2
37+
make pytest -j 2 && make cpptest -j 2
3838
# The following are regular test configurations, including optional dependencies.
3939
# With regard to each other they differ in Python version, C++ standard and compiler.
4040
- os: linux
@@ -62,7 +62,7 @@ matrix:
6262
- os: linux
6363
dist: trusty
6464
env: PYTHON=2.7 CPP=14 GCC=6 CMAKE=1
65-
name: Python 2.7, c++14, gcc 4.8, CMake test
65+
name: Python 2.7, c++14, gcc 6, CMake test
6666
addons:
6767
apt:
6868
sources:
@@ -107,13 +107,39 @@ matrix:
107107
- lld-7
108108
- libc++-7-dev
109109
- libc++abi-7-dev # Why is this necessary???
110+
- os: linux
111+
dist: xenial
112+
env: PYTHON=3.8 CPP=17 GCC=7
113+
name: Python 3.8, c++17, gcc 7 (w/o numpy/scipy) # TODO: update build name when the numpy/scipy wheels become available
114+
addons:
115+
apt:
116+
sources:
117+
- deadsnakes
118+
- ubuntu-toolchain-r-test
119+
packages:
120+
- g++-7
121+
- python3.8-dev
122+
- python3.8-venv
123+
# Currently there is no numpy/scipy wheels available for python3.8
124+
# TODO: remove next before_install, install and script clause when the wheels become available
125+
before_install:
126+
- pyenv global $(pyenv whence 2to3) # activate all python versions
127+
- PY_CMD=python3
128+
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
129+
install:
130+
- $PY_CMD -m pip install --user --upgrade pytest
131+
script:
132+
- |
133+
# Barebones build
134+
cmake -DCMAKE_BUILD_TYPE=Debug -DPYBIND11_WERROR=ON -DDOWNLOAD_CATCH=ON -DPYTHON_EXECUTABLE=$(which $PY_CMD) .
135+
make pytest -j 2 && make cpptest -j 2
110136
- os: osx
111137
name: Python 2.7, c++14, AppleClang 7.3, CMake test
112138
osx_image: xcode7.3
113139
env: PYTHON=2.7 CPP=14 CLANG CMAKE=1
114140
- os: osx
115141
name: Python 3.7, c++14, AppleClang 9, Debug build
116-
osx_image: xcode9
142+
osx_image: xcode9.4
117143
env: PYTHON=3.7 CPP=14 CLANG DEBUG=1
118144
# Test a PyPy 2.7 build
119145
- os: linux
@@ -131,7 +157,7 @@ matrix:
131157
dist: trusty
132158
services: docker
133159
env: DOCKER=i386/debian:stretch PYTHON=3.5 CPP=14 GCC=6 INSTALL=1
134-
name: Python 3.4, c++14, gcc 6, 32-bit
160+
name: Python 3.5, c++14, gcc 6, 32-bit
135161
script:
136162
- |
137163
# Consolidated 32-bit Docker Build + Install
@@ -194,7 +220,7 @@ before_install:
194220
PY_CMD=python$PYTHON
195221
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
196222
if [ "$PY" = "3" ]; then
197-
brew update && brew upgrade python
223+
brew update && brew unlink python@2 && brew upgrade python
198224
else
199225
curl -fsSL https://bootstrap.pypa.io/get-pip.py | $PY_CMD - --user
200226
fi

docs/advanced/exceptions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ exceptions:
2828
+--------------------------------------+--------------------------------------+
2929
| :class:`std::range_error` | ``ValueError`` |
3030
+--------------------------------------+--------------------------------------+
31+
| :class:`std::overflow_error` | ``OverflowError`` |
32+
+--------------------------------------+--------------------------------------+
3133
| :class:`pybind11::stop_iteration` | ``StopIteration`` (used to implement |
3234
| | custom iterators) |
3335
+--------------------------------------+--------------------------------------+

docs/basics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ load and execute the example:
164164
Keyword arguments
165165
=================
166166

167-
With a simple modification code, it is possible to inform Python about the
167+
With a simple code modification, it is possible to inform Python about the
168168
names of the arguments ("i" and "j" in this case).
169169

170170
.. code-block:: cpp

docs/changelog.rst

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,86 @@ Changelog
66
Starting with version 1.8.0, pybind11 releases use a `semantic versioning
77
<http://semver.org>`_ policy.
88

9+
v2.4.3 (Oct 15, 2019)
10+
-----------------------------------------------------
11+
12+
* Adapt pybind11 to a C API convention change in Python 3.8. `#1950
13+
<https://github.com/pybind/pybind11/pull/1950>`_.
14+
15+
v2.4.2 (Sep 21, 2019)
16+
-----------------------------------------------------
17+
18+
* Replaced usage of a C++14 only construct. `#1929
19+
<https://github.com/pybind/pybind11/pull/1929>`_.
20+
21+
* Made an ifdef future-proof for Python >= 4. `f3109d
22+
<https://github.com/pybind/pybind11/commit/f3109d>`_.
23+
24+
v2.4.1 (Sep 20, 2019)
25+
-----------------------------------------------------
26+
27+
* Fixed a problem involving implicit conversion from enumerations to integers
28+
on Python 3.8. `#1780 <https://github.com/pybind/pybind11/pull/1780>`_.
929

10-
v2.3.1 (Not yet released)
30+
v2.4.0 (Sep 19, 2019)
1131
-----------------------------------------------------
1232

33+
* Try harder to keep pybind11-internal data structures separate when there
34+
are potential ABI incompatibilities. Fixes crashes that occurred when loading
35+
multiple pybind11 extensions that were e.g. compiled by GCC (libstdc++)
36+
and Clang (libc++).
37+
`#1588 <https://github.com/pybind/pybind11/pull/1588>`_ and
38+
`c9f5a <https://github.com/pybind/pybind11/commit/c9f5a>`_.
39+
40+
* Added support for ``__await__``, ``__aiter__``, and ``__anext__`` protocols.
41+
`#1842 <https://github.com/pybind/pybind11/pull/1842>`_.
42+
43+
* ``pybind11_add_module()``: don't strip symbols when compiling in
44+
``RelWithDebInfo`` mode. `#1980
45+
<https://github.com/pybind/pybind11/pull/1980>`_.
46+
47+
* ``enum_``: Reproduce Python behavior when comparing against invalid values
48+
(e.g. ``None``, strings, etc.). Add back support for ``__invert__()``.
49+
`#1912 <https://github.com/pybind/pybind11/pull/1912>`_,
50+
`#1907 <https://github.com/pybind/pybind11/pull/1907>`_.
51+
52+
* List insertion operation for ``py::list``.
53+
Added ``.empty()`` to all collection types.
54+
Added ``py::set::contains()`` and ``py::dict::contains()``.
55+
`#1887 <https://github.com/pybind/pybind11/pull/1887>`_,
56+
`#1884 <https://github.com/pybind/pybind11/pull/1884>`_,
57+
`#1888 <https://github.com/pybind/pybind11/pull/1888>`_.
58+
1359
* ``py::details::overload_cast_impl`` is available in C++11 mode, can be used
1460
like ``overload_cast`` with an additional set of parantheses.
15-
`1581 <https://github.com/pybind/pybind11/pull/1581>`_.
61+
`#1581 <https://github.com/pybind/pybind11/pull/1581>`_.
62+
63+
* Fixed ``get_include()`` on Conda.
64+
`#1877 <https://github.com/pybind/pybind11/pull/1877>`_.
65+
66+
* ``stl_bind.h``: negative indexing support.
67+
`#1882 <https://github.com/pybind/pybind11/pull/1882>`_.
68+
69+
* Minor CMake fix to add MinGW compatibility.
70+
`#1851 <https://github.com/pybind/pybind11/pull/1851>`_.
71+
72+
* GIL-related fixes.
73+
`#1836 <https://github.com/pybind/pybind11/pull/1836>`_,
74+
`8b90b <https://github.com/pybind/pybind11/commit/8b90b>`_.
75+
76+
* Other very minor/subtle fixes and improvements.
77+
`#1329 <https://github.com/pybind/pybind11/pull/1329>`_,
78+
`#1910 <https://github.com/pybind/pybind11/pull/1910>`_,
79+
`#1863 <https://github.com/pybind/pybind11/pull/1863>`_,
80+
`#1847 <https://github.com/pybind/pybind11/pull/1847>`_,
81+
`#1890 <https://github.com/pybind/pybind11/pull/1890>`_,
82+
`#1860 <https://github.com/pybind/pybind11/pull/1860>`_,
83+
`#1848 <https://github.com/pybind/pybind11/pull/1848>`_,
84+
`#1821 <https://github.com/pybind/pybind11/pull/1821>`_,
85+
`#1837 <https://github.com/pybind/pybind11/pull/1837>`_,
86+
`#1833 <https://github.com/pybind/pybind11/pull/1833>`_,
87+
`#1748 <https://github.com/pybind/pybind11/pull/1748>`_,
88+
`#1852 <https://github.com/pybind/pybind11/pull/1852>`_.
1689

1790
v2.3.0 (June 11, 2019)
1891
-----------------------------------------------------

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
# built documents.
6262
#
6363
# The short X.Y version.
64-
version = '2.3'
64+
version = '2.4'
6565
# The full version, including alpha/beta/rc tags.
66-
release = '2.3.dev1'
66+
release = '2.4.dev4'
6767

6868
# The language for content autogenerated by Sphinx. Refer to documentation
6969
# for a list of supported languages.

docs/faq.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,33 @@ that that were ``malloc()``-ed in another shared library, using data
248248
structures with incompatible ABIs, and so on. pybind11 is very careful not
249249
to make these types of mistakes.
250250

251+
How can I properly handle Ctrl-C in long-running functions?
252+
===========================================================
253+
254+
Ctrl-C is received by the Python interpreter, and holds it until the GIL
255+
is released, so a long-running function won't be interrupted.
256+
257+
To interrupt from inside your function, you can use the ``PyErr_CheckSignals()``
258+
function, that will tell if a signal has been raised on the Python side. This
259+
function merely checks a flag, so its impact is negligible. When a signal has
260+
been received, you must either explicitly interrupt execution by throwing
261+
``py::error_already_set`` (which will propagate the existing
262+
``KeyboardInterrupt``), or clear the error (which you usually will not want):
263+
264+
.. code-block:: cpp
265+
266+
PYBIND11_MODULE(example, m)
267+
{
268+
m.def("long running_func", []()
269+
{
270+
for (;;) {
271+
if (PyErr_CheckSignals() != 0)
272+
throw py::error_already_set();
273+
// Long running iteration
274+
}
275+
});
276+
}
277+
251278
Inconsistent detection of Python version in CMake and pybind11
252279
==============================================================
253280

docs/release.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ To release a new version of pybind11:
1313
- ``git push --tags``.
1414
- ``python setup.py sdist upload``.
1515
- ``python setup.py bdist_wheel upload``.
16-
- Update conda-forge (https://github.com/conda-forge/pybind11-feedstock) via PR
17-
- download release package from Github: ``wget https://github.com/pybind/pybind11/archive/vX.Y.Z.tar.gz``
18-
- compute checksum: ``shasum -a 256 vX.Y.Z.tar.gz``
19-
- change version number and checksum in ``recipe/meta.yml``
2016
- Get back to work
2117
- Update ``_version.py`` (add 'dev' and increment minor).
2218
- Update version in ``docs/conf.py``

include/pybind11/buffer_info.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,39 @@ struct buffer_info {
2121
std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::format()
2222
ssize_t ndim = 0; // Number of dimensions
2323
std::vector<ssize_t> shape; // Shape of the tensor (1 entry per dimension)
24-
std::vector<ssize_t> strides; // Number of entries between adjacent entries (for each per dimension)
24+
std::vector<ssize_t> strides; // Number of bytes between adjacent entries (for each per dimension)
25+
bool readonly = false; // flag to indicate if the underlying storage may be written to
2526

2627
buffer_info() { }
2728

2829
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
29-
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in)
30+
detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
3031
: ptr(ptr), itemsize(itemsize), size(1), format(format), ndim(ndim),
31-
shape(std::move(shape_in)), strides(std::move(strides_in)) {
32+
shape(std::move(shape_in)), strides(std::move(strides_in)), readonly(readonly) {
3233
if (ndim != (ssize_t) shape.size() || ndim != (ssize_t) strides.size())
3334
pybind11_fail("buffer_info: ndim doesn't match shape and/or strides length");
3435
for (size_t i = 0; i < (size_t) ndim; ++i)
3536
size *= shape[i];
3637
}
3738

3839
template <typename T>
39-
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in)
40-
: buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in)) { }
40+
buffer_info(T *ptr, detail::any_container<ssize_t> shape_in, detail::any_container<ssize_t> strides_in, bool readonly=false)
41+
: buffer_info(private_ctr_tag(), ptr, sizeof(T), format_descriptor<T>::format(), static_cast<ssize_t>(shape_in->size()), std::move(shape_in), std::move(strides_in), readonly) { }
4142

42-
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size)
43-
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}) { }
43+
buffer_info(void *ptr, ssize_t itemsize, const std::string &format, ssize_t size, bool readonly=false)
44+
: buffer_info(ptr, itemsize, format, 1, {size}, {itemsize}, readonly) { }
4445

4546
template <typename T>
46-
buffer_info(T *ptr, ssize_t size)
47-
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size) { }
47+
buffer_info(T *ptr, ssize_t size, bool readonly=false)
48+
: buffer_info(ptr, sizeof(T), format_descriptor<T>::format(), size, readonly) { }
49+
50+
template <typename T>
51+
buffer_info(const T *ptr, ssize_t size, bool readonly=true)
52+
: buffer_info(const_cast<T*>(ptr), sizeof(T), format_descriptor<T>::format(), size, readonly) { }
4853

4954
explicit buffer_info(Py_buffer *view, bool ownview = true)
5055
: buffer_info(view->buf, view->itemsize, view->format, view->ndim,
51-
{view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}) {
56+
{view->shape, view->shape + view->ndim}, {view->strides, view->strides + view->ndim}, view->readonly) {
5257
this->view = view;
5358
this->ownview = ownview;
5459
}
@@ -70,6 +75,7 @@ struct buffer_info {
7075
strides = std::move(rhs.strides);
7176
std::swap(view, rhs.view);
7277
std::swap(ownview, rhs.ownview);
78+
readonly = rhs.readonly;
7379
return *this;
7480
}
7581

@@ -81,8 +87,8 @@ struct buffer_info {
8187
struct private_ctr_tag { };
8288

8389
buffer_info(private_ctr_tag, void *ptr, ssize_t itemsize, const std::string &format, ssize_t ndim,
84-
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in)
85-
: buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in)) { }
90+
detail::any_container<ssize_t> &&shape_in, detail::any_container<ssize_t> &&strides_in, bool readonly)
91+
: buffer_info(ptr, itemsize, format, ndim, std::move(shape_in), std::move(strides_in), readonly) { }
8692

8793
Py_buffer *view = nullptr;
8894
bool ownview = false;

0 commit comments

Comments
 (0)