Add py::reinterpret_borrow<T>()/steal<T>() for low-level unchecked casts

The pytype converting constructors are convenient and safe for user
code, but for library internals the additional type checks and possible
conversions are sometimes not desired. `reinterpret_borrow<T>()` and
`reinterpret_steal<T>()` serve as the low-level unsafe counterparts
of `cast<T>()`.

This deprecates the `object(handle, bool)` constructor.

Renamed `borrowed` parameter to `is_borrowed` to avoid shadowing
warnings on MSVC.
This commit is contained in:
Dean Moldovan
2016-10-28 03:08:15 +02:00
committed by Wenzel Jakob
parent e18bc02fc9
commit c7ac16bb2e
8 changed files with 178 additions and 136 deletions

View File

@@ -36,7 +36,7 @@ public:
captured variables), in which case the roundtrip can be avoided.
*/
if (PyCFunction_Check(src_.ptr())) {
capsule c(PyCFunction_GetSelf(src_.ptr()), true);
auto c = reinterpret_borrow<capsule>(PyCFunction_GetSelf(src_.ptr()));
auto rec = (function_record *) c;
using FunctionType = Return (*) (Args...);
@@ -47,7 +47,7 @@ public:
}
}
object src(src_, true);
auto src = reinterpret_borrow<object>(src_);
value = [src](Args... args) -> Return {
gil_scoped_acquire acq;
object retval(src(std::move(args)...));