mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 09:46:10 +00:00
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:
committed by
Wenzel Jakob
parent
e18bc02fc9
commit
c7ac16bb2e
@@ -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)...));
|
||||
|
||||
Reference in New Issue
Block a user