| 330 | |
| 331 | template <typename OutFn, typename Return, typename... Args> |
| 332 | std::function<OutFn> BindFunction(Return (*unbound)(PyObject*, Args...), |
| 333 | PyObject* bound_arg) { |
| 334 | using Fn = BoundFunction<Return(PyObject*, Args...)>; |
| 335 | |
| 336 | static_assert(std::is_same<typename Fn::Bound, OutFn>::value, |
| 337 | "requested bound function of unsupported type"); |
| 338 | |
| 339 | Py_XINCREF(bound_arg); |
| 340 | auto bound_fn = std::make_shared<Fn>(unbound, bound_arg); |
| 341 | return |
| 342 | [bound_fn](Args... args) { return bound_fn->Invoke(std::forward<Args>(args)...); }; |
| 343 | } |
| 344 | |
| 345 | // A temporary conversion of a Python object to a bytes area. |
| 346 | struct PyBytesView { |