Commit Graph

1480 Commits

Author SHA1 Message Date
Henry Schreiner 53782c08c0 Fix pip issues on AppVeyor CI (#1369) 2018-04-29 14:24:04 +02:00
Wenzel Jakob 8edc147d67 changelog for v2.2.3 2018-04-29 14:06:14 +02:00
Lori A. Burns 2972cb3808 Enforces intel icpc >= 2017, fixes #1121 (#1363) 2018-04-29 13:55:49 +02:00
Jason Rhinelander 97a62ebef2 Add workaround for clang 3.3/3.4
As reported in #1349, clang before 3.5 can segfault on a function-local
variable referenced inside a lambda.  This moves the function-local
static into a separate function that the lambda can invoke to avoid the
issue.

Fixes #1349
2018-04-29 13:52:59 +02:00
Jason Rhinelander 6837740bb6 Fix numpy dtypes test on big-endian architectures
This fixes the test code on big-endian architectures: the array support
(PR #832) had hard-coded the little-endian '<' but we need to use '>' on
big-endian architectures.
2018-04-29 13:52:37 +02:00
Wenzel Jakob 60306045ab Detect pybind11 header path without depending on pip internals (fixes #1174) (#1190) 2018-04-29 13:52:07 +02:00
Wenzel Jakob f117a48ea2 mark release date in changelog 2018-02-07 10:59:22 +01:00
Jason Rhinelander 19e90dc310 Updated version/changelog for 2.2.2 2018-02-07 10:54:31 +01:00
Wenzel Jakob ebe16361b0 Fix pybind11 interoperability with Clang trunk 2018-02-07 10:54:31 +01:00
Jason Rhinelander f99f685160 MSVC workaround for broken `using detail::_` warning
Current MSVC generates totally bizarre errors:

    error C2884: 'pybind11::detail::_': introduced by using-declaration
    conflicts with local function 'pybind11::detail::_'

which makes no sense (since the supposed "conflict" is the function
itself).  Work around it by `using namespace detail;` instead (which
also lets us drop a bunch of other `detail::` qualifications, so isn't
actually a bad thing).
2018-02-07 10:54:31 +01:00
Jason Rhinelander c3d81d235f Use stricter brace initialization
This updates the `py::init` constructors to only use brace
initialization for aggregate initiailization if there is no constructor
with the given arguments.

This, in particular, fixes the regression in #1247 where the presence of
a `std::initializer_list<T>` constructor started being invoked for
constructor invocations in 2.2 even when there was a specific
constructor of the desired type.

The added test case demonstrates: without this change, it fails to
compile because the `.def(py::init<std::vector<int>>())` constructor
tries to invoke the `T(std::initializer_list<std::vector<int>>)`
constructor rather than the `T(std::vector<int>)` constructor.

By only using `new T{...}`-style construction when a `T(...)`
constructor doesn't exist, we should bypass this by while still allowing
`py::init<...>` to be used for aggregate type initialization (since such
types, by definition, don't have a user-declared constructor).
2018-02-07 10:54:31 +01:00
Jason Rhinelander 56c1edb46d Don't add duplicate patients
This fixes #1251 (patient vector grows without bounds) for the 2.2.2
branch by checking that the vector doesn't already have the given
patient.

This is a little less elegant than the same fix for `master` (which
changes the patients `vector` to an `unordered_set`), but that requires
an internals layout change, which this approach avoids.
2018-02-07 10:54:31 +01:00
Jason Rhinelander 20d6d1d457 Fix segfault when reloading interpreter with external modules (#1092)
* Fix segfault when reloading interpreter with external modules

When embedding the interpreter and loading external modules in that
embedded interpreter, the external module correctly shares its
internals_ptr with the one in the embedded interpreter.  When the
interpreter is shut down, however, only the `internals_ptr` local to
the embedded code is actually reset to nullptr: the external module
remains set.

The result is that loading an external pybind11 module, letting the
interpreter go through a finalize/initialize, then attempting to use
something in the external module fails because this external module is
still trying to use the old (destroyed) internals.  This causes
undefined behaviour (typically a segfault).

This commit fixes it by adding a level of indirection in the internals
path, converting the local internals variable to `internals **` instead
of `internals *`.  With this change, we can detect a stale internals
pointer and reload the internals pointer (either from a capsule or by
creating a new internals instance).

(No issue number: this was reported on gitter by @henryiii and @aoloe).
2018-02-07 10:54:31 +01:00
Jeff VanOss 17ad517d61 fix return from std::map bindings to __delitem__ (#1229)
Fix return from `std::map` bindings to `__delitem__`: we should be returning `void`, not an iterator.

Also adds a test for map item deletion.
2018-02-07 10:54:31 +01:00
luz.paz ed0a72eb0e misc. typos
Found via `codespell`
2018-02-07 10:54:31 +01:00
Jason Rhinelander c8f07b5d01 Use a named rather than anon struct in instance
The anonymous struct nested in a union triggers a -Wnested-anon-type
warning ("anonymous types declared in an anonymous union are an
extension") under clang (#1204).  This names the struct and defines it
out of the definition of `instance` to get around to warning (and makes
the code slightly simpler).
2018-02-07 10:54:31 +01:00
Jason Rhinelander 7f170fe4e1 Fixes for numpy 1.14.0 compatibility
- UPDATEIFCOPY is deprecated, replaced with similar (but not identical)
  WRITEBACKIFCOPY; trying to access the flag causes a deprecation
  warning under numpy 1.14, so just check the new flag there.
- Numpy `repr` formatting of floats changed in 1.14.0 to `[1., 2., 3.]`
  instead of the pre-1.14 `[ 1.,  2.,  3.]`.  Updated the tests to
  check for equality with the `repr(...)` value rather than the
  hard-coded (and now version-dependent) string representation.
2018-02-07 10:54:31 +01:00
Jason Rhinelander 8310aa4676 Added py::args ref counting tests 2018-02-07 10:54:31 +01:00
Jason Rhinelander 0c7aec480a Simplify arg copying 2018-02-07 10:54:31 +01:00
Zach DeVito 155cc7c4d2 Fix leak in var arg handling
When using the mixed position + vararg path, pybind over inc_ref's
the vararg positions. Printing the ref_count() of `item` before
and after this change you see:

Before change:

```
refcount of item before assign 3
refcount of item after assign 5
```

After change
```
refcount of item before assign 3
refcount of item after assign 4
```
2018-02-07 10:54:31 +01:00
Jason Rhinelander c715c70e0a Fix premature destruction of args/kwargs arguments
The `py::args` or `py::kwargs` arguments aren't properly referenced
when added to the function_call arguments list: their reference counts
drop to zero if the first (non-converting) function call fails, which
means they might be cleaned up before the second pass call runs.

This commit adds a couple of extra `object`s to the `function_call`
where we can stash a reference to them when needed to tie their
lifetime to the function_call object's lifetime.

(Credit to YannickJadoul for catching and proposing a fix in #1223).
2018-02-07 10:54:31 +01:00
Elliott Sales de Andrade 53e0aa034b Update PyPI URLs. 2018-02-07 10:54:31 +01:00
Jason Rhinelander 3793c7ed9a Silence new MSVC C++17 deprecation warnings
In the latest MSVC in C++17 mode including Eigen causes warnings:

    warning C4996: 'std::unary_negate<_Fn>': warning STL4008: std::not1(),
    std::not2(), std::unary_negate, and std::binary_negate are deprecated in
    C++17. They are superseded by std::not_fn(). You can define
    _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING or
    _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have
    received this warning.

This disables 4996 for the Eigen includes.

Catch generates a similar warning for std::uncaught_exception, so
disable the warning there, too.

In both cases this is temporary; we can (and should) remove the warnings
disabling once new upstream versions of Eigen and Catch are available
that address the warning. (The Catch one, in particular, looks to be
fixed in upstream master, so will probably be fixed in the next (2.0.2)
release).
2018-02-07 10:54:31 +01:00
Antony Lee 7ab1cd34b1 Remove spurious quote in error message. (#1202) 2018-02-07 10:54:31 +01:00
Wenzel Jakob 83e73091f0 Moved section on licensing of contributions (fixes #1109) (#1188) 2018-02-07 10:54:31 +01:00
Jason Rhinelander 07dc73da1e __qualname__ and nested class naming fixes (#1171)
A few fixes related to how we set `__qualname__` and how we show the
type name in function signatures:

- `__qualname__` isn't supposed to have the module name at the
beginning, but we've been putting it there.  This removes it, while
keeping the `Nested.Class` name chaining.

- print `__module__.__qualname__` rather than `type->tp_name`; the
latter doesn't work properly for nested classes, so we would get
`module.B` rather than `module.A.B` for a class `B` with parent `A`.
This also unifies the Python 3 and PyPy code.  Fixes #1166.

- This now sets a `__qualname__` attribute on the type (as would happen
in Python 3.3+) for Python <3.3, including PyPy.  While not particularly
important to have in earlier Python versions, it's useful for us to be
able to extracted the nested name, which is why `__qualname__` was
invented in the first place.

- Added tests for the above.
2018-02-07 10:54:31 +01:00
Unknown 0957972650 Trivial typos
Non-user facing. 
Found using `codespell -q 3`
2018-02-07 10:54:31 +01:00
Jason Rhinelander fc8d1c7667 Fix new flake8 E741 error from using `l` variable
The just-updated flake8 package hits a bunch of:

    E741 ambiguous variable name 'l'

warnings.  This commit renames them all from `l` to `lst` (they are all
list values) to avoid the error.
2018-02-07 10:54:31 +01:00
Wenzel Jakob 2406a0cff9 added citation reference (fixes #767) (#1189) 2018-02-07 10:54:31 +01:00
Jason Rhinelander fbb2ef7ea1 Miscellaneous travis-ci updates/fixes
- For the debian/buster docker build (GCC 7/C++17) install and use the
  system `catch` package; this also renames "COMPILER_PACKAGES" to
  "EXTRA_PACKAGES" since it now contains a non-compiler package.

- Add a status message indicating the catch version being used for
  compiling the embedded tests

- Simplify some bash code by using VAR+=" foo" to append (rather than
  VAR="${VAR} foo"

- Fix CMAKE_INCLUDE_PATH appending: it was prepending the ':' but not
  the existing $CMAKE_INCLUDE_PATH value and so would end up with
  ":/eigen-path" if CMAKE_INCLUDE_PATH was already set.  (This wasn't
  bug that was actually noticed since currently nothing else sets it).
2018-02-07 10:54:31 +01:00
Jason Rhinelander 6519388f5c Build /permissive- under VS2017
Building with the (VS2017) /permissive- flag puts the compiler into
stricter standards-compliant mode.  It shouldn't cause the compiler to
work differently--it just disallows some non-conforming code--so should
be perfectly fine for the test suite under all VS2017 builds.

This commit also fixes one failure under non-permissive mode.
2018-02-07 10:54:31 +01:00
Jason Rhinelander a28393cf7b Fix 2D Nx1/1xN inputs to eigen dense vector args
This fixes a bug introduced in b68959e822
when passing in a two-dimensional, but conformable, array as the value
for a compile-time Eigen vector (such as VectorXd or RowVectorXd).  The
commit switched to using numpy to copy into the eigen data, but this
broke the described case because numpy refuses to broadcast a (N,1)
into a (N).

This commit fixes it by squeezing the input array whenever the output
array is 1-dimensional, which will let the problematic case through.
(This shouldn't squeeze inappropriately as dimension compatibility is
already checked for conformability before getting to the copy code).
2018-02-07 10:54:31 +01:00
Jason Rhinelander fe1266e069 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
2018-02-07 10:54:31 +01:00
Wenzel Jakob 86e2ad4f77 updated changelog for v2.2.1 release 2017-09-14 08:49:47 +02:00
Wenzel Jakob 49518d2cd1 updated version info for v2.2.1 release 2017-09-14 08:48:54 +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