Skip to content

Commit e6bd3d7

Browse files
committed
Merge branch 'master' of github.com:pybind/pybind11 into pypy3
2 parents a752c51 + 8c0cd94 commit e6bd3d7

38 files changed

+668
-139
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cmake_install.cmake
1010
*.sdf
1111
*.opensdf
1212
*.vcxproj
13+
*.vcxproj.user
1314
*.filters
1415
example.dir
1516
Win32

.travis.yml

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ matrix:
1717
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
1818
install:
1919
# 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
20+
# Latest breathe + Sphinx causes warnings and errors out
21+
- $PY_CMD -m pip install --user --upgrade "sphinx<3" sphinx_rtd_theme breathe==4.13.1 flake8 pep8-naming pytest
2122
- curl -fsSL https://sourceforge.net/projects/doxygen/files/rel-1.8.15/doxygen-1.8.15.linux.bin.tar.gz/download | tar xz
2223
- export PATH="$PWD/doxygen-1.8.15/bin:$PATH"
2324
script:
@@ -109,7 +110,7 @@ matrix:
109110
- os: linux
110111
dist: xenial
111112
env: PYTHON=3.8 CPP=17 GCC=7
112-
name: Python 3.8, c++17, gcc 7 (w/o numpy/scipy) # TODO: update build name when the numpy/scipy wheels become available
113+
name: Python 3.8, c++17, gcc 7
113114
addons:
114115
apt:
115116
sources:
@@ -119,12 +120,21 @@ matrix:
119120
- g++-7
120121
- python3.8-dev
121122
- python3.8-venv
122-
# Currently there is no numpy/scipy wheels available for python3.8
123-
# TODO: remove next before_install, install and script clause when the wheels become available
124-
before_install:
125-
- pyenv global $(pyenv whence 2to3) # activate all python versions
126-
- PY_CMD=python3
127-
- $PY_CMD -m pip install --user --upgrade pip wheel setuptools
123+
- os: linux
124+
dist: xenial
125+
env: PYTHON=3.9 CPP=17 GCC=7
126+
name: Python 3.9 beta, c++17, gcc 7 (w/o numpy/scipy) # TODO: update build name when the numpy/scipy wheels become available
127+
addons:
128+
apt:
129+
sources:
130+
- deadsnakes
131+
- ubuntu-toolchain-r-test
132+
packages:
133+
- g++-7
134+
- python3.9-dev
135+
- python3.9-venv
136+
# Currently there are no numpy/scipy wheels available for python3.9
137+
# TODO: remove next install and script clause when the wheels become available
128138
install:
129139
- $PY_CMD -m pip install --user --upgrade pytest
130140
script:
@@ -143,25 +153,25 @@ matrix:
143153
# Test a PyPy 2.7 build
144154
- os: linux
145155
dist: trusty
146-
env: PYPY=5.8.0 PYTHON=2.7 CPP=11 GCC=4.8
147-
name: PyPy 5.8.0, Python 2.7, c++11, gcc 4.8
156+
env: PYPY=7.3.1 PYTHON=2.7 CPP=11 GCC=4.8
157+
name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
148158
addons:
149159
apt:
150160
packages:
151161
- libblas-dev
152162
- liblapack-dev
153163
- gfortran
154-
# Test a PyPy 3.6 build
155164
- os: linux
156-
dist: trusty
157-
env: PYPY=7.3.0 PYTHON=3.6 CPP=11 GCC=4.8
158-
name: PyPy 7.3.0, Python 3.6, c++11, gcc 4.8
165+
dist: xenial
166+
env: PYPY=7.3.1 PYTHON=3.6 CPP=11 GCC=5
167+
name: PyPy 7.3, Python 3.6, c++11, gcc 5
159168
addons:
160169
apt:
161170
packages:
162171
- libblas-dev
163172
- liblapack-dev
164173
- gfortran
174+
- g++-5
165175
# Build in 32-bit mode and tests against the CMake-installed version
166176
- os: linux
167177
dist: trusty
@@ -181,6 +191,10 @@ matrix:
181191
cmake ../pybind11-tests ${CMAKE_EXTRA_ARGS} -DPYBIND11_WERROR=ON
182192
make pytest -j 2"
183193
set +ex
194+
allow_failures:
195+
- name: PyPy 7.3, Python 2.7, c++11, gcc 4.8
196+
- name: PyPy 7.3, Python 3.6, c++11, gcc 5
197+
- name: Python 3.9 beta, c++17, gcc 7 (w/o numpy/scipy)
184198
cache:
185199
directories:
186200
- $HOME/.local/bin
@@ -222,9 +236,15 @@ before_install:
222236
SCRIPT_RUN_PREFIX="docker exec --tty $containerid"
223237
$SCRIPT_RUN_PREFIX sh -c 'for s in 0 15; do sleep $s; apt-get update && apt-get -qy dist-upgrade && break; done'
224238
else
239+
<<<<<<< HEAD
225240
if [ "$PYPY" = "5.8.0" ]; then
226241
curl -fSL https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.8.0-linux64.tar.bz2 | tar xj
227242
PY_CMD=$(echo `pwd`/pypy2-v5.8.0-linux64/bin/pypy)
243+
=======
244+
if [ -n "$PYPY" ]; then
245+
curl -fSL https://bitbucket.org/pypy/pypy/downloads/pypy$PYTHON-v$PYPY-linux64.tar.bz2 | tar xj
246+
PY_CMD=$(echo `pwd`/pypy$PYTHON-v$PYPY-linux64/bin/pypy$PY)
247+
>>>>>>> 8c0cd94465fbc1dbc34217e5a614edc784f0913e
228248
CMAKE_EXTRA_ARGS+=" -DPYTHON_EXECUTABLE:FILEPATH=$PY_CMD"
229249
elif [ -n "$PYPY" ]; then
230250
curl -fSL https://bitbucket.org/pypy/pypy/downloads/pypy${PYTHON:0:3}-v${PYPY}-linux64.tar.bz2 | tar xj
@@ -271,10 +291,19 @@ install:
271291
fi
272292
273293
local PIP_CMD=""
294+
<<<<<<< HEAD
274295
export NPY_NUM_BUILD_JOBS=2
275296
if [ -n "$PYPY" ]; then
276297
echo Installing "pytest"
277298
$PY_CMD -m pip install --user --upgrade pytest
299+
=======
300+
if [ -n "$PYPY" ]; then
301+
# For expediency, install only versions that are available on the extra index.
302+
travis_wait 30 \
303+
$PY_CMD -m pip install --user --upgrade --extra-index-url https://antocuni.github.io/pypy-wheels/manylinux2010 \
304+
numpy scipy
305+
$PY_CMD -m pip install --user --upgrade pytest
306+
>>>>>>> 8c0cd94465fbc1dbc34217e5a614edc784f0913e
278307
else
279308
echo "Installing pytest, numpy, scipy..."
280309
$PY_CMD -m pip install --user --upgrade pytest numpy scipy

docs/advanced/classes.rst

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,17 @@ An instance can now be pickled as follows:
768768
p.setExtra(15)
769769
data = pickle.dumps(p, 2)
770770
771-
Note that only the cPickle module is supported on Python 2.7. The second
772-
argument to ``dumps`` is also crucial: it selects the pickle protocol version
773-
2, since the older version 1 is not supported. Newer versions are also fine—for
774-
instance, specify ``-1`` to always use the latest available version. Beware:
775-
failure to follow these instructions will cause important pybind11 memory
776-
allocation routines to be skipped during unpickling, which will likely lead to
777-
memory corruption and/or segmentation faults.
771+
772+
.. note::
773+
Note that only the cPickle module is supported on Python 2.7.
774+
775+
The second argument to ``dumps`` is also crucial: it selects the pickle
776+
protocol version 2, since the older version 1 is not supported. Newer
777+
versions are also fine—for instance, specify ``-1`` to always use the
778+
latest available version. Beware: failure to follow these instructions
779+
will cause important pybind11 memory allocation routines to be skipped
780+
during unpickling, which will likely lead to memory corruption and/or
781+
segmentation faults.
778782

779783
.. seealso::
780784

@@ -784,6 +788,38 @@ memory corruption and/or segmentation faults.
784788

785789
.. [#f3] http://docs.python.org/3/library/pickle.html#pickling-class-instances
786790
791+
Deepcopy support
792+
================
793+
794+
Python normally uses references in assignments. Sometimes a real copy is needed
795+
to prevent changing all copies. The ``copy`` module [#f5]_ provides these
796+
capabilities.
797+
798+
On Python 3, a class with pickle support is automatically also (deep)copy
799+
compatible. However, performance can be improved by adding custom
800+
``__copy__`` and ``__deepcopy__`` methods. With Python 2.7, these custom methods
801+
are mandatory for (deep)copy compatibility, because pybind11 only supports
802+
cPickle.
803+
804+
For simple classes (deep)copy can be enabled by using the copy constructor,
805+
which should look as follows:
806+
807+
.. code-block:: cpp
808+
809+
py::class_<Copyable>(m, "Copyable")
810+
.def("__copy__", [](const Copyable &self) {
811+
return Copyable(self);
812+
})
813+
.def("__deepcopy__", [](const Copyable &self, py::dict) {
814+
return Copyable(self);
815+
}, "memo"_a);
816+
817+
.. note::
818+
819+
Dynamic attributes will not be copied in this example.
820+
821+
.. [#f5] https://docs.python.org/3/library/copy.html
822+
787823
Multiple Inheritance
788824
====================
789825

@@ -1042,6 +1078,32 @@ described trampoline:
10421078
``.def("foo", static_cast<int (A::*)() const>(&Publicist::foo));``
10431079
where ``int (A::*)() const`` is the type of ``A::foo``.
10441080

1081+
Binding final classes
1082+
=====================
1083+
1084+
Some classes may not be appropriate to inherit from. In C++11, classes can
1085+
use the ``final`` specifier to ensure that a class cannot be inherited from.
1086+
The ``py::is_final`` attribute can be used to ensure that Python classes
1087+
cannot inherit from a specified type. The underlying C++ type does not need
1088+
to be declared final.
1089+
1090+
.. code-block:: cpp
1091+
1092+
class IsFinal final {};
1093+
1094+
py::class_<IsFinal>(m, "IsFinal", py::is_final());
1095+
1096+
When you try to inherit from such a class in Python, you will now get this
1097+
error:
1098+
1099+
.. code-block:: pycon
1100+
1101+
>>> class PyFinalChild(IsFinal):
1102+
... pass
1103+
TypeError: type 'IsFinal' is not an acceptable base type
1104+
1105+
.. note:: This attribute is currently ignored on PyPy
1106+
10451107
Custom automatic downcasters
10461108
============================
10471109

docs/advanced/functions.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,34 @@ like so:
362362
py::class_<MyClass>("MyClass")
363363
.def("myFunction", py::arg("arg") = (SomeType *) nullptr);
364364
365+
Keyword-only arguments
366+
======================
367+
368+
Python 3 introduced keyword-only arguments by specifying an unnamed ``*``
369+
argument in a function definition:
370+
371+
.. code-block:: python
372+
373+
def f(a, *, b): # a can be positional or via keyword; b must be via keyword
374+
pass
375+
376+
f(a=1, b=2) # good
377+
f(b=2, a=1) # good
378+
f(1, b=2) # good
379+
f(1, 2) # TypeError: f() takes 1 positional argument but 2 were given
380+
381+
Pybind11 provides a ``py::kwonly`` object that allows you to implement
382+
the same behaviour by specifying the object between positional and keyword-only
383+
argument annotations when registering the function:
384+
385+
.. code-block:: cpp
386+
387+
m.def("f", [](int a, int b) { /* ... */ },
388+
py::arg("a"), py::kwonly(), py::arg("b"));
389+
390+
Note that, as in Python, you cannot combine this with a ``py::args`` argument.
391+
This feature does *not* require Python 3 to work.
392+
365393
.. _nonconverting_arguments:
366394

367395
Non-converting arguments

docs/changelog.rst

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

9+
v2.5.0 (Mar 31, 2020)
10+
-----------------------------------------------------
11+
12+
* Use C++17 fold expressions in type casters, if available. This can
13+
improve performance during overload resolution when functions have
14+
multiple arguments.
15+
`#2043 <https://github.com/pybind/pybind11/pull/2043>`_.
16+
17+
* Changed include directory resolution in ``pybind11/__init__.py``
18+
and installation in ``setup.py``. This fixes a number of open issues
19+
where pybind11 headers could not be found in certain environments.
20+
`#1995 <https://github.com/pybind/pybind11/pull/1995>`_.
21+
22+
* C++20 ``char8_t`` and ``u8string`` support. `#2026
23+
<https://github.com/pybind/pybind11/pull/2026>`_.
24+
25+
* CMake: search for Python 3.9. `bb9c91
26+
<https://github.com/pybind/pybind11/commit/bb9c91>`_.
27+
28+
* Fixes for MSYS-based build environments.
29+
`#2087 <https://github.com/pybind/pybind11/pull/2087>`_,
30+
`#2053 <https://github.com/pybind/pybind11/pull/2053>`_.
31+
32+
* STL bindings for ``std::vector<...>::clear``. `#2074
33+
<https://github.com/pybind/pybind11/pull/2074>`_.
34+
35+
* Read-only flag for ``py::buffer``. `#1466
36+
<https://github.com/pybind/pybind11/pull/1466>`_.
37+
38+
* Exception handling during module initialization.
39+
`bf2b031 <https://github.com/pybind/pybind11/commit/bf2b031>`_.
40+
41+
* Support linking against a CPython debug build.
42+
`#2025 <https://github.com/pybind/pybind11/pull/2025>`_.
43+
44+
* Fixed issues involving the availability and use of aligned ``new`` and
45+
``delete``. `#1988 <https://github.com/pybind/pybind11/pull/1988>`_,
46+
`759221 <https://github.com/pybind/pybind11/commit/759221>`_.
47+
48+
* Fixed a resource leak upon interpreter shutdown.
49+
`#2020 <https://github.com/pybind/pybind11/pull/2020>`_.
50+
51+
* Fixed error handling in the boolean caster.
52+
`#1976 <https://github.com/pybind/pybind11/pull/1976>`_.
53+
954
v2.4.3 (Oct 15, 2019)
1055
-----------------------------------------------------
1156

docs/compiling.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,14 @@ on the target compiler, falling back to C++11 if C++14 support is not
105105
available. Note, however, that this default is subject to change: future
106106
pybind11 releases are expected to migrate to newer C++ standards as they become
107107
available. To override this, the standard flag can be given explicitly in
108-
``PYBIND11_CPP_STANDARD``:
108+
`CMAKE_CXX_STANDARD <https://cmake.org/cmake/help/v3.17/variable/CMAKE_CXX_STANDARD.html>`_:
109109

110110
.. code-block:: cmake
111111
112112
# Use just one of these:
113-
# GCC/clang:
114-
set(PYBIND11_CPP_STANDARD -std=c++11)
115-
set(PYBIND11_CPP_STANDARD -std=c++14)
116-
set(PYBIND11_CPP_STANDARD -std=c++1z) # Experimental C++17 support
117-
# MSVC:
118-
set(PYBIND11_CPP_STANDARD /std:c++14)
119-
set(PYBIND11_CPP_STANDARD /std:c++latest) # Enables some MSVC C++17 features
113+
set(CMAKE_CXX_STANDARD 11)
114+
set(CMAKE_CXX_STANDARD 14)
115+
set(CMAKE_CXX_STANDARD 17) # Experimental C++17 support
120116
121117
add_subdirectory(pybind11) # or find_package(pybind11)
122118
@@ -287,3 +283,11 @@ code by introspecting existing C++ codebases using LLVM/Clang. See the
287283
[binder]_ documentation for details.
288284

289285
.. [binder] http://cppbinder.readthedocs.io/en/latest/about.html
286+
287+
[AutoWIG]_ is a Python library that wraps automatically compiled libraries into
288+
high-level languages. It parses C++ code using LLVM/Clang technologies and
289+
generates the wrappers using the Mako templating engine. The approach is automatic,
290+
extensible, and applies to very complex C++ libraries, composed of thousands of
291+
classes or incorporating modern meta-programming constructs.
292+
293+
.. [AutoWIG] https://github.com/StatisKit/AutoWIG

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.4'
64+
version = '2.5'
6565
# The full version, including alpha/beta/rc tags.
66-
release = '2.4.dev4'
66+
release = '2.5.dev1'
6767

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

0 commit comments

Comments
 (0)