Skip to content

Commit

Permalink
Merge pull request #20 from EricCousineau-TRI/feature/merge_20180903
Browse files Browse the repository at this point in the history
Merge `upstream/master` (435dbdd) from previous merge-base (e763f04)
  • Loading branch information
EricCousineau-TRI authored Nov 19, 2018
2 parents 8ad6a89 + c3fddfd commit 25731f6
Show file tree
Hide file tree
Showing 52 changed files with 1,054 additions and 203 deletions.
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ image:
- Visual Studio 2017
- Visual Studio 2015
test: off
skip_branch_with_pr: true
build:
parallel: true
platform:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ MANIFEST
*.py[co]
*.egg-info
*~
.*.swp
.DS_Store
/dist
/build
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "tools/clang"]
path = tools/clang
url = https://github.com/wjakob/clang-cindex-python3
url = ../../wjakob/clang-cindex-python3
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ matrix:
env: PYTHON=2.7 CPP=14 CLANG CMAKE=1
- os: osx
osx_image: xcode9
env: PYTHON=3.6 CPP=14 CLANG DEBUG=1
env: PYTHON=3.7 CPP=14 CLANG DEBUG=1
# Test a PyPy 2.7 build
- os: linux
env: PYPY=5.8 PYTHON=2.7 CPP=11 GCC=4.8
Expand Down Expand Up @@ -108,7 +108,7 @@ before_install:
export CXX=g++-$GCC CC=gcc-$GCC
fi
if [ "$GCC" = "6" ]; then DOCKER=${ARCH:+$ARCH/}debian:stretch
elif [ "$GCC" = "7" ]; then DOCKER=debian:buster EXTRA_PACKAGES+=" catch" DOWNLOAD_CATCH=OFF
elif [ "$GCC" = "7" ]; then DOCKER=debian:buster EXTRA_PACKAGES+=" catch python3-distutils" DOWNLOAD_CATCH=OFF
fi
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
export CXX=clang++ CC=clang;
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE INTERNAL "")
set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE INTERNAL "")
set(PYTHON_MODULE_PREFIX ${PYTHON_MODULE_PREFIX} CACHE INTERNAL "")
set(PYTHON_MODULE_EXTENSION ${PYTHON_MODULE_EXTENSION} CACHE INTERNAL "")
set(PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR} CACHE INTERNAL "")
set(PYTHON_VERSION_MINOR ${PYTHON_VERSION_MINOR} CACHE INTERNAL "")

# NB: when adding a header don't forget to also add it to setup.py
set(PYBIND11_HEADERS
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ adhere to the following rules to make the process as smooth as possible:
do add value by themselves.
* Add tests for any new functionality and run the test suite (``make pytest``)
to ensure that no existing features break.
* Please run ``flake8`` and ``tools/check-style.sh`` to check your code matches
the project style. (Note that ``check-style.sh`` requires ``gawk``.)
* This project has a strong focus on providing general solutions using a
minimal amount of code, thus small pull requests are greatly preferred.

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pybind11 can map the following core C++ features to Python
- Custom operators
- Single and multiple inheritance
- STL data structures
- Iterators and ranges
- Smart pointers with reference counting like ``std::shared_ptr``
- Internal references with correct reference counting
- C++ classes with virtual (and pure virtual) methods can be extended in Python
Expand Down
2 changes: 2 additions & 0 deletions docs/advanced/cast/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ as arguments and return values, refer to the section on binding :ref:`classes`.
+------------------------------------+---------------------------+-------------------------------+
| ``std::vector<T>`` | STL dynamic array | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::deque<T>`` | STL double-ended queue | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::valarray<T>`` | STL value array | :file:`pybind11/stl.h` |
+------------------------------------+---------------------------+-------------------------------+
| ``std::list<T>`` | STL linked list | :file:`pybind11/stl.h` |
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/cast/stl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Automatic conversion
====================

When including the additional header file :file:`pybind11/stl.h`, conversions
between ``std::vector<>``/``std::list<>``/``std::array<>``,
between ``std::vector<>``/``std::deque<>``/``std::list<>``/``std::array<>``,
``std::set<>``/``std::unordered_set<>``, and
``std::map<>``/``std::unordered_map<>`` and the Python ``list``, ``set`` and
``dict`` data structures are automatically enabled. The types ``std::pair<>``
Expand Down
4 changes: 3 additions & 1 deletion docs/advanced/cast/strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ Passing bytes to C++
--------------------

A Python ``bytes`` object will be passed to C++ functions that accept
``std::string`` or ``char*`` *without* conversion.
``std::string`` or ``char*`` *without* conversion. On Python 3, in order to
make a function *only* accept ``bytes`` (and not ``str``), declare it as taking
a ``py::bytes`` argument.


Returning C++ strings to Python
Expand Down
24 changes: 22 additions & 2 deletions docs/advanced/pycpp/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ simply using ``vectorize``).
namespace py = pybind11;
py::array_t<double> add_arrays(py::array_t<double> input1, py::array_t<double> input2) {
auto buf1 = input1.request(), buf2 = input2.request();
py::buffer_info buf1 = input1.request(), buf2 = input2.request();
if (buf1.ndim != 1 || buf2.ndim != 1)
throw std::runtime_error("Number of dimensions must be one");
Expand All @@ -272,7 +272,7 @@ simply using ``vectorize``).
/* No pointer is passed, so NumPy will allocate the buffer */
auto result = py::array_t<double>(buf1.size);
auto buf3 = result.request();
py::buffer_info buf3 = result.request();
double *ptr1 = (double *) buf1.ptr,
*ptr2 = (double *) buf2.ptr,
Expand Down Expand Up @@ -364,3 +364,23 @@ uses of ``py::array``:

The file :file:`tests/test_numpy_array.cpp` contains additional examples
demonstrating the use of this feature.

Ellipsis
========

Python 3 provides a convenient ``...`` ellipsis notation that is often used to
slice multidimensional arrays. For instance, the following snippet extracts the
middle dimensions of a tensor with the first and last index set to zero.

.. code-block:: python
a = # a NumPy array
b = a[0, ..., 0]
The function ``py::ellipsis()`` function can be used to perform the same
operation on the C++ side:

.. code-block:: cpp
py::array a = /* A NumPy array */;
py::array b = a[py::make_tuple(0, py::ellipsis(), 0)];
77 changes: 75 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,84 @@ v2.3.0 (Not yet released)
for non-MSVC compilers).
`#934 <https://github.com/pybind/pybind11/pull/934>`_.

* Add basic support for tag-based static polymorphism, where classes
provide a method to returns the desired type of an instance.
`#1326 <https://github.com/pybind/pybind11/pull/1326>`_.

* Added support for write only properties.
`#1144 <https://github.com/pybind/pybind11/pull/1144>`_.

* The ``value()`` method of ``py::enum_`` now accepts an optional docstring
that will be shown in the documentation of the associated enumeration.
* Python type wrappers (``py::handle``, ``py::object``, etc.)
now support map Python's number protocol onto C++ arithmetic
operators such as ``operator+``, ``operator/=``, etc.
`#1511 <https://github.com/pybind/pybind11/pull/1511>`_.

* A number of improvements related to enumerations:

1. The ``enum_`` implementation was rewritten from scratch to reduce
code bloat. Rather than instantiating a full implementation for each
enumeration, most code is now contained in a generic base class.
`#1511 <https://github.com/pybind/pybind11/pull/1511>`_.

2. The ``value()`` method of ``py::enum_`` now accepts an optional
docstring that will be shown in the documentation of the associated
enumeration. `#1160 <https://github.com/pybind/pybind11/pull/1160>`_.

3. check for already existing enum value and throw an error if present.
`#1453 <https://github.com/pybind/pybind11/pull/1453>`_.

* added ``py::ellipsis()`` method for slicing of multidimensional NumPy arrays
`#1502 <https://github.com/pybind/pybind11/pull/1502>`_.

* ``pybind11_add_module()``: allow including Python as a ``SYSTEM`` include path.
`#1416 <https://github.com/pybind/pybind11/pull/1416>`_.

* ``pybind11/stl.h`` does not convert strings to ``vector<string>`` anymore.
`#1258 <https://github.com/pybind/pybind11/issues/1258>`_.

v2.2.4 (September 11, 2018)
-----------------------------------------------------

* Use new Python 3.7 Thread Specific Storage (TSS) implementation if available.
`#1454 <https://github.com/pybind/pybind11/pull/1454>`_,
`#1517 <https://github.com/pybind/pybind11/pull/1517>`_.

* Fixes for newer MSVC versions and C++17 mode.
`#1347 <https://github.com/pybind/pybind11/pull/1347>`_,
`#1462 <https://github.com/pybind/pybind11/pull/1462>`_.

* Propagate return value policies to type-specific casters
when casting STL containers.
`#1455 <https://github.com/pybind/pybind11/pull/1455>`_.

* Allow ostream-redirection of more than 1024 characters.
`#1479 <https://github.com/pybind/pybind11/pull/1479>`_.

* Set ``Py_DEBUG`` define when compiling against a debug Python build.
`#1438 <https://github.com/pybind/pybind11/pull/1438>`_.

* Untangle integer logic in number type caster to work for custom
types that may only be castable to a restricted set of builtin types.
`#1442 <https://github.com/pybind/pybind11/pull/1442>`_.

* CMake build system: Remember Python version in cache file.
`#1434 <https://github.com/pybind/pybind11/pull/1434>`_.

* Fix for custom smart pointers: use ``std::addressof`` to obtain holder
address instead of ``operator&``.
`#1435 <https://github.com/pybind/pybind11/pull/1435>`_.

* Properly report exceptions thrown during module initialization.
`#1362 <https://github.com/pybind/pybind11/pull/1362>`_.

* Fixed a segmentation fault when creating empty-shaped NumPy array.
`#1371 <https://github.com/pybind/pybind11/pull/1371>`_.

* The version of Intel C++ compiler must be >= 2017, and this is now checked by
the header files. `#1363 <https://github.com/pybind/pybind11/pull/1363>`_.

* A few minor typo fixes and improvements to the test suite, and
patches that silence compiler warnings.

v2.2.3 (April 29, 2018)
-----------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function with the following signature:
.. code-block:: cmake
pybind11_add_module(<name> [MODULE | SHARED] [EXCLUDE_FROM_ALL]
[NO_EXTRAS] [THIN_LTO] source1 [source2 ...])
[NO_EXTRAS] [SYSTEM] [THIN_LTO] source1 [source2 ...])
This function behaves very much like CMake's builtin ``add_library`` (in fact,
it's a wrapper function around that command). It will add a library target
Expand All @@ -86,6 +86,10 @@ latter optimizations are never applied in ``Debug`` mode. If ``NO_EXTRAS`` is
given, they will always be disabled, even in ``Release`` mode. However, this
will result in code bloat and is generally not recommended.

By default, pybind11 and Python headers will be included with ``-I``. In order
to include pybind11 as system library, e.g. to avoid warnings in downstream
code with warn-levels outside of pybind11's scope, set the option ``SYSTEM``.

As stated above, LTO is enabled by default. Some newer compilers also support
different flavors of LTO such as `ThinLTO`_. Setting ``THIN_LTO`` will cause
the function to prefer this flavor if available. The function falls back to
Expand Down
44 changes: 40 additions & 4 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ Frequently asked questions
"ImportError: dynamic module does not define init function"
===========================================================

You are likely using an incompatible version of Python (for instance, the
extension library was compiled against Python 2, while the interpreter is
running on top of some version of Python 3, or vice versa).
1. Make sure that the name specified in PYBIND11_MODULE is identical to the
filename of the extension library (without prefixes such as .so)

2. If the above did not fix the issue, you are likely using an incompatible
version of Python (for instance, the extension library was compiled against
Python 2, while the interpreter is running on top of some version of Python
3, or vice versa).

"Symbol not found: ``__Py_ZeroStruct`` / ``_PyInstanceMethod_Type``"
========================================================================
Expand Down Expand Up @@ -242,6 +246,39 @@ that that were ``malloc()``-ed in another shared library, using data
structures with incompatible ABIs, and so on. pybind11 is very careful not
to make these types of mistakes.

Inconsistent detection of Python version in CMake and pybind11
==============================================================

The functions ``find_package(PythonInterp)`` and ``find_package(PythonLibs)`` provided by CMake
for Python version detection are not used by pybind11 due to unreliability and limitations that make
them unsuitable for pybind11's needs. Instead pybind provides its own, more reliable Python detection
CMake code. Conflicts can arise, however, when using pybind11 in a project that *also* uses the CMake
Python detection in a system with several Python versions installed.

This difference may cause inconsistencies and errors if *both* mechanisms are used in the same project. Consider the following
Cmake code executed in a system with Python 2.7 and 3.x installed:

.. code-block:: cmake
find_package(PythonInterp)
find_package(PythonLibs)
find_package(pybind11)
It will detect Python 2.7 and pybind11 will pick it as well.

In contrast this code:

.. code-block:: cmake
find_package(pybind11)
find_package(PythonInterp)
find_package(PythonLibs)
will detect Python 3.x for pybind11 and may crash on ``find_package(PythonLibs)`` afterwards.

It is advised to avoid using ``find_package(PythonInterp)`` and ``find_package(PythonLibs)`` from CMake and rely
on pybind11 in detecting Python version. If this is not possible CMake machinery should be called *before* including pybind11.

How to cite this project?
=========================

Expand All @@ -256,4 +293,3 @@ discourse:
note = {https://github.com/pybind/pybind11},
title = {pybind11 -- Seamless operability between C++11 and Python}
}
1 change: 0 additions & 1 deletion docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ The following core C++ features can be mapped to Python
- Custom operators
- Single and multiple inheritance
- STL data structures
- Iterators and ranges
- Smart pointers with reference counting like ``std::shared_ptr``
- Internal references with correct reference counting
- C++ classes with virtual (and pure virtual) methods can be extended in Python
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Redirecting C++ streams

.. doxygenfunction:: add_ostream_redirect

Python build-in functions
Python built-in functions
=========================

.. doxygengroup:: python_builtins
Expand Down
7 changes: 5 additions & 2 deletions include/pybind11/attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,14 @@ struct type_record {
/// How large is the underlying C++ type?
size_t type_size = 0;

/// What is the alignment of the underlying C++ type?
size_t type_align = 0;

/// How large is the type's holder?
size_t holder_size = 0;

/// The global operator new can be overridden with a class-specific variant
void *(*operator_new)(size_t) = ::operator new;
void *(*operator_new)(size_t) = nullptr;

/// Function pointer to class_<..>::init_instance
void (*init_instance)(instance *, holder_erased) = nullptr;
Expand Down Expand Up @@ -281,7 +284,7 @@ struct type_record {
}
};

inline function_call::function_call(function_record &f, handle p) :
inline function_call::function_call(const function_record &f, handle p) :
func(f), parent(p) {
args.reserve(f.nargs);
args_convert.reserve(f.nargs);
Expand Down
Loading

0 comments on commit 25731f6

Please sign in to comment.