Commit Graph

395 Commits

Author SHA1 Message Date
Wenzel Jakob
987be18fee Merge pull request #379 from nevion/buffer_info
Buffer info improvements
2016-09-04 23:02:20 +09:00
Jason Newton
10d46e7f73 explicitly delete copy-ctor and assignment operator 2016-09-02 18:39:47 -04:00
Jason Newton
4764698069 add move ctor and move-assignment operator 2016-09-02 18:37:13 -04:00
Jason Newton
514c6dad70 add field for ownership 2016-09-02 17:10:50 -04:00
Jason Newton
3718c38e68 default all fields in all ctors 2016-09-02 17:10:02 -04:00
Jason Rhinelander
2097826346 Fix template trampoline overload lookup failure
Problem
=======

The template trampoline pattern documented in PR #322 has a problem with
virtual method overloads in intermediate classes in the inheritance
chain between the trampoline class and the base class.

For example, consider the following inheritance structure, where `B` is
the actual class, `PyB<B>` is the trampoline class, and `PyA<B>` is an
intermediate class adding A's methods into the trampoline:

    PyB<B> -> PyA<B> -> B -> A

Suppose PyA<B> has a method `some_method()` with a PYBIND11_OVERLOAD in
it to overload the virtual `A::some_method()`.  If a Python class `C` is
defined that inherits from the pybind11-registered `B` and tries to
provide an overriding `some_method()`, the PYBIND11_OVERLOADs declared
in PyA<B> fails to find this overloaded method, and thus never invoke it
(or, if pure virtual and not overridden in PyB<B>, raises an exception).

This happens because the base (internal) `PYBIND11_OVERLOAD_INT` macro
simply calls `get_overload(this, name)`; `get_overload()` then uses the
inferred type of `this` to do a type lookup in `registered_types_cpp`.
This is where it fails: `this` will be a `PyA<B> *`, but `PyA<B>` is
neither the base type (`B`) nor the trampoline type (`PyB<B>`).  As a
result, the overload fails and we get a failed overload lookup.

The fix
=======

The fix is relatively simple: we can cast `this` passed to
`get_overload()` to a `const B *`, which lets get_overload look up the
correct class.  Since trampoline classes should be derived from `B`
classes anyway, this cast should be perfectly safe.

This does require adding the class name as an argument to the
PYBIND11_OVERLOAD_INT macro, but leaves the public macro signatures
unchanged.
2016-08-29 19:41:44 -04:00
Wenzel Jakob
5e4e477b8b minor fixes to PR #368 2016-08-28 02:03:15 +02:00
Wenzel Jakob
a3906778eb minor: renamed argument in array constructor 2016-08-28 01:55:07 +02:00
Nickolai Belakovski
6333825350 Added support for exposing classes with private destructors and corresponding documentation 2016-08-27 15:09:15 -07:00
Wenzel Jakob
324c9c521b minor Intel compiler fix 2016-08-26 16:52:45 +02:00
Ivan Smirnov
d8b11b8708 Fix dtype::strip_padding() on Intel compiler 2016-08-25 21:52:52 +01:00
Wenzel Jakob
9a777a263d numpy.h: fix test suite issues on the Intel Compiler 2016-08-25 02:18:00 +02:00
Wenzel Jakob
89f2db4596 Merge pull request #353 from aldanor/feature/generalized-iterators
Add support for iterators with different begin/end types
2016-08-25 01:47:38 +02:00
Wenzel Jakob
1ffce7422d Get pybind11 test suite to compile on the Intel compiler (more or less..)
- ICPC can't handle the NCVirt trampoline which returns a non-copyable
  type, which is likely due to a constexpr/SFINAE issue. This disables
  the test on that compiler so that at least the rest can be tested.
2016-08-25 01:43:35 +02:00
Ivan Smirnov
1c8828fe8f Fix int_ shadowing problem in detail namespace
If operators.h is included, int_ function in the `detail`
namespace will shadow pybind11::int_ type, so the fully qualified
name has to be used.
2016-08-25 00:33:02 +01:00
Ivan Smirnov
2b308e01f7 Add support for iterators with differing end type 2016-08-24 23:29:04 +01:00
Ivan Smirnov
c5a1c8a6b9 Don't require operator-> for key iterators 2016-08-24 23:27:19 +01:00
Wenzel Jakob
8de0437e46 type_caster<std::function>: allow None values in both directions 2016-08-18 11:18:12 +02:00
Glen Walker
f45bb585c3 Support keep_alive where nurse may be None
For example keep_alive<0,1>() should work where the return value may sometimes be None. At present a "Could not allocate weak reference!" exception is thrown.
Update documentation to clarify behaviour of keep_alive when nurse is None or does not support weak references.
2016-08-18 09:09:41 +12:00
Ivan Smirnov
6956b655f0 Simplify code in eigen.h using new array ctors 2016-08-15 18:41:54 +01:00
Ivan Smirnov
67b3daeea4 Always decay type param of npy_format_descriptor 2016-08-15 18:41:54 +01:00
Ivan Smirnov
edbd4cb0a7 Decay const qualifiers in is_pod_struct<> 2016-08-15 18:41:54 +01:00
Ivan Smirnov
03fb488579 format_descriptor::format() now yields std::string
This is required since format descriptors for string types that
were using PYBIND11_DESCR were causing problems on C++14 on Linux.

Although this is technically a breaking change, it shouldn't cause
problems since the only use of format strings is passing them to
buffer_info constructor which expects std::string.

Note: for non-structured types, the const char * value is still
accessible via ::value for compatibility purpose.
2016-08-15 00:40:29 +01:00
Ivan Smirnov
6715736936 Add handle::repr() method 2016-08-14 13:43:31 +01:00
Ivan Smirnov
7dcbfe228e Add a missing bytes ctor from const char * 2016-08-13 20:00:15 +01:00
Ivan Smirnov
c22fe428ed Change str/bytes cast operators to ctors 2016-08-13 19:39:11 +01:00
Ivan Smirnov
89ec7f3e79 Add (const char *, size_t) ctors for str/bytes 2016-08-13 19:38:50 +01:00
Ivan Smirnov
fd6cede7e9 Avoid extra allocations in operator str/bytes 2016-08-13 15:46:46 +01:00
Ivan Smirnov
61e3b0bd15 Use builtin str type for recarray field names 2016-08-13 12:51:31 +01:00
Ivan Smirnov
1cdd171fbc Add PYBIND11_STR_TYPE to represent builtin str 2016-08-13 12:51:31 +01:00
Ivan Smirnov
006d8b6621 Add casting operators between py::str / py::bytes 2016-08-13 12:51:31 +01:00
Ivan Smirnov
3768b6abf9 Use fully qualified name in PYBIND11_DESCR macro 2016-08-13 12:43:16 +01:00
Ivan Smirnov
ad5ca6d4e6 Added dtype from const char pointer ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
c6257f8641 Allow nullptr in array ctors wherever possible 2016-08-13 12:43:16 +01:00
Ivan Smirnov
98ba98c06b Add a simplified buffer_info ctor for 1-D case 2016-08-13 12:43:16 +01:00
Ivan Smirnov
6636ae9d4e Also add the new ctors to py::array_t 2016-08-13 12:43:16 +01:00
Ivan Smirnov
6bb0ee1186 Add all possible ctors for py::array 2016-08-13 12:43:16 +01:00
Ivan Smirnov
d77bc8c343 Add dtype(names, offsets, formats, itemsize) ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
fc5620afa6 Fix a segfault where func object wasn't released 2016-08-13 12:43:16 +01:00
Ivan Smirnov
01f7409550 Initial implementation of py::dtype 2016-08-13 12:43:16 +01:00
Ivan Smirnov
05cb58ade2 Cleanup: move numpy API bindings out of py::array 2016-08-13 12:43:16 +01:00
Ivan Smirnov
afb07e7e92 Code reordering / cleanup only 2016-08-13 12:43:16 +01:00
Ivan Smirnov
f9c0defed7 Add numpy wrappers for char[] and std::array<char> 2016-08-13 12:43:16 +01:00
Ivan Smirnov
103d5eadc3 Remove redundant definition 2016-08-13 12:43:16 +01:00
Ivan Smirnov
098f9aef73 Replace 4096B format buffer with std::string 2016-08-13 12:43:16 +01:00
Ivan Smirnov
b37985ee0c Fix a comment and wrong indentation 2016-08-13 12:43:16 +01:00
Ivan Smirnov
bf2510ee86 Make buffer_info::as_pybuffer a memoryview ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
41c3399021 Update npy_format_descriptor::name() 2016-08-13 12:43:16 +01:00
Ivan Smirnov
076b953ccd Restore dtype equivalence sanity check 2016-08-13 12:43:16 +01:00
Ivan Smirnov
8f2f7cd61c Various cleanup 2016-08-13 12:43:16 +01:00