Commit Graph

1049 Commits

Author SHA1 Message Date
Yung-Yu Chen
c40d8c617f Fix segfault when repr() with pybind11 type with metaclass (#571)
* Fixed a regression that was introduced in the PyPy patch: use ht_qualname_meta instead of ht_qualname to fix PyHeapTypeObject->ht_qualname field.

* Added a qualname/repr test that works in both Python 3.3+ and previous versions
2016-12-26 11:25:42 +01:00
Yung-Yu Chen
87f893b766 Temporarily allows osx homebrew Python 3.6 to fail (#572)
* Temporarily allows osx homebrew Python 3.6 to fail.

https://github.com/pybind/pybind11/pull/570#issuecomment-269120613

"Homebrew just got Python 3.6 (brew install python3), but numpy and scipy don't have binary wheels for 3.6 yet so it's trying to compile from source and failing."
2016-12-26 11:24:30 +01:00
Wenzel Jakob
3c79671112 a few more minor v2.0.0-rc1 related changes 2016-12-23 16:19:36 +01:00
Wenzel Jakob
d3549d6027 added changelog for v2.0.0-rc1 2016-12-23 16:01:19 +01:00
Jason Rhinelander
05920e363e Change compilation/test target back to check (#566) 2016-12-19 17:33:02 +01:00
Dean Moldovan
06b9397c72 Add 'check' target to run all available tests 2016-12-19 16:34:48 +01:00
Dean Moldovan
71e8a7962c Rename target from pybind11::pybind11 to pybind11::module
Makes room for an eventual pybind11::embedded target.
2016-12-19 16:34:48 +01:00
Dean Moldovan
0cbec5c96e Add new options and docs for pybind11_add_module
See the documentation for a description of the options.
2016-12-19 16:34:48 +01:00
Dean Moldovan
b0f3885c95 Make sure add_subdirectory and find_package behave identically
Add a BUILD_INTERFACE and a pybind11::pybind11 alias for the interface
library to match the installed target.

Add new cmake tests for add_subdirectory and consolidates the
.cpp and .py files needed for the cmake build tests:

Before:
tests
|-- test_installed_module
|   |-- CMakeLists.txt
|   |-- main.cpp
|   \-- test.py
\-- test_installed_target
    |-- CMakeLists.txt
    |-- main.cpp
    \-- test.py

After:
tests
\-- test_cmake_build
    |-- installed_module/CMakeLists.txt
    |-- installed_target/CMakeLists.txt
    |-- subdirectory_module/CMakeLists.txt
    |-- subdirectory_target/CMakeLists.txt
    |-- main.cpp
    \-- test.py
2016-12-19 16:34:48 +01:00
Wenzel Jakob
003a9eba59 fixed pypy minimum version 2016-12-18 17:08:13 +01:00
Wenzel Jakob
1d1f81b278 WIP: PyPy support (#527)
This commit includes modifications that are needed to get pybind11 to work with PyPy. The full test suite compiles and runs except for a last few functions that are commented out (due to problems in PyPy that were reported on the PyPy bugtracker).

Two somewhat intrusive changes were needed to make it possible: two new tags ``py::buffer_protocol()`` and ``py::metaclass()`` must now be specified to the ``class_`` constructor if the class uses the buffer protocol and/or requires a metaclass (e.g. for static properties).

Note that this is only for the PyPy version based on Python 2.7 for now. When the PyPy 3.x has caught up in terms of cpyext compliance, a PyPy 3.x patch will follow.
2016-12-16 15:00:46 +01:00
Lori A. Burns
c79e435e00 remove constexpr to help export void arg functions with Intel (#557) 2016-12-16 00:15:24 +01:00
Wenzel Jakob
2029171211 always_construct_holder feature to support intrusively reference-counted types (#561)
* always_construct_holder feature to support intrusively reference-counted types

* added testcase
2016-12-15 23:44:23 +01:00
Jason Rhinelander
709e648c57 Add temporary allow_failure for python 2.7/gcc 6 (#562)
Current debian testing has Python 2.7.13-RC1, which has a serious
regression (upstream https://bugs.python.org/issue5322) which should be
reverted for RC2 (or the final 2.7.13).  Ignore build failures for this
build test temporarily (with the intention of reverting this commit in a
couple of weeks once it stops failing, i.e. when debian testing picks up
an updated python 2.7 release).
2016-12-15 22:49:09 +01:00
Jason Rhinelander
6ae68fe301 Add simple any_of/all_of implementation for C++17 2016-12-14 20:42:36 +01:00
Jason Rhinelander
fa5d05e15d Change all_of_t/any_of_t to all_of/any_of, add none_of
This replaces the current `all_of_t<Pred, Ts...>` with `all_of<Ts...>`,
with previous use of `all_of_t<Pred, Ts...>` becoming
`all_of<Pred<Ts>...>` (and similarly for `any_of_t`).  It also adds a
`none_of<Ts...>`, a shortcut for `negation<any_of<Ts...>>`.

This allows `all_of` and `any_of` to be used a bit more flexible, e.g.
in cases where several predicates need to be tested for the same type
instead of the same predicate for multiple types.

This commit replaces the implementation with a more efficient version
for non-MSVC.  For MSVC, this changes the workaround to use the
built-in, recursive std::conjunction/std::disjunction instead.

This also removes the `count_t` since `any_of_t` and `all_of_t` were the
only things using it.

This commit also rearranges some of the future std imports to use actual
`std` implementations for C++14/17 features when under the appropriate
compiler mode, as we were already doing for a few things (like
index_sequence).  Most of these aren't saving much (the implementation
for enable_if_t, for example, is trivial), but I think it makes the
intention of the code instantly clear.  It also enables MSVC's native
std::index_sequence support.
2016-12-14 20:42:36 +01:00
Jason Rhinelander
b11b144603 Remove duplicate protected:/private: 2016-12-14 20:40:49 +01:00
Jason Rhinelander
a3d41d103c Add gcc-7 build from debian experimental
Add a build using g++-7 snapshot from debian experimental.  This build
is set to allow failures without triggering an overall build failure
(since this is an experimental compiler with experimental support for a
future C++ standard).
2016-12-14 20:40:49 +01:00
Jason Rhinelander
6e036e78a7 Support binding noexcept function/methods in C++17
When compiling in C++17 mode the noexcept specifier is part of the
function type.  This causes a failure in pybind11 because, by omitting
a noexcept specifier when deducing function return and argument types,
we are implicitly making `noexcept(false)` part of the type.

This means that functions with `noexcept` fail to match the function
templates in cpp_function (and other places), and we get compilation
failure (we end up trying to fit it into the lambda function version,
which fails since a function pointer has no `operator()`).

We can, however, deduce the true/false `B` in noexcept(B), so we don't
need to add a whole other set of overloads, but need to deduce the extra
argument when under C++17.  That will *not* work under pre-C++17,
however.

This commit adds two macros to fix the problem: under C++17 (with the
appropriate feature macro set) they provide an extra `bool NoExceptions`
template argument and provide the `noexcept(NoExceptions)` deduced
specifier.  Under pre-C++17 they expand to nothing.

This is needed to compile pybind11 with gcc7 under -std=c++17.
2016-12-14 20:40:49 +01:00
Jason Rhinelander
79de508ef4 Fix test compilation when both optional's exist
gcc 7 has both std::experimental::optional and std::optional, but this
breaks the test compilation as we are trying to use the same `opt_int`
type alias for both.
2016-12-14 20:40:49 +01:00
Jason Rhinelander
12ce07a2c2 Remove useless convert argument from argument_loader
Since the argument loader split off from the tuple converter, it is
never called with a `convert` argument set to anything but true.  This
removes the argument entirely, passing a literal `true` from within
`argument_loader` to the individual value casters.
2016-12-14 20:40:49 +01:00
Jason Rhinelander
23e59c8633 Work around gcc 7 ICE
Current g++ 7 snapshot fails to compile pybind under -std=c++17 with:

```
$ make
[  3%] Building CXX object tests/CMakeFiles/pybind11_tests.dir/pybind11_tests.cpp.o
In file included from /home/jagerman/src/pybind11/tests/pybind11_tests.h:2:0,
                 from /home/jagerman/src/pybind11/tests/pybind11_tests.cpp:10:
/home/jagerman/src/pybind11/include/pybind11/pybind11.h: In instantiation of 'pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...)::<lambda(pybind11::detail::function_record*, pybind11::handle, pybind11::handle, pybind11::handle)> [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::<lambda(ConstructorStats*)>; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]':
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:120:22:   required from 'struct pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::<lambda(ConstructorStats*)>; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::<lambda(struct pybind11::detail::function_record*, class pybind11::handle, class pybind11::handle, class pybind11::handle)>'
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:120:19:   required from 'void pybind11::cpp_function::initialize(Func&&, Return (*)(Args ...), const Extra& ...) [with Func = pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]::<lambda(ConstructorStats*)>; Return = int; Args = {ConstructorStats*}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]'
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:62:9:   required from 'pybind11::cpp_function::cpp_function(Return (Class::*)(Arg ...), const Extra& ...) [with Return = int; Class = ConstructorStats; Arg = {}; Extra = {pybind11::name, pybind11::is_method, pybind11::sibling}]'
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:984:22:   required from 'pybind11::class_<type_, options>& pybind11::class_<type_, options>::def(const char*, Func&&, const Extra& ...) [with Func = int (ConstructorStats::*)(); Extra = {}; type_ = ConstructorStats; options = {}]'
/home/jagerman/src/pybind11/tests/pybind11_tests.cpp:24:47:   required from here
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:147:9: sorry, unimplemented: unexpected AST of kind cleanup_stmt
         };
         ^
/home/jagerman/src/pybind11/include/pybind11/pybind11.h:147:9: internal compiler error: in potential_constant_expression_1, at cp/constexpr.c:5593
0x84c52a potential_constant_expression_1
	../../src/gcc/cp/constexpr.c:5593
0x84c3c0 potential_constant_expression_1
	../../src/gcc/cp/constexpr.c:5154
0x645511 finish_function(int)
	../../src/gcc/cp/decl.c:15527
0x66e80b instantiate_decl(tree_node*, int, bool)
	../../src/gcc/cp/pt.c:22558
0x6b61e2 instantiate_class_template_1
	../../src/gcc/cp/pt.c:10444
0x6b61e2 instantiate_class_template(tree_node*)
	../../src/gcc/cp/pt.c:10514
0x75a676 complete_type(tree_node*)
	../../src/gcc/cp/typeck.c:133
0x67d5a4 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:17516
0x67ca19 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool)
	../../src/gcc/cp/pt.c:16655
0x672cce tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:16140
0x6713dc tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:15408
0x671915 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:15394
0x671fc0 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:15618
0x66e97f tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
	../../src/gcc/cp/pt.c:15379
0x66e97f instantiate_decl(tree_node*, int, bool)
	../../src/gcc/cp/pt.c:22536
0x6ba0cb instantiate_pending_templates(int)
	../../src/gcc/cp/pt.c:22653
0x6fd7f8 c_parse_final_cleanups()
	../../src/gcc/cp/decl2.c:4512
```

which looks a lot like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77545.

The error seems to be that it gets confused about the `std::tuple<...>
value` in argument_loader: it is apparently not being initialized
properly.  Adding a default constructor with an explicit
default-initialization of `value` works around the problem.
2016-12-14 20:40:49 +01:00
Jason Rhinelander
cb63770978 Silence warnings from eigen under g++ 7
-Wint-in-bool-context triggers many warnings when compiling eigen code,
so disable it locally in eigen.h.
2016-12-14 20:40:49 +01:00
Lori A. Burns
f4b81b36bf reflow some docs paragraphs 2016-12-13 21:44:19 +01:00
Lori A. Burns
eb09af5e58 test installed pybind 2016-12-13 21:44:19 +01:00
Lori A. Burns
545b4dbc19 separate main CMakeLists.txt into Tools file also available upon installation 2016-12-13 21:44:19 +01:00
Lori A. Burns
5cafc99884 add CMake exported interface library and Config detection file 2016-12-13 21:44:19 +01:00
Lori A. Burns
44d7c59c55 make installation include and Config dirs configurable. set CMake project version from source. 2016-12-13 21:44:19 +01:00
Dean Moldovan
76e993a3f4 Set maximum line length for Python style checker (#552) 2016-12-13 00:59:28 +01:00
Wenzel Jakob
de2c6df200 check-style.sh: check for accidentally committed CRLF line endings 2016-12-13 00:24:08 +01:00
Jason Rhinelander
3f1ff3f4d1 Adds automatic casting on assignment of non-pyobject types (#551)
This adds automatic casting when assigning to python types like dict,
list, and attributes.  Instead of:

    dict["key"] = py::cast(val);
    m.attr("foo") = py::cast(true);
    list.append(py::cast(42));

you can now simply write:

    dict["key"] = val;
    m.attr("foo") = true;
    list.append(42);

Casts needing extra parameters (e.g. for a non-default rvp) still
require the py::cast() call. set::add() is also supported.

All usage is channeled through a SFINAE implementation which either just returns or casts. 

Combined non-converting handle and autocasting template methods via a
helper method that either just returns (handle) or casts (C++ type).
2016-12-12 23:42:52 +01:00
Wenzel Jakob
7c9ef7b553 stable documentation link in README.md 2016-12-12 23:35:25 +01:00
Wenzel Jakob
f8571ea1bc workaround for sphinx/docutils issue
https://github.com/sphinx-doc/sphinx/issues/3212
2016-12-11 18:51:46 +01:00
Wenzel Jakob
8fadade225 add valarray to documentation, update docutils on travis 2016-12-09 16:08:16 +01:00
Dean Moldovan
4e959c9af4 Add syntax sugar for resolving overloaded functions (#541) 2016-12-08 11:07:52 +01:00
Jason Rhinelander
ae185b7f19 std::valarray support for stl.h (#545)
* Added ternary support with descr args

Current the `_<bool>(a, b)` ternary support only works for `char[]` `a`
and `b`; this commit allows it to work for `descr` `a` and `b` arguments
as well.

* Add support for std::valarray to stl.h

This abstracts the std::array into a `array_caster` which can then be
used with either std::array or std::valarray, the main difference being
that std::valarray is resizable.  (It also lets the array_caster be
potentially used for other std::array-like interfaces, much as the
list_caster and map_caster currently provide).

* Small stl.h cleanups

- Remove redundant `type` typedefs
- make internal list_caster methods private
2016-12-08 00:43:29 +01:00
Dean Moldovan
ab90ec6ce9 Allow references to objects held by smart pointers (#533) 2016-12-07 02:36:44 +01:00
Dean Moldovan
8c85a85747 Use C++14 index_sequence when possible
Newer standard libraries use compiler intrinsics for std::index_sequence
which makes it ‘free’. This prevents hitting instantiation limits for
recursive templates (-ftemplate-depth).
2016-12-03 23:13:53 +01:00
Dean Moldovan
107285b353 Accept any sequence type as std::tuple or std::pair
This is more Pythonic and compliments the std::vector and std::list
casters which also accept sequences.
2016-12-03 23:13:53 +01:00
Dean Moldovan
719c1733dd Split up tuple caster and function argument loader
This is needed in order to allow the tuple caster to accept any sequence
while keeping the argument loader fast. There is also very little overlap
between the two classes which makes the separation clean. It’s also good
practice not to have completely new functionality in a specialization.
2016-12-03 23:13:53 +01:00
Alessandro Bacchini
9f13a30c6e Add missing C++ headers. Sort headers (#540) 2016-12-01 15:22:17 +01:00
esquires
67a68f1394 print traceback on failed import (#537) 2016-12-01 11:35:34 +01:00
Jason Rhinelander
14bfe622f8 Simplify cast_op return type (#532)
Using a complicated declval here was pointlessly complicated: we
already know the type, because that's what cast_op_type<T> is in the
first place.  (The declval also broke MSVC).
2016-11-25 19:23:01 +01:00
Jason Rhinelander
db86f7f285 Clean up cast operator invocations (#531)
This adds a `detail::cast_op<T>(caster)` function which handles the
rather verbose:

    caster.operator typename CasterType::template cast_op_type<T>()

which allows various places to use the shorter and clearer:

    cast_op<T>(caster)

instead of the full verbose cast operator invocation.
2016-11-25 18:35:00 +01:00
Jason Rhinelander
f200493716 Fixed stl casters to use the appropriate type_caster cast_op_type (#529)
stl casters were using a value cast to (Value) or (Key), but that isn't
always appropriate.  This changes it to use the appropriate value
converter's cast_op_type.
2016-11-25 13:06:18 +01:00
Wenzel Jakob
8d396fcff2 use pybind11::gil_scoped_acquire instead of PyGILState_* 2016-11-24 23:11:11 +01:00
Wenzel Jakob
099d6e9c48 Improved implementation of error_already_set::~error_already_set()
C++ exceptions are destructed in the context of the code that catches
them. At this point, the Python GIL may not be held, which could lead
to crashes with the previous implementation.

PyErr_Fetch and PyErr_Restore should always occur in pairs, which was
not the case for the previous implementation. To clear the exception,
the new approach uses PyErr_Restore && PyErr_Clear instead of simply
decreasing the reference counts of the exception objects.
2016-11-24 18:52:33 +01:00
Wenzel Jakob
e72d958a5d detail::error_string: handle call stacks that switch between C++ and Python multiple times 2016-11-24 12:48:31 +01:00
Wenzel Jakob
fbec17ce90 error_already_set: move-only semantics 2016-11-24 12:30:11 +01:00
Jason Rhinelander
2ac2d69418 Improve FindPythonLibsNew detection of python library directory (#523)
* Use LIBDIR and MULTIARCH on linux to find python library

* Remove apple-specific setting; the non-windows one should work fine on OS X

* Default LIBDIR/MULTIARCH to '' (to avoid getting None)

* Remove trailing whitespace from FindPythonLibsNew
2016-11-22 22:01:03 +01:00