Commit Graph

1457 Commits

Author SHA1 Message Date
Jason Rhinelander
7672292e6b Add informative compilation failure for method_adaptor failures
When using `method_adaptor` (usually implicitly via a `cl.def("f",
&D::f)`) a compilation failure results if `f` is actually a method of
an inaccessible base class made public via `using`, such as:

    class B { public: void f() {} };
    class D : private B { public: using B::f; };

pybind deduces `&D::f` as a `B` member function pointer.  Since the base
class is inaccessible, the cast in `method_adaptor` from a base class
member function pointer to derived class member function pointer isn't
valid, and a cast failure results.

This was sort of a regression in 2.2, which introduced `method_adaptor`
to do the expected thing when the base class *is* accessible.  It wasn't
actually something that *worked* in 2.1, though: you wouldn't get a
compile-time failure, but the method was not callable (because the `D *`
couldn't be cast to a `B *` because of the access restriction).  As a
result, you'd simply get a run-time failure if you ever tried to call
the function (this is what #855 fixed).

Thus the change in 2.2 essentially promoted a run-time failure to a
compile-time failure, so isn't really a regression.

This commit simply adds a `static_assert` with an accessible-base-class
check so that, rather than just a cryptic cast failure, you get
something more informative (along with a suggestion for a workaround).

The workaround is to use a lambda, e.g.:

    class Derived : private Base {
    public:
        using Base::f;
    };

    // In binding code:
    //cl.def("f", &Derived::f); // fails: &Derived::f is actually a base
                                // class member function pointer
    cl.def("f", [](Derived &self) { return self.f(); });

This is a bit of a nuissance (especially if there are a bunch of
arguments to forward), but I don't really see another solution.

Fixes #1124
2017-10-12 09:45:07 -04:00
Jason Rhinelander
1b08df5872 Fix char & arguments being non-bindable
This changes the caster to return a reference to a (new) local `CharT`
type caster member so that binding lvalue-reference char arguments
works (currently it results in a compilation failure).

Fixes #1116
2017-10-12 09:41:54 -04:00
Henry Schreiner
04b41f0304 Upgrading to Xcode 9 & fix OSX/Py3 build failure
* Upgrades to latest stable Xcode (9)

* Fixes build error in the OS X/Python 3 build.
2017-10-09 22:47:02 -04:00
Bruce Merry
1e6172d405 Fix some minor mistakes in comments on struct instance 2017-10-08 07:03:52 -04:00
Jason Rhinelander
64a99b92fe Specify minimum needed cmake version in test suite
Fixes #1117
2017-09-28 08:04:34 -03:00
Ansgar Burchardt
a22dd2d1df correct stride in matrix example and test
This also matches the Eigen example for the row-major case.

This also enhances one of the tests to trigger a failure (and fixes it in the PR).  (This isn't really a flaw in pybind itself, but rather fixes wrong code in the test code and docs).
2017-09-21 18:07:48 -03:00
Jason Rhinelander
d2757d0440 Remove superfluous "requires_numpy"
The entire test file is already marked as requiring numpy; it isn't
needed on the individual test.
2017-09-19 23:17:21 -03:00
Jason Rhinelander
c6a57c10d1 Fix dtype string leak
`PyArray_DescrConverter_` doesn't steal a reference to the argument,
and so the passed arguments shouldn't be `.release()`d.
2017-09-19 23:16:45 -03:00
Dean Moldovan
0aef6422a3 Simplify function signature annotation and parsing
`type_descr` is now applied only to the final signature so that it only
marks the argument types, but not nested types (e.g. for tuples) or
return types.
2017-09-16 12:02:49 +02:00
Dean Moldovan
56613945ae Use semi-constexpr signatures on MSVC
MSCV does not allow `&typeid(T)` in constexpr contexts, but the string
part of the type signature can still be constexpr. In order to avoid
`typeid` as long as possible, `descr` is modified to collect type
information as template parameters instead of constexpr `typeid`.
The actual `std::type_info` pointers are only collected in the end,
as a `constexpr` (gcc/clang) or regular (MSVC) function call.

Not only does it significantly reduce binary size on MSVC, gcc/clang
benefit a little bit as well, since they can skip some intermediate
`std::type_info*` arrays.
2017-09-16 12:02:49 +02:00
Dean Moldovan
c10ac6cf1f Make it possible to generate constexpr signatures in C++11 mode
The current C++14 constexpr signatures don't require relaxed constexpr,
but only `auto` return type deduction. To get around this in C++11,
the type caster's `name()` static member functions are turned into
`static constexpr auto` variables.
2017-09-16 12:02:49 +02:00
Wenzel Jakob
f94d759881 updated changelog for v2.2.1 release 2017-09-14 08:51:30 +02:00
Dean Moldovan
1caeb8d789 Fix Travis style/docs/pip build
When Travis changes their default Python 3.x, it breaks any hardcoded
version selection. Fix: make pyenv activate everything (2.7, 3.x) and
use whichever Python 3.x is on by default.

[skip appveyor]
2017-09-13 22:32:29 +02:00
Dean Moldovan
27680302dd Update changelog for v2.2.1 release 2017-09-13 19:04:25 +02:00
tzh1043
d81d11a61c Make PYBIND11_MODULE name usable with define (#1082) 2017-09-13 19:02:53 +02:00
jbarlow83
9f82370e48 docs: Describe importing Python modules and Python methods (#1079)
* Expand documentation to include explicit example of py::module::import 
  where one would expect it.

* Describe how to use unbound and bound methods to class Python classes.

[skip ci]
2017-09-13 16:18:08 +02:00
Dean Moldovan
2b4477eb65 Make TypeErrors more informative when an optional header is missing
E.g. trying to convert a `list` to a `std::vector<int>` without
including <pybind11/stl.h> will now raise an error with a note that
suggests checking the headers.

The note is only appended if `std::` is found in the function
signature. This should only be the case when a header is missing.
E.g. when stl.h is included, the signature would contain `List[int]`
instead of `std::vector<int>` while using stl_bind.h would produce
something like `MyVector`. Similarly for `std::map`/`Dict`, `complex`,
`std::function`/`Callable`, etc.

There's a possibility for false positives, but it's pretty low.
2017-09-12 08:06:46 +02:00
Gunnar Läthén
c64e6b1670 Added function for reloading module (#1040) 2017-09-12 08:05:05 +02:00
Dean Moldovan
2cf87a54d8 Fix implicit conversion of accessors to types derived from py::object
Fixes #1069.
2017-09-11 10:09:32 +02:00
Dean Moldovan
953d2422b3 Fix a reference leak in the number converter (#1078)
Fixes #1075.

`PyNumber_Float()` and `PyNumber_Long()` return new references.
2017-09-10 16:53:02 +02:00
Dean Moldovan
7b1de1e551 Fix nullptr dereference when loading an external-only module_local type 2017-09-10 12:28:03 +02:00
Dean Moldovan
3c4933cb50 Fix STL casters for containers with proxies (regression)
To avoid an ODR violation in the test suite while testing
both `stl.h` and `std_bind.h` with `std::vector<bool>`,
the `py::bind_vector<std::vector<bool>>` test is moved to
the secondary module (which does not include `stl.h`).
2017-09-10 12:25:10 +02:00
Henry Schreiner
43126201a6 Fix style script and add comment to failing blocks (#1045)
[skip appveyor]
2017-09-10 12:24:33 +02:00
Dean Moldovan
2d49aee4c5 Remove unused value assignment 2017-09-08 13:44:55 +02:00
Dean Moldovan
b0a0e4a23c Fix compilation with Clang on host GCC < 5 (old libstdc++) 2017-09-08 12:48:14 +02:00
Dean Moldovan
cdf38dc6ba Move the style check/barebones config up to the first position on Travis
This runs the most basic tests first and avoids waiting until the very
end for style checks.

[skip appveyor]
2017-09-08 12:13:42 +02:00
Dean Moldovan
b7c98d21e1 Speed up Travis CI build (#1056)
* Update Python 3 osx image to xcode8.3 to speed up brew install. 
  The Python 2 osx image remains xcode7.3.

* Have one osx config run in debug mode to improve coverage.

* Only run CMake build tests on two configs to speed up overall build.

  The CMake tests take ~30 seconds on each configuration, but we really 
  only need to them to run on two: one on Linux and one on macOS. This
  mirrors the recent change on AppVeyor.

* Merge the style/docs/pip tests with the barebones build.

* Merge 32-bit and CMake install configurations.

  This removes clang 3.9 from testing, but there are already 3 other clang 
  versions being tested on Travis and the new xcode8.3 image should be 
  close to clang 3.9.

[skip appveyor]
2017-09-08 10:59:50 +02:00
Dean Moldovan
0991d7fba1 Remove deprecated placement-new constructor from docs
[skip ci]
2017-09-07 15:02:16 +02:00
Dean Moldovan
a80af9557d Add a dummy common.h header with a deprecation warning 2017-09-06 15:22:26 +02:00
Dean Moldovan
00b8f3655d Relax py::pickle() get/set type check
Fixes #1061.

`T` and `const T &` are compatible types.
2017-09-06 15:20:52 +02:00
Dean Moldovan
7939f4b3fe Fix application of keep_alive policy to constructors (regression) 2017-09-06 10:21:11 +02:00
Marcin Wojdyr
fbab29c73a remove extra ';' [-Wpedantic] 2017-09-05 16:00:34 -04:00
Dean Moldovan
91b42c8174 Add upgrade guide entry about stricter compile-time checks
Closes #1048, closes #1052.

[skip ci]
2017-09-04 23:01:34 +02:00
Patrik Huber
1ad2227d3c Fixed typo in docs
[skip ci]
2017-09-04 23:00:19 +02:00
Bruce Merry
b490b44e34 Update documentation for keep_alive to match new implementation
PR #880 changed the implementation of keep_alive to avoid weak
references when the nurse is pybind11-registered, but the documentation
didn't get updated to match.
2017-09-01 21:38:16 +02:00
Wenzel Jakob
2fb4e9532e fix release.rst instructions for conda-forge SHA checksum
[skip ci]
2017-08-31 23:05:47 +02:00
Wenzel Jakob
8cf091a41f updated version flags for next version 2017-08-31 14:01:08 +02:00
Wenzel Jakob
2a5a5ec0a4 updated changelog.rst with release date 2017-08-31 13:58:24 +02:00
Wenzel Jakob
def3c18c65 updated variables for v2.2.0 release 2017-08-31 13:56:57 +02:00
Dean Moldovan
6898679270 Update enum_ and bind_vector to new-style init and pickle
Fixes #1046.
2017-08-31 01:28:07 +02:00
Dean Moldovan
4c5404421f Update changelog and upgrade guide
[skip ci]
2017-08-30 22:48:39 +02:00
Ivan Smirnov
5cbfda5b68 Update build commands for Linux / OS X in the docs (#907) 2017-08-30 21:58:43 +02:00
Bruce Merry
37de2da9dd Access C++ hash functions from Python and vice versa (#1034)
There are two separate additions:

1. `py::hash(obj)` is equivalent to the Python `hash(obj)`.
2. `.def(hash(py::self))` registers the hash function defined by
   `std::hash<T>` as the Python hash function.
2017-08-30 14:22:00 +02:00
Florian Apolloner
29b99a11a4 Specify CXX as project language for CMake >= 3.4 (#1027) 2017-08-30 14:17:54 +02:00
Dean Moldovan
b8c5dbdef5 Show a deprecation warning for old-style __init__ and __setstate__
The warning is shown at module initialization time (on import, not
when the functions are called). It's only visible when compiled in
debug mode.
2017-08-30 11:11:38 +02:00
Dean Moldovan
1e5a7da30d Add py::pickle() adaptor for safer __getstate__/__setstate__ bindings
This is analogous to `py::init()` vs `__init__` + placement-new.
`py::pickle()` reuses most of the implementation details of `py::init()`.
2017-08-30 11:11:38 +02:00
Wenzel Jakob
a1041190c8 mention PR #1037 in changelog 2017-08-28 16:35:32 +02:00
Wenzel Jakob
8ed5b8ab55 make implicit conversions non-reentrant (fixes #1035) (#1037) 2017-08-28 16:34:06 +02:00
Dean Moldovan
15f36d2b2d Simplify py::init() type deduction and error checking 2017-08-28 16:08:53 +02:00
Dean Moldovan
39fd6a9463 Reduce binary size overhead of new-style constructors
The lookup of the `self` type and value pointer are moved out of
template code and into `dispatcher`. This brings down the binary
size of constructors back to the level of the old placement-new
approach. (It also avoids a second lookup for `init_instance`.)

With this implementation, mixing old- and new-style constructors
in the same overload set may result in some runtime overhead for
temporary allocations/deallocations, but this should be fine as
old style constructors are phased out.
2017-08-28 16:08:53 +02:00