Commit Graph

916 Commits

Author SHA1 Message Date
Borja Zarco
b2fdfd1228 Avoid use of lambda to work around a clang bug. (#1883)
Clang has a bug [1] in x86 Windows that is exposed by the use of lambdas with "unforwardable" prototypes. The error is "error: cannot compile this forwarded non-trivially copyable parameter yet", and the message was introduced in [2] (used to be an assertion).

[1] https://llvm.org/bugs/show_bug.cgi?id=28299
[2] feb1567e07
2019-08-15 13:42:43 +02:00
Saran Tunyasuvunakool
bdf1a2cc34 In internals.h, only look at _DEBUG when compiling with MSVC. (#1855)
* In internals.h, only look at _DEBUG when compiling with MSVC.

(_DEBUG is a MSVC-specific macro.)
2019-08-13 22:00:47 +02:00
Pauli Virtanen
c9d32a81f4 numpy: fix refcount leak to dtype singleton (#1860)
PyArray_DescrFromType returns a new reference, not borrowed one
2019-07-27 11:35:32 +02:00
Eric Cousineau
4a3464fd88 numpy: Provide concrete size aliases
Test for dtype checks now succeed without warnings
2019-07-23 13:17:20 +02:00
phil-zxx
c6b699d9c2 Added ability to convert from datetime.date to system_clock::time_point (#1848)
* Added ability to convert from Python datetime.date and datetime.time to C++ system_clock::time_point
2019-07-19 11:28:48 +02:00
Jeremy Maitin-Shepard
a3f4a0e8ab Add support for __await__, __aiter__, and __anext__ protocols (#1842) 2019-07-18 09:02:35 +02:00
Nathan
9b3fb05326 Allow Windows.h min/max to coexist with pybind11 (#1847)
* Protect std::min/max functions from windows.h min/max
Removed check for windows min/max
2019-07-18 09:01:50 +02:00
Wenzel Jakob
b2c4ff6052 renamed local gil_scoped_acquire to gil_scoped_acquire_local to avoid ambiguity 2019-07-15 17:29:13 +02:00
Saran Tunyasuvunakool
b60fd233fa Make sure detail::get_internals acquires the GIL before making Python calls. (#1836)
This is only necessary if `get_internals` is called for the first time in a given module when the running thread is in a GIL-released state.

Fixes #1364
2019-07-15 16:47:02 +02:00
Thomas Peters
dffe869dba quiet clang warning by adding default move ctor (#1821) 2019-07-15 16:16:14 +02:00
Igor Socec
a301c5add8 Dtype field ordering for NumPy 1.14 (#1837)
* Test dtype field order in numpy dtype tests

When running tests with NumPy 1.14 or later this test exposes the
"invalid buffer descriptor" error reported in #1274.

* Create dtype_ptr with ordered fields
2019-07-15 13:31:03 +02:00
Toru Niina
74d335a535 Replace a usage of C++14 language features with C++11 code (#1833) 2019-07-10 10:13:56 +02:00
Wenzel Jakob
8b90b1da62 error_already_set: acquire GIL one line earlier (fixes #1779) 2019-07-06 14:52:32 +02:00
Wenzel Jakob
a1b71df137 fix issue #1804 (warning about redefined macros) 2019-06-19 10:48:42 +02:00
Alexander Gagarin
b3bf248eec Fix casting of time points with non-system-clock duration with VS (#1748)
* Fix casting of time points with non-system-clock duration on Windows

Add explicit `time_point_cast` to time point with duration of system
clock. Fixes Visual Studio compile error.

* Add test case for custom time points casting
2019-06-13 09:17:10 +02:00
Wenzel Jakob
64f2a5f8e6 begin work on v2.3.1 2019-06-12 21:03:40 +02:00
sizmailov
21c3911bd3 add signed overload for py::slice::compute 2019-06-11 23:28:58 +02:00
Chris Rusby
22859bb8fc Support more natural syntax for vector extend 2019-06-11 23:28:58 +02:00
Roland Dreier
1aa8dd1745 Fix assertion failure for unions (#1685) (#1709)
In def_readonly and def_readwrite, there is an assertion that the member comes
from the class or a base class:

    static_assert(std::is_base_of<C, type>::value, "...");

However, if C and type are the same type, is_base_of will still only be true
if they are the same _non-union_ type.  This means we can't define accessors
for the members of a union type because of this assertion.

Update the assertion to test

    std::is_same<C, type>::value || std::is_base_of<C, type>::value

which will allow union types, or members of base classes.

Also add a basic unit test for accessing unions.
2019-06-11 23:28:58 +02:00
Alexander Gagarin
0071a3feb0 Fix async Python functors invoking from multiple C++ threads (#1587) (#1595)
* Fix async Python functors invoking from multiple C++ threads (#1587)

Ensure GIL is held during functor destruction.

* Add async Python callbacks test that runs in separate Python thread
2019-06-11 23:28:58 +02:00
Henry Schreiner
047ce8c452 Fix iostream when used with nogil (#1368) 2019-06-11 23:28:58 +02:00
Omar Awile
95f750a87d Add optional buffer size to pythonbuf::d_buffer constructor (#1687)
In some cases the user of pythonbuf needs to allocate the internal
buffer to a specific size e.g. for performance or to enable synchronous
writes to the buffer.
By changing `pythonbuf::d_buffer` to be dynamically allocated we can now
enable these use-cases while still providing the default behavior of
allocating a 1024 byte internal buffer (through a default parameter).
2019-06-11 23:28:58 +02:00
Axel Huebl
38f408fccd value_and_holder: uninit members (#1660)
fix some uninitialized members in `value_and_holder` for
some of the constructurs.

Found with coverity in a downstream project.
2019-06-11 23:28:58 +02:00
Jeff VanOss
77ef03d5b1 compile time check that properties have no py:arg values (#1524) 2019-06-11 14:25:35 +02:00
Yannick Jadoul
d23c821b20 Make static member functions, added with def_static, staticmethod descriptor instances (#1732) 2019-06-11 10:59:57 +02:00
Axel Huebl
a2cdd0b915 dict_readonly: member init (#1661)
fix missing member initialization in pytypes: read-only dict.

Found with coverity in a downstream project.
2019-06-10 22:19:41 +02:00
Axel Huebl
1c627c9ec0 pybind11_getbuffer: useless safe nullptr check (#1664)
Alternative implementation for #1657: if
we know that `obj` is never a `nullptr` [1], we should
not `nullptr`-check it *after* already dereferencing it.

[1] https://github.com/pybind/pybind11/pull/1657#issuecomment-452090058
2019-06-10 22:18:11 +02:00
Jeffrey Quesnelle
f93cd0aa72 PYBIND11_TLS_REPLACE_VALUE should use macro argument value in Python 3.7+ (#1683) 2019-06-10 22:13:35 +02:00
Ivor Wanders
2b045757b5 Improve documentation related to inheritance. (#1676)
* Adds section to the reference.
* Adds section to advanced classes page describing how to use `get_overload`.
2019-06-10 22:12:28 +02:00
Axel Huebl
9424d5d277 type_record: Uninit Member (#1658)
Fix an uninitialized member in `type_record`.

Found with coverity in a downstream project.
2019-06-10 22:02:40 +02:00
Jörg Kreuzberger
69dc380c0d #1208 Handle forced unwind exception (e.g. during pthread termination)
* #1208 Bugfix thread kill wihile running pybind11 module

* #1208 Bugfix missing space after catch
2019-06-10 22:00:55 +02:00
Steven Johnson
4ddf7c402d Add missing includes for better Bazel compatibility (#1255)
Bazel has a "strict" build model that requires all C++ header files be compilable on their own, and thus must explicitly #include all headers they require (even if de facto header inclusion order means they'd get them "for free"). This adds a couple of headers that are needed (but missing) by this model.
2019-06-10 21:54:56 +02:00
Blake Thompson
30c0352348 Added __contains__ to stl bindings for maps (#1767)
* Added __contains__ to stl bindings for maps
2019-06-10 21:01:11 +02:00
Yannick Jadoul
97784dad3e [BUGFIX] Fixing pybind11::error_already_set.matches to also work with exception subclasses (#1715)
* Fixing order of arguments in call to PyErr_GivenExceptionMatches in pybind11::error_already_set.matches

* Added tests on error_already_set::matches fix for exception base classes
2019-05-12 23:35:49 +02:00
martinRenou
35045eeef8 Add getters for exception type, value and traceback (#1641) 2019-05-03 14:32:28 +02:00
Henry Schreiner
9bb3313162 Fixing warnings about conversions in GCC 7+ (#1753) 2019-04-07 10:38:10 +02:00
Henry Schreiner
ae951ca085 CI fixes (#1744)
* Fix warning that not including a cmake source or build dir will be a fatal error (it is now on newest CMakes)
    * Fixes appveyor
* Travis uses CMake 3.9 for more than a year now
* Travis dropped sudo: false in December
* Dropping Sphinx 2
- clang7: Suppress self-assign warnings; fix missing virtual dtors
- pypy:
  - Keep old version (newer stuff breaks)
  - Pin packages to extra index for speed
- travis:
  - Make docker explicit; remove docker if not needed
  - Make commands more verbose (for debugging / repro)
  - Make Ubuntu dist explicit per job
- Fix Windows
- Add names to travis
2019-04-06 19:09:39 +02:00
Wenzel Jakob
ccbe68b084 added binding delattr() -> PyObject_DelAttr analogous to hasattr() 2019-02-04 16:24:07 +01:00
Boris Staletic
0ca6867e8e Avoid Visual Studio 2017 15.9.4 ICE 2019-01-03 12:05:01 +01:00
Borja Zarco
e2b884c33b Use PyGILState_GetThisThreadState when using gil_scoped_acquire. (#1211)
This avoids GIL deadlocking when pybind11 tries to acquire the GIL in a thread that already acquired it using standard Python API (e.g. when running from a Python thread).
2018-12-01 22:47:40 +09:00
Baljak
81da9888c7 Fix Intel C++ compiler warning on Windows (#1608) 2018-11-20 23:22:02 +01:00
voxmea
17983e7425 Adds type_caster support for std::deque. (#1609)
* Adds std::deque to the types supported by list_caster in stl.h.
* Adds a new test_deque test in test_stl.{py,cpp}.
* Updates the documentation to include std::deque as a default
  supported type.
2018-11-16 06:45:19 +01:00
Karl Haubenwallner
e9d6e87949 Added a debug flag to the PYBIND11_INTERNALS_VERSION (#1549) 2018-11-11 20:49:33 +01:00
Trevor Laughlin
63c2a972fe Enable unique_ptr holder with mixed Deleters between base and derived types (#1353)
* Check default holder

-Recognize "std::unique_ptr<T, D>" as a default holder even if "D" doesn't match between base and derived holders

* Add test for unique_ptr<T, D> change
2018-11-11 19:36:55 +01:00
Wenzel Jakob
cea42467b0
fix py::cast<void *> (#1605)
Pybind11 provides a cast operator between opaque void* pointers on the
C++ side and capsules on the Python side. The py::cast<void *>
expression was not aware of this possibility and incorrectly triggered a
compile-time assertion ("Unable to cast type to reference: value is
local to type caster") that is now fixed.
2018-11-11 19:32:09 +01:00
Wenzel Jakob
e2eca4f8f8
Support C++17 aligned new statement (#1582)
* Support C++17 aligned new statement

This patch makes pybind11 aware of nonstandard alignment requirements in
bound types and passes on this information to C++17 aligned 'new'
operator. Pre-C++17, the behavior is unchanged.
2018-11-09 20:14:53 +01:00
Wenzel Jakob
adc2cdd5c4
fixed regression in STL type caster RVPs (fixes #1561) (#1603) 2018-11-09 20:12:46 +01:00
Wenzel Jakob
9f73060cc7
std::array<> caster: support arbitrary sequences (#1602)
This PR brings the std::array<> caster in sync with the other STL type
casters: to accept an arbitrary sequence as input (rather than a list,
which is too restrictive).
2018-11-09 12:32:48 +01:00
Michał Wawrzyniec Urbańczyk
978d439e92 Add PYBIND11_ prefix to the THROW macro to prevent name collisions. (#1578) 2018-11-03 13:20:08 +01:00
Josh Kelley
741576dd11 Update documentation for initialize_interpreter (#1584)
Add a detailed link to Python 3 documentation.  Add a caveat about
the program terminating if initializing the interpreter fails.
2018-11-01 02:10:11 +01:00