Commit Graph

2552 Commits

Author SHA1 Message Date
Jason Rhinelander
16c86638a5 Remove object::borrowed/stolen
PR #771 deprecated them as they can cause linking failures (#770), but
the deprecation tags cause warnings on GCC 5.x through 6.2.x.  Removing
them entirely will break backwards-compatibility consequences, but the
effects should be minimal (only code that was inheriting from `object`
could get at them at all as they are protected).

Fixes #777
2017-04-06 18:31:21 -04:00
Dean Moldovan
555dc4f07a Fix test_cmake_build failure with bare python exe name (fix #783)
Besides appearing in the CMake GUI, the `:FILENAME` specifier changes
behavior as well:

cmake -DPYTHON_EXECUTABLE=python ..  # FAIL, can't find python
cmake -DPYTHON_EXECUTABLE=/path/to/python ..  # OK
cmake -DPYTHON_EXECUTABLE:FILENAME=python ..  # OK
cmake -DPYTHON_EXECUTABLE:FILENAME=/path/to/python ..  # OK
2017-04-06 22:41:32 +02:00
Jason Rhinelander
087b8d84e9 Skip VS2015/x86 builds
AppVeyor just added support for excluding specific jobs; thhis commit
cuts the number of builds down to 6 from 8 by eliminating the VS2015 x86
builds.
2017-04-05 20:17:25 -04:00
Ivan Smirnov
7348c407f6 Fix -Wmissing-braces warning 2017-04-05 18:03:08 -04:00
Jason Rhinelander
6906b270d6 Improve make_tuple error message under debugging
When make_tuple fails (for example, when print() is called with a
non-convertible argument, as in #778) the error message a less helpful
than it could be:

    make_tuple(): unable to convert arguments of types 'std::tuple<type1, type2>' to Python object

There is no actual std::tuple involved (only a parameter pack and a
Python tuple), but it also doesn't immediately reveal which type caused
the problem.

This commit changes the debugging mode output to show just the
problematic type:

    make_tuple(): unable to convert argument of type 'type2' to Python object
2017-04-05 11:43:05 -04:00
Wenzel Jakob
8f010cce8e AppVeyor: use parallel builds
My group now has a subscription to AppVeyor pro, which also permits
running parallel builds on the open source projects.
2017-04-05 17:02:37 +02:00
Dean Moldovan
82ece940fb Replace first_of_t with exactly_one_t 2017-04-03 00:52:47 +02:00
Dean Moldovan
1ac19036d6 Add a scope guard call policy
```c++
m.def("foo", foo, py::call_guard<T>());
```

is equivalent to:

```c++
m.def("foo", [](args...) {
    T scope_guard;
    return foo(args...); // forwarded arguments
});
```
2017-04-03 00:52:47 +02:00
Roman Miroshnychenko
83a8a977a7 Add a method to check Python exception types (#772)
This commit adds `error_already_set::matches()` convenience method to
check if the exception trapped by `error_already_set` matches a given
Python exception type. This will address #700 by providing a less
verbose way to check exceptions.
2017-04-02 22:38:50 +02:00
Sylvain Corlay
37ef74c584 Wrong msvc version 2017-04-01 16:23:45 -04:00
Wenzel Jakob
280470d80c updated cindex.py submodule to latest version 2017-03-30 13:14:33 +02:00
Wenzel Jakob
aa1b316f6f adjusted module::add_object signature so that it accepts a py::handle 2017-03-30 12:03:48 +02:00
Dean Moldovan
194d8b99b3 Support raw string literals as input for py::eval (#766)
* Support raw string literals as input for py::eval
* Dedent only when needed
2017-03-29 00:27:56 +02:00
Jason Rhinelander
6db60cd945 Deprecated borrowed/stolen for borrowed_t{}/stolen_t{} (#771)
The constexpr static instances can cause linking failures if the
compiler doesn't optimize away the reference, as reported in #770.

There's no particularly nice way of fixing this in C++11/14: we can't
inline definitions to match the declaration aren't permitted for
non-templated static variables (C++17 *does* allows "inline" on
variables, but that obviously doesn't help us.)

One solution that could work around it is to add an extra inherited
subclass to `object`'s hierarchy, but that's a bit of a messy solution
and was decided against in #771 in favour of just deprecating (and
eventually dropping) the constexpr statics.

Fixes #770.
2017-03-29 00:23:37 +02:00
Jason Rhinelander
d6fdafb203 Fix unchecked type caster template Dim type 2017-03-26 12:43:22 -03:00
Ghislain Antony Vaillant
5b50376490 Arch-indep CMake packaging (#764)
* Arch-indep CMake packaging

Since pybind11 is a header-only library, the CMake packaging does not have to carry any architecture specific checks. Without this patch, the detection of pybind11 will fail on 32-bit architectures if the project was built on a 64-bit machine and vice-versa. This fix is similar to what is applied to `Eigen` and other header-only C++ libraries.
2017-03-24 23:09:38 +01:00
Wenzel Jakob
0d92938f74 minor style fix 2017-03-22 22:52:29 +01:00
Wenzel Jakob
d405b1b3a4 updated version information for v2.2 development 2017-03-22 22:20:07 +01:00
Dean Moldovan
f0e58a69d3 Fix compilation with clang 4.0 in -std=c++1z mode 2017-03-22 22:08:47 +01:00
Wenzel Jakob
62e5fef09e Changelog for v2.1.0 (#759) 2017-03-22 22:07:45 +01:00
Wenzel Jakob
b16421edb1 Nicer API to pass py::capsule destructor (#752)
* nicer py::capsule destructor mechanism
* added destructor-only version of capsule & tests
* added documentation for module destructors (fixes #733)
2017-03-22 22:04:00 +01:00
Wenzel Jakob
ab26259c87 added note about trailing commas (fixes #593) 2017-03-22 21:39:19 +01:00
Jason Rhinelander
ed8a461d9a Change pypy travis-ci PyPy build to 5.7 release
We no longer need a nightly build now that 5.7 is released (and the
current nightly 5.8 is failing).
2017-03-22 17:07:55 -03:00
Jason Rhinelander
773339f131 array-unchecked: add runtime dimension support and array-compatible methods
The extends the previous unchecked support with the ability to
determine the dimensions at runtime.  This incurs a small performance
hit when used (versus the compile-time fixed alternative), but is still considerably
faster than the full checks on every call that happen with
`.at()`/`.mutable_at()`.
2017-03-22 16:15:56 -03:00
Jason Rhinelander
423a49b8be array: add unchecked access via proxy object
This adds bounds-unchecked access to arrays through a `a.unchecked<Type,
Dimensions>()` method.  (For `array_t<T>`, the `Type` template parameter
is omitted).  The mutable version (which requires the array have the
`writeable` flag) is available as `a.mutable_unchecked<...>()`.

Specifying the Dimensions as a template parameter allows storage of an
std::array; having the strides and sizes stored that way (as opposed to
storing a copy of the array's strides/shape pointers) allows the
compiler to make significant optimizations of the shape() method that it
can't make with a pointer; testing with nested loops of the form:

    for (size_t i0 = 0; i0 < r.shape(0); i0++)
        for (size_t i1 = 0; i1 < r.shape(1); i1++)
            ...
                r(i0, i1, ...) += 1;

over a 10 million element array gives around a 25% speedup (versus using
a pointer) for the 1D case, 33% for 2D, and runs more than twice as fast
with a 5D array.
2017-03-22 16:13:59 -03:00
Dean Moldovan
0d765f4a7c Support class-specific operator new and delete
Fixes #754.
2017-03-22 19:28:04 +01:00
Jason Rhinelander
b0292c1df3 vectorize: trivial handling for F-order arrays
This extends the trivial handling to support trivial handling for
Fortran-order arrays (i.e. column major): if inputs aren't all
C-contiguous, but *are* all F-contiguous, the resulting array will be
F-contiguous and we can do trivial processing.

For anything else (e.g. C-contiguous, or inputs requiring non-trivial
processing), the result is in (numpy-default) C-contiguous layout.
2017-03-21 18:53:56 -03:00
Jason Rhinelander
ae5a8f7eb3 Stop forcing c-contiguous in py::vectorize
The only part of the vectorize code that actually needs c-contiguous is
the "trivial" broadcast; for non-trivial arguments, the code already
uses strides properly (and so handles C-style, F-style, neither, slices,
etc.)

This commit rewrites `broadcast` to additionally check for C-contiguous
storage, then takes off the `c_style` flag for the arguments, which
will keep the functionality more or less the same, except for no longer
requiring an array copy for non-c-contiguous input arrays.

Additionally, if we're given a singleton slice (e.g. a[0::4, 0::4] for a
4x4 or smaller array), we no longer fail triviality because the trivial
code path never actually uses the strides on a singleton.
2017-03-21 18:53:56 -03:00
Dean Moldovan
cd3d1fc7df Throw an exception when attempting to load an incompatible holder
Instead of a segfault. Fixes #751.

This covers the case of loading a custom holder from a default-holder
instance. Attempting to load one custom holder from a different custom
holder (i.e. not `std::unique_ptr`) yields undefined behavior, just as
#588 established for inheritance.
2017-03-21 10:26:22 +01:00
Jason Rhinelander
0f5ec0a87e Error message wording tweak
py::arg() doesn't only specify named arguments anymore, so the error
message was misleading (e.g. when using `py::arg().noconvert()` and
forgetting `py::arg()` for a second positional argument).
2017-03-19 12:36:18 -03:00
Jason Rhinelander
5a9247872d Added minimum compiler version assertions
We now require (and enforce at compile time):
- GCC 4.8+
- clang 3.3+ (5.0+ for Apple's renumbered clang)
- MSVC 2015u3+
- ICC 15+

This also updates the versions listed in the README, and removes a
now-redundant MSVC version check.
2017-03-19 01:34:16 -03:00
Jason Rhinelander
3d591e8f2f Document make_iterator/make_key_iterator
This adds brief API documentation for make_iterator/make_key_iterator,
specifically mentioning that it requires InputIterators.

Closes #734.

[skip ci] (no code change here)
2017-03-18 13:38:08 -03:00
Jason Rhinelander
b961626c0c Fail to compile with MI via class_ ctor parameters
We can't support this for classes from imported modules (which is the
primary purpose of a ctor argument base class) because we *have* to
have both parent and derived to properly extract a multiple-inheritance
base class pointer from a derived class pointer.

We could support this for actual `class_<Base, ...> instances, but since
in that case the `Base` is already present in the code, it seems more
consistent to simply always require MI to go via template options.
2017-03-17 15:35:34 -03:00
Jason Rhinelander
d51acb6873 Use C++17 fold expression macro
This puts the fold expressions behind the feature macro instead of a
general C++17 macro.

It also adds a fold expression optimization to constexpr_sum (guarded
by the same feature macro).
2017-03-17 15:32:33 -03:00
Jason Rhinelander
efa8726ff7 Eigen: don't require conformability on length-1 dimensions
Fixes #738

The current check for conformability fails when given a 2D, 1xN or Nx1
input to a row-major or column-major, respectively, Eigen::Ref, leading
to a copy-required state in the type_caster, but this later failed
because the copy was also non-conformable because it had the same shape
and strides (because a 1xN or Nx1 is both F and C contiguous).

In such cases we can safely ignore the stride on the "1" dimension since
it'll never be used: only the "N" dimension stride needs to match the
Eigen::Ref stride, which both fixes the non-conformable copy problem,
but also avoids a copy entirely as long as the "N" dimension has a
compatible stride.
2017-03-17 15:32:18 -03:00
Jean-Michaël Celerier
68e089a8bf Use custom definitions for negation and bool_constant (#737)
Instead of relying on sometimes missing C++17 definitions
2017-03-17 14:51:41 +01:00
Jason Rhinelander
cabbf610a7 Add VS 2017 build, and bump conda to 3.6
This adds VS 2017 to the build matrix, plus various other small
appveyor build changes:

- conda version bumped from 3.5 to 3.6
- build newer versions/architectures/python first (i.e. VS2017/x64/3.6
  is the first build, VS2015/x86/2.7 is the last)
- stop building after a job failure: often a build failure in one
  occurs everywhere; this just stops processing jobs (freeing them up
  for other PRs) if an error is hit.

Annoyingly, appveyor doesn't allow excluding tests: i.e. the test matrix
is always dense (appveyor issue 386), so for now we'll just run
everything.  (Once appveyor issue 386 is resolved, we can come back and
cut this down to 4-5 builds).
2017-03-17 14:47:51 +01:00
Dean Moldovan
819cb5533e Fix nullptr to None conversion for builtin type casters
Fixes #731.

Generally, this applies to any caster made with PYBIND11_TYPE_CASTER().
2017-03-16 13:57:35 +01:00
Wenzel Jakob
dfd89a6081 remove all pybind11 namespace prefixes from stl_bind.h 2017-03-16 11:44:01 +01:00
Dean Moldovan
1769ea427f Add __module__ attribute to all pybind11 builtin types (#729)
Fixes #728.
2017-03-15 15:38:14 +01:00
Wenzel Jakob
9f383a542e added @patstew to README.md 2017-03-14 02:51:09 +01:00
Patrick Stewart
0b6d08a008 Add function for comparing buffer_info formats to types
Allows equivalent integral types and numpy dtypes
2017-03-14 02:50:04 +01:00
Patrick Stewart
5467979588 Add the buffer interface for wrapped STL vectors
Allows use of vectors as python buffers, so for example they can be adopted without a copy by numpy.asarray
Allows faster conversion of buffers to vectors by copying instead of individually casting the elements
2017-03-14 02:50:04 +01:00
Dean Moldovan
16afbcef46 Improve py::array_t scalar type information (#724)
* Add value_type member alias to py::array_t (resolve #632)

* Use numpy scalar name in py::array_t function signatures (e.g. float32/64 instead of just float)
2017-03-13 19:17:18 +01:00
Jason Rhinelander
dc5ce5930f Use move assignment for eigen ref copy
This won't affect much, but makes the code consistent with the
non-copying branch.
2017-03-13 12:49:10 -03:00
Jason Rhinelander
139a082b0e Add static_assert failure for non-static def_static
Fixes #697
2017-03-12 21:32:37 -03:00
Jason Rhinelander
2d965d43a6 Add MSVC 2017 cpp_function ICE workaround
The `decltype(...)` in the template parameter that gives us SFINAE
matching for a lambda makes MSVC 2017 ICE; this works around if by
changing the test to an explicit not-a-function-or-pointer test, which
seems to work everywhere.
2017-03-12 20:02:58 -03:00
Dean Moldovan
b7017c3dad Fix readthedocs build (#721)
RTD updated their build environment which broke the 1.8.14.dev build of
doxygen that we were using. The update also breaks the conda-forge build
of 1.8.13 (but that version has other issues).

Luckily, the RTD update did bring their doxygen version up to 1.8.11
which is enough to parse the C++11 code we need (ref qualifiers) and it
also avoids the segfault found in 1.8.13.

Since we're using the native doxygen, conda isn't required anymore and
we can simplify the RTD configuration.

[skip ci]
2017-03-12 22:36:48 +01:00
Jason Rhinelander
ee9296395d Call PyUnicode_DecodeUTF* directly
Some versions of Python 2.7 reportedly (#713) have issues with
PyUnicode_Decode being passed the encoding string, so just skip it
entirely by calling the PyUnicode_DecodeUTF* function directly.  This
will also be slightly more efficient by avoiding having to check the
encoding string, and (for python 2) going through the unicode class's
decode (python 3 fast-tracks this for all utf-{8,16,32} encodings;
python 2 only fast-tracked for the exact string "utf-8", which we
weren't passing anyway (we had "utf8")).

This doesn't work for PyPy, however: its `PyUnicode_DecodeUTF{8,16,32}`
appear rather broken: the UTF8 one segfaults, while the 16/32 require
recasting into a non-const `char *` (and might segfault; I didn't get
far enough to find out).  Just avoid the whole thing by keeping the
encoding-passed-as-string version for PyPy, which seems to work
reliably.
2017-03-12 00:17:51 -04:00
Jason Rhinelander
e5456c2226 Fix for floating point durations
The duration calculation was using %, but that's only supported on
duration objects when the arithmetic type supports %, and hence fails
for floats.  Fixed by subtracting off the calculated values instead.
2017-03-11 23:04:16 -04:00