Commit Graph

2052 Commits

Author SHA1 Message Date
Henry Schreiner
0f404a5d4d Allow recursive checkout without https (#1563) 2018-10-10 21:28:53 +02:00
Jason Rhinelander
177713fa4e Fix gcc-8 compilation warning 2018-10-02 12:11:37 -03:00
Rune Paamand
73634b6db7 Update iostream.h: Changed a local varname 'self' to 'self_' (#1535)
* Update iostream.h: Changed a local varname 'self' to 'self_'

Avoiding conflicts in namespace pybind11::self.
https://github.com/pybind/pybind11/issues/1531
2018-09-27 16:26:42 +02:00
oremanj
e7761e3383 Fix potential crash when calling an overloaded function (#1327)
* Fix potential crash when calling an overloaded function

The crash would occur if:
- dispatcher() uses two-pass logic (because the target is overloaded and some arguments support conversions)
- the first pass (with conversions disabled) doesn't find any matching overload
- the second pass does find a matching overload, but its return value can't be converted to Python

The code for formatting the error message assumed `it` still pointed to the selected overload,
but during the second-pass loop `it` was nullptr. Fix by setting `it` correctly if a second-pass
call returns a nullptr `handle`. Add a new test that segfaults without this fix.

* Make overload iteration const-correct so we don't have to iterate again on second-pass error

* Change test_error_after_conversions dependencies to local classes/variables
2018-09-25 23:55:18 +02:00
Davis E. King
9343e68b46 Fix cmake scripts so projects using CUDA .cu files build correctly. (#1441) 2018-09-14 14:28:54 +02:00
Wenzel Jakob
c8e9f3ccad quench __setstate__ warnings (fixes #1522) 2018-09-14 12:07:47 +02:00
Semen Yesylevskyy
ef13fb2e1c Info about inconsistent detection of Python version between pybind11 … (#1093)
* Info about inconsistent detection of Python version between pybind11 and CMake in FAQ
2018-09-12 00:20:56 +02:00
Wenzel Jakob
f4245181ae enum_: move most functionality to a non-template implementation
This commit addresses an inefficiency in how enums are created in
pybind11. Most of the enum_<> implementation is completely generic --
however, being a template class, it ended up instantiating vast amounts
of essentially identical code in larger projects with many enums.

This commit introduces a generic non-templated helper class that is
compatible with any kind of enumeration. enum_ then becomes a thin
wrapper around this new class.

The new enum_<> API is designed to be 100% compatible with the old one.
2018-09-11 22:08:26 +02:00
Wenzel Jakob
b4b2292488 relax operator[] for tuples, lists, and sequences
object_api::operator[] has a powerful overload for py::handle that can
accept slices, tuples (for NumPy), etc.

Lists, sequences, and tuples provide their own specialized operator[],
which unfortunately disables this functionality. This is accidental, and
the purpose of this commit is to re-enable the more general behavior.

This commit is tangentially related to the previous one in that it makes
py::handle/py::object et al. behave more like their Python counterparts.
2018-09-11 22:08:26 +02:00
Wenzel Jakob
067100201f object_api: support the number protocol
This commit revamps the object_api class so that it maps most C++
operators to their Python analogs. This makes it possible to, e.g.
perform arithmetic using a py::int_ or py::array.
2018-09-11 22:08:26 +02:00
Krzysztof Fornalczyk
5c8746ff13 check for already existing enum value added; added test (#1453)
* check for already existing enum value added; added test

* added enum value name to exception message

* test for defining enum with multiple identical names moved to test_enum.cpp/py
2018-09-11 10:59:56 +02:00
Wenzel Jakob
35c82c7250 changelog for version 2.2.4 & features targeted for 2.3.0 2018-09-11 10:41:30 +02:00
Jeff VanOss
01839dce8d remove duplicate feature from list (#1476) 2018-09-11 10:39:17 +02:00
Wenzel Jakob
44e39e0de7
fix regression reported by @cyfdecyf in #1454 (#1517) 2018-09-11 09:32:45 +02:00
Michael Goulding
77374a7e5f VS 15.8.0 Preview 4.0 has a bug with alias templates (#1462)
* VS 15.8.0 Preview 4.0 has a bug with alias templates
2018-09-08 16:25:11 +02:00
Axel Huebl
435dbdd114 add_module: allow include as SYSTEM (#1416)
pybind11 headers passed via the `pybind11_add_module` CMake
function can now be included as `SYSTEM` includes (`-isystem`).

This allows to set stricter (or experimental) warnings in
calling projects that might throw otherwise in headers
a user of pybind11 can not influence.
2018-08-29 13:20:11 +02:00
Axel Huebl
3a94561c4d Debug Builds: -DPy_DEBUG (#1438)
builds against a python debug library were unreliable and
could lead to symbol errors during linking.

Setting the `Py_DEBUG` define is necessary when linking
against a debug build:

https://stackoverflow.com/questions/39161202/how-to-work-around-missing-pymodule-create2-in-amd64-win-python35-d-lib

https://docs.python.org/2/c-api/intro.html#debugging-builds

https://docs.python.org/3.6/c-api/intro.html#debugging-builds
2018-08-29 13:18:43 +02:00
Wenzel Jakob
e0f3a766e9
Fixed flake8 error in test_iostream.py 2018-08-29 12:10:48 +02:00
Justin Bassett
2cbafb057f fix detail::pythonbuf::overflow()'s return value to return not_eof(c) (#1479) 2018-08-29 11:48:30 +02:00
Henry Schreiner
3789b4f9fd Update C++ macros for C++17 and MSVC Z mode (#1347) 2018-08-29 00:07:35 +02:00
Matthias Geier
7bb1da969a fix copy-paste error: non-const -> const 2018-08-28 23:23:13 +02:00
Wenzel Jakob
885b5b905a Eigen test suite: don't create a np.matrix 2018-08-28 23:22:55 +02:00
Wenzel Jakob
d4b37a284a added py::ellipsis() method for slicing of multidimensional NumPy arrays
This PR adds a new py::ellipsis() method which can be used in
conjunction with NumPy's generalized slicing support. For instance,
the following is now valid (where "a" is a NumPy array):

py::array b = a[py::make_tuple(0, py::ellipsis(), 0)];
2018-08-28 23:22:55 +02:00
Jason Rhinelander
f7bc18f528 Fix compatibility with catch v2
Catch v2 changed the `run(...)` signature to take a `char *argv[]`,
arguing partly that technically a `char *argv[]` type is the correct
`main()` signature rather than `const char *argv[]`.

Dropping the `const` here doesn't appear to cause any problems with
catch v1 (tested against both the cmake-downloaded 1.9.3 and Debian's
1.12.1 package) so we can follow suit.
2018-07-19 16:12:39 -03:00
Wenzel Jakob
cbd16a8247
stl.h: propagate return value policies to type-specific casters (#1455)
* stl.h: propagate return value policies to type-specific casters

Return value policies for containers like those handled in in 'stl.h'
are currently broken.

The problem is that detail::return_value_policy_override<C>::policy()
always returns 'move' when given a non-pointer/reference type, e.g.
'std::vector<...>'.

This is sensible behavior for custom types that are exposed via
'py::class_<>', but it does not make sense for types that are handled by
other type casters (STL containers, Eigen matrices, etc.).

This commit changes the behavior so that
detail::return_value_policy_override only becomes active when the type
caster derives from type_caster_generic.

Furthermore, the override logic is called recursively in STL type
casters to enable key/value-specific behavior.
2018-07-17 16:56:26 +02:00
Yannick Jadoul
b4719a60d3 Switching deprecated Thread Local Storage (TLS) usage in Python 3.7 to Thread Specific Storage (TSS) (#1454)
* Switching deprecated Thread Local Storage (TLS) usage in Python 3.7 to Thread Specific Storage (TSS)

* Changing Python version from 3.6 to 3.7 for Travis CI, to match brew's version of Python 3

* Introducing PYBIND11_ macros to switch between TLS and TSS API
2018-07-17 16:55:52 +02:00
Boris Dalstein
b30734ee9f Fix typo in doc: build-in -> built-in 2018-07-17 11:28:15 -03:00
Dennis Luxen
221fb1e11e Untangle cast logic to not implicitly require castability (#1442)
The current code requires implicitly that integral types are cast-able to floating point. In case of strongly-typed integrals (e.g. as explained at http://www.ilikebigbits.com/blog/2014/5/6/type-safe-identifiers-in-c) this is not always the case.

This commit uses SFINAE to move the numeric conversions into separate `cast()` implementations to avoid the issue.
2018-07-17 10:48:51 -03:00
Thomas Hrabe
534b756cb3 Minor documentation clarification in numpy.rst (#1356) 2018-06-24 15:41:27 +02:00
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