Commit Graph

2928 Commits

Author SHA1 Message Date
Jason Rhinelander
1f8a100d38 Track base class pointers of instances
This commits adds base class pointers of offset base classes (i.e. due
to multiple inheritance) to `registered_instances` so that if such a
pointer is returned we properly recognize it as an existing instance.

Without this, returning a base class pointer will cast to the existing
instance if the pointer happens to coincide with the instance pointer,
but constructs a new instance (quite possibly with a segfault, if
ownership is applied) for unequal base class pointers due to multiple
inheritance.
2017-04-27 09:12:41 -04:00
Jason Rhinelander
14e70650fe Fix downcasting of base class pointers
When we are returned a base class pointer (either directly or via
shared_from_this()) we detect its runtime type (using `typeid`), then
end up essentially reinterpret_casting the pointer to the derived type.
This is invalid when the base class pointer was a non-first base, and we
end up with an invalid pointer.  We could dynamic_cast to the
most-derived type, but if *that* type isn't pybind11-registered, the
resulting pointer given to the base `cast` implementation isn't necessarily valid
to be reinterpret_cast'ed back to the backup type.

This commit removes the "backup" type argument from the many-argument
`cast(...)` and instead does the derived-or-pointer type decision and
type lookup in type_caster_base, where the dynamic_cast has to be to
correctly get the derived pointer, but also has to do the type lookup to
ensure that we don't pass the wrong (derived) pointer when the backup
type (i.e. the type caster intrinsic type) pointer is needed.

Since the lookup is needed before calling the base cast(), this also
changes the input type to a detail::type_info rather than doing a
(second) lookup in cast().
2017-04-27 09:12:41 -04:00
Jason Rhinelander
929009954b Expose more instance management functions
This breaks up the instance management functions in class_support.h a
little bit so that other pybind11 code can use it.  In particular:

- added make_new_instance() which does what pybind11_object_new does,
  but also allows instance allocation without `value` allocation.  This
  lets `cast.h` use the same instance allocation rather than having its
  own separate implementation.
- instance registration is now moved to a
  `register_instance()`/deregister_instance()` pair (rather than having
  individual code add or remove things from `registered_instances`
  directory).
- clear_instance() does everything `pybind11_object_dealloc()` needs
  except for the deallocation; this is helpful for factory construction
  which needs to be able to replace the internals of an instance without
  deallocating it.
- clear_instance() now also calls `dealloc` when `holder_constructed`
  is true, even if `value` is false.  This can happen in factory
  construction when the pointer is moved from one instance to another,
  but the holder itself is only copied (i.e. for a shared_ptr holder).
2017-04-27 09:12:41 -04:00
Dean Moldovan
deb85f46ef Switch to regular breathe package on Travis
Breathe was previously installed from the git master because of a bug
in the released version. The fix has since migrated to PyPI.

[skip appveyor]
2017-04-22 23:30:33 +02:00
Jason Rhinelander
fb50ce1fef Add static_assert-raising error for overload_cast in c++11
I got some unexpected errors from code using `overload_cast` until I
realized that I'd configured the build with -std=c++11.

This commit adds a fake `overload_cast` class in C++11 mode that
triggers a static_assert failure indicating that C++14 is needed.
2017-04-18 22:06:25 -04:00
Jason Rhinelander
d355f2fcca Don't allow mixed static/non-static overloads
We currently fail at runtime when trying to call a method that is
overloaded with both static and non-static methods.  This is something
python won't allow: the object is either a function or an instance, and
can't be both.
2017-04-18 17:17:47 -04:00
Jason Rhinelander
90bac96321 Keep skipping buffer tests on pypy
Adding numpy to the pypy test exposed a segfault caused by the buffer
tests in test_stl_binders.py: the first such test was explicitly skipped
on pypy, but the second (test_vector_buffer_numpy) which also seems to
cause an occasional segfault was just marked as requiring numpy.

Explicitly skip it on pypy as well (until a workaround, fix, or pypy fix
are found).
2017-04-18 14:21:31 -04:00
Jason Rhinelander
d170731f6f Remove unneeded exports
Various bash variables that are only used in the travis-ci script and
don't need to propagate (e.g. to cmake) are being pointlessly exported;
this removes these `export`s.
2017-04-18 14:21:31 -04:00
Jason Rhinelander
f0c7c00815 Switch clang-4.0 build to trusty; cache libc++
This uses the trusty container rather than docker for the clang 4.0
build.  It also caches the local libc++ installation so that it doesn't
need to be compiled every time, which should speed up the job
considerably.
2017-04-18 14:21:31 -04:00
Jason Rhinelander
3d5005168b travis-ci: switch to trusty; cache pip packages
This applies several changes to the non-docker travis-ci builds:

- Make all builds use trusty rather than precise.  pybind can't really
  build in precise anyway (we install essentially the entire toolchain
  backported from trusty on every build), and so this saves needing to
  install all the backported packages during the build setup.
- Updated the 3.5 build to 3.6 (via deadsnakes, which didn't backport
  3.6 to ubuntu releases earlier than trusty).
- As a result of the switch to trusty, the BAREBONES build now picks up
  the (default installed) python 3.5 installation.
- Invoke pip everywhere via $PYTHON -m pip rather than the pip
  executable, which saves us having to figure out what the pip
  executable is, and ensures that we are using the correct pip.
- Install packages with `pip --user` rather than in a virtualenv.
- Add the local user python package archive to the travis-ci cache
  (rather than the pip cache).  This saves needing to install packages
  during installation (unless there are updates, in which case the
  package and the cache are updated).
- Install numpy and scipy on the pypy build.  This has to build from
  source (and so blas and fortran need to be installed on the build),
  but given the above caching, the build will only be slow for the first
  build after a new numpy/scipy release.  This testing is valuable:
  numpy has various behaviour differences under pypy.
- Added set -e/+e around the before_install/install blocks so that a
  failure here (e.g. a pip install failure or dependency download
  failure) triggers a build failure.
- Update eigen version to latest (3.3.3), mainly to be consistent with
  the appveyor build.
- The travis trusty environment has an upgraded cmake, so this
  downgrades cmake (to the stock trusty version) on the first couple
  jobs so that we're still including some cmake 2.8.12 testing.
2017-04-18 14:21:31 -04:00
Jason Rhinelander
b4cbd7a1fe Appveyor: Disable fast_finish for now
While builds are randomly failing, fast_finish is counterproductive.

Will reenable this once appveyor stabilizes.
2017-04-17 11:57:46 -04:00
Jason Rhinelander
2d14c1c5db Fixed bad_arg_def imports
Don't try to define these in the issues submodule, because that fails
if testing without issues compiled in (e.g. using
cmake -DPYBIND11_TEST_OVERRIDE=test_methods_and_attributes.cpp).
2017-04-15 11:12:41 -04:00
Jason Rhinelander
02ffbf16fe Fix PyBuffer_Release leak
5f38386293 accidentally dropped setting
buffer_info.view, resulting in the buffer never being released (because
view was always nullptr).
2017-04-14 13:57:49 -04:00
Jason Rhinelander
201796d94f Make any_container implicitly constructible from arithmetic values
This further reduces the constructors required in buffer_info/numpy by
removing the need for the constructors that take a single size_t and
just forward it on via an initializer_list to the container-accepting
constructor.

Unfortunately, in `array` one of the constructors runs into an ambiguity
problem with the deprecated `array(handle, bool)` constructor (because
both the bool constructor and the any_container constructor involve an
implicit conversion, so neither has precedence), so a forwarding
constructor is kept there (until the deprecated constructor is
eventually removed).
2017-04-13 09:57:02 -04:00
Jason Rhinelander
5f38386293 Accept abitrary containers and iterators for shape/strides
This adds support for constructing `buffer_info` and `array`s using
arbitrary containers or iterator pairs instead of requiring a vector.

This is primarily needed by PR #782 (which makes strides signed to
properly support negative strides, and will likely also make shape and
itemsize to avoid mixed integer issues), but also needs to preserve
backwards compatibility with 2.1 and earlier which accepts the strides
parameter as a vector of size_t's.

Rather than adding nearly duplicate constructors for each stride-taking
constructor, it seems nicer to simply allow any type of container (or
iterator pairs).  This works by replacing the existing vector arguments
with a new `detail::any_container` class that handles implicit
conversion of arbitrary containers into a vector of the desired type.
It can also be explicitly instantiated with a pair of iterators (e.g.
by passing {begin, end} instead of the container).
2017-04-13 09:57:02 -04:00
Jason Rhinelander
dbb4c5b531 Move buffer_info to its own header
Upcoming changes to buffer_info make it need some things declared in
common.h; it also feels a bit misplaced in common.h (which is arguably
too large already), so move it out.  (Separating this and the subsequent
changes into separate commits to make the changes easier to distinguish
from the move.)
2017-04-13 09:57:02 -04:00
Jason Rhinelander
5749b50239 array: set exception message on failure
When attempting to get a raw array pointer we return nullptr if given a
nullptr, which triggers an error_already_set(), but we haven't set an
exception message, which results in "Unknown internal error".

Callers that want explicit allowing of a nullptr here already handle it
(by clearing the exception after the call).
2017-04-13 09:53:56 -04:00
Wenzel Jakob
257df10ffe improve mkdoc.py determinism
When processing many files that contain top-level items with the same
name (e.g. "operator<<"), the output was non-deterministic and depended
on the order in which the different Clang processes finished. This
commit adds sorting that also accounts for the filename to prevent
random changes from run to run.
2017-04-12 11:09:47 +02:00
Wenzel Jakob
46469d4ec3 AppVeyor: suppress debug messages about generate.stamp
(https://gitlab.kitware.com/cmake/cmake/issues/16783)
2017-04-11 03:01:52 +02:00
Jason Rhinelander
3983a8ed48 AppVeyor: Update eigen to 3.3.3
The 3.3.2 changelog indicates it has some VS 2017 fixes.  Updating to
see if that avoids the random build failures.
2017-04-10 14:48:24 -04:00
Jason Rhinelander
4c72ec2220 Appveyor: Remove /m to attempt to resolve build failures
/m also doesn't seem to have made the builds any faster.
2017-04-09 08:12:17 -04:00
Jason Rhinelander
e9e17746c8 Fix Eigen argument doc strings
Many of the Eigen type casters' name() methods weren't wrapping the type
description in a `type_descr` object, which thus wasn't adding the
"{...}" annotation used to identify an argument which broke the help
output by skipping eigen arguments.

The test code I had added even had some (unnoticed) broken output (with
the "arg0: " showing up in the return value).

This commit also adds test code to ensure that named eigen arguments
actually work properly, despite the invalid help output.  (The added
tests pass without the rest of this commit).
2017-04-08 23:25:13 -04:00
Jason Rhinelander
501135fa76 Add static_assert to holder casters
The holder casters assume but don't check that a `holder<type>`'s `type`
is really a `type_caster_base<type>`; this adds a static_assert to make
sure this is really the case, to turn things like
`std::shared_ptr<array>` into a compilation failure.

Fixes #785
2017-04-08 10:55:51 -04:00
Jason Rhinelander
d994db2da0 Remove gcc 6/7 LTO and -Werror workarounds
The gcc versions in Debian stretch (gcc 6) and experimental (gcc 7)
incorporate the upstream gcc fixes.
2017-04-08 10:41:57 -04:00
Dean Moldovan
e0e2ea3378 Fix overriding static properties in derived classes
Fixes #775.

Assignments of the form `Type.static_prop = value` should be translated to
`Type.static_prop.__set__(value)` except when `isinstance(value, static_prop)`.
2017-04-07 22:41:46 +02:00
Wenzel Jakob
db200955b9 changelog for v2.1.1 2017-04-07 02:08:29 +02:00
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