Skip to content

Commit 5febe3a

Browse files
committed
Clarify rvalue reference to unique_ptr parameter in initialize_generic
1 parent a5729a3 commit 5febe3a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/pybind11/pybind11.h

+3
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class cpp_function : public function {
256256
/// Register a function call with Python (generic non-templated code goes here)
257257
void initialize_generic(unique_function_record &&unique_rec, const char *text,
258258
const std::type_info *const *types, size_t args) {
259+
// Do NOT receive `unique_rec` by value. If this function fails to move the unique_ptr, then
260+
// we do not want this to destuct the pointer. `initialize` (the caller) still relies on the
261+
// pointee being alive after this call. Only move if a `capsule` is going to keep it alive.
259262
auto rec = unique_rec.get();
260263

261264
// Keep track of strdup'ed strings, and clean them up as long as the function's capsule

0 commit comments

Comments
 (0)