Commit Graph

1673 Commits

Author SHA1 Message Date
Antony Lee
baf6b99004 Silence GCC8's -Wcast-function-type. (#1396)
* Silence GCC8's -Wcast-function-type.

See https://bugs.python.org/issue33012 and PRs linked therein.
2018-06-24 15:38:09 +02:00
Axel Huebl
97b20e537a CMake: Remember Python Version (#1434)
It is useful not only to remember the python libs and includes but
also the interpreter version in cache.

If users call pybind11 throught `add_subdirectories` they will
otherwise have no access to the selected interpreter version.
The interpreter version is useful for downstream projects, e.g.
to select default `lib/pythonX.Y/site-packages/` install paths.
2018-06-24 15:22:41 +02:00
Khachajantc Michael
e3cb2a674a Use std::addressof to obtain holder address instead of operator& 2018-06-23 21:29:54 -03:00
Maciek Starzyk
9b02856293 Update PyPI URLs 2018-06-21 11:37:16 -03:00
Axel Huebl
4b84bad7ef Fix Travis GCC 7 Python 3.6.6 (#1436)
Add missing python3 distutils on Debian "buster".
2018-06-21 11:31:46 -03:00
Antony Lee
58e551cc73 Properly report exceptions thrown during module initialization.
If an exception is thrown during module initialization, the
error_already_set destructor will try to call `get_internals()` *after*
setting Python's error indicator, resulting in a `SystemError: ...
returned with an error set`.

Fix that by temporarily stashing away the error indicator in the
destructor.
2018-06-15 10:56:50 -03:00
Antony Lee
55dc131944 Clarify docs for functions taking bytes and not str. 2018-05-24 11:09:41 -03:00
Jason Rhinelander
e763f04689 Base class destructor should be virtual
Fixes #1401
2018-05-18 12:48:32 -03:00
François Becker
ce9d6e2c0d Fixed typo in classes.rst (#1388)
Fixed typos (erroneous `;`) in `classes.rst`.
2018-05-07 10:18:08 -03:00
Naotoshi Seo
5ef1af138d Fix SEGV to create empty shaped numpy array (#1371)
Fix a segfault when creating a 0-dimension, c-strides array.
2018-05-06 10:59:25 -03:00
luzpaz
4b874616b2 Misc. typos (#1384)
Found via `codespell`
2018-05-06 10:54:10 -03:00
Tom de Geus
a7ff616dfb Simplified example allowing more robust usage, fixed minor spelling issues 2018-05-06 10:48:54 -03:00
Wenzel Jakob
f5f6618962 updated changelog for v2.2.3 2018-04-29 15:47:13 +02:00
Lori A. Burns
bdbe8d0bde Enforces intel icpc >= 2017, fixes #1121 (#1363) 2018-04-29 13:48:25 +02:00
David Caron
307ea6b7fd Typo 2018-04-24 17:44:57 -03:00
Wenzel Jakob
ed67005583
Minor fix for MSVC warning CS4459 (#1374)
When using pybind11 to bind enums on MSVC and warnings (/W4) enabled,
the following warning pollutes builds. This fix renames one of the
occurrences.

pybind11\include\pybind11\pybind11.h(1398): warning C4459: declaration of 'self' hides global declaration
pybind11\include\pybind11\operators.h(41): note: see declaration of 'pybind11::detail::self'
2018-04-22 14:04:31 +02:00
Henry Schreiner
ffd56ebec0 Fix pip issues on AppVeyor CI (#1369) 2018-04-22 14:04:12 +02:00
Wenzel Jakob
060936fed2
Detect pybind11 header path without depending on pip internals (fixes #1174) (#1190) 2018-04-16 10:27:21 +02:00
oremanj
fd9bc8f54d Add basic support for tag-based static polymorphism (#1326)
* Add basic support for tag-based static polymorphism

Sometimes it is possible to look at a C++ object and know what its dynamic type is,
even if it doesn't use C++ polymorphism, because instances of the object and its
subclasses conform to some other mechanism for being self-describing; for example,
perhaps there's an enumerated "tag" or "kind" member in the base class that's always
set to an indication of the correct type. This might be done for performance reasons,
or to permit most-derived types to be trivially copyable. One of the most widely-known
examples is in LLVM: https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html

This PR permits pybind11 to be informed of such conventions via a new specializable
detail::polymorphic_type_hook<> template, which generalizes the previous logic for
determining the runtime type of an object based on C++ RTTI. Implementors provide
a way to map from a base class object to a const std::type_info* for the dynamic
type; pybind11 then uses this to ensure that casting a Base* to Python creates a
Python object that knows it's wrapping the appropriate sort of Derived.

There are a number of restrictions with this tag-based static polymorphism support
compared to pybind11's existing support for built-in C++ polymorphism:

- there is no support for this-pointer adjustment, so only single inheritance is permitted
- there is no way to make C++ code call new Python-provided subclasses
- when binding C++ classes that redefine a method in a subclass, the .def() must be
  repeated in the binding for Python to know about the update

But these are not much of an issue in practice in many cases, the impact on the
complexity of pybind11's innards is minimal and localized, and the support for
automatic downcasting improves usability a great deal.
2018-04-14 02:13:10 +02:00
Antony Lee
8fbb5594fd Clarify error_already_set documentation. 2018-04-09 16:25:04 -03:00
Boris Staletic
289e5d9cc2 Implement an enum_ property "name"
The property returns the enum_ value as a string.
For example:

>>> import module
>>> module.enum.VALUE
enum.VALUE
>>> str(module.enum.VALUE)
'enum.VALUE'
>>> module.enum.VALUE.name
'VALUE'

This is actually the equivalent of Boost.Python "name" property.
2018-04-07 19:11:35 -03:00
Jason Rhinelander
6862cb9b35 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-05 12:01:39 -03:00
Henry Schreiner
6c62d2797c Fix for conda failures on Windows 2018-04-03 20:36:06 -03:00
Patrik Huber
41a4fd8ae9 Fix missing word typo
I think that there's the word "for" missing for that sentence to be correct.
Please double-check that the sentence means what it's supposed to mean. :-)
2018-04-02 21:10:38 -03:00
Jason Rhinelander
6d0b4708c6 Reimplement version check and combine init macros
This reimplements the version check to avoid sscanf (which has
reportedly started throwing warnings under MSVC, even when used
perfectly safely -- #1314).  It also extracts the mostly duplicated
parts of PYBIND11_MODULE/PYBIND11_PLUGIN into separate macros.
2018-03-11 11:10:06 -03:00
Jason Rhinelander
9f41c8eade Fix class name in overload failure message 2018-03-10 14:24:23 -04:00
Jason Rhinelander
e88656ab45 Improve macro type handling for types with commas
- PYBIND11_MAKE_OPAQUE now takes ... rather than a single argument and
  expands it with __VA_ARGS__; this lets templated, comma-containing
  types get through correctly.
- Adds a new macro PYBIND11_TYPE() that lets you pass the type into a
  macro as a single argument, such as:

      PYBIND11_OVERLOAD(PYBIND11_TYPE(R<1,2>), PYBIND11_TYPE(C<3,4>), func)

  Unfortunately this only works for one macro call: to forward the
  argument on to the next macro call (without the processor breaking it
  up again) requires also adding the PYBIND11_TYPE(...) to type macro
  arguments in the PYBIND11_OVERLOAD_... macro chain.
- updated the documentation with these two changes, and use them at a couple
  places in the test suite to test that they work.
2018-03-10 14:24:23 -04:00
Marc Schlaich
ab003dbdd9 Correct VS version in FAQ 2018-03-10 14:19:31 -04:00
Jason Rhinelander
1ddfacbad1 Fix for Python3 via brew
Apparently with homebrew the correct package for python3 is now just
`python`; python 2 was relegated to 'python@2', and `python3` is an
alias for `python` (which needs to be upgraded rather than installed).
2018-03-10 13:33:15 -04:00
luz.paz
13c08072dc Typo 2018-02-27 22:46:56 -04:00
Tomas Babej
01fada7674 Minor typo 2018-02-27 22:46:29 -04:00
Jason Rhinelander
431fc0e198 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-02-18 18:36:11 +01:00
Wenzel Jakob
2d0507db43 added v2.2.2 changelog 2018-02-07 11:05:41 +01:00
Wenzel Jakob
ff6bd092d4
Fix pybind11 interoperability with Clang trunk (#1269) 2018-02-06 15:40:50 +01:00
Jason Rhinelander
add56ccdca MSVC workaround for broken using detail::_ warning 2018-01-12 12:37:54 -04:00
Jason Rhinelander
657a51e889 Remove unnecessary detail::
This function already has a `using namespace detail`, so all the
`detail::` qualifications are not needed.
2018-01-12 12:06:46 -04:00
Jason Rhinelander
adbc8111bc 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-01-12 09:29:57 -04:00
Jason Rhinelander
326deef2ae
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-01-11 19:46:10 -04:00
Jeff VanOss
05d379a9aa 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-01-11 19:43:37 -04:00
luz.paz
28cb6764fc misc. typos
Found via `codespell`
2018-01-11 16:39:50 -04:00
Jason Rhinelander
507da4181d 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-01-11 16:38:45 -04:00
Jason Rhinelander
88efb25145 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-01-11 11:43:54 -04:00
Antony Lee
0826b3c106 Add spaces around "=" in signature repr.
PEP8 indicates (correctly, IMO) that when an annotation is present, the
signature should include spaces around the equal sign, i.e.

    def f(x: int = 1): ...

instead of

    def f(x: int=1): ...

(in the latter case the equal appears to bind to the type, not to the
argument).

pybind11 signatures always includes a type annotation so we can always
add the spaces.
2017-12-27 11:04:24 -04:00
Ivan Smirnov
d1db2ccfdf Make register_dtype() accept any field containers (#1225)
* Make register_dtype() accept any field containers

* Add a test for programmatic dtype registration
2017-12-27 11:00:27 -04:00
Jason Rhinelander
b48d4a01ca Added py::args ref counting tests 2017-12-23 18:53:26 -04:00
Jason Rhinelander
367d723a54 Simplify arg copying 2017-12-23 18:53:26 -04:00
Zach DeVito
03874e3738 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
```
2017-12-23 18:53:26 -04:00
Jason Rhinelander
48e1f9aadc 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).
2017-12-23 16:42:22 -04:00
Elliott Sales de Andrade
5e7591c66b Update PyPI URLs. 2017-12-23 15:47:51 -04:00
Jason Rhinelander
3be401f2a2 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).
2017-12-23 09:00:45 -04:00