Skip to content

Commit a5729a3

Browse files
committed
Zero-state unique_function_record deleter object
1 parent 247d61a commit a5729a3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

include/pybind11/pybind11.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,16 @@ class cpp_function : public function {
114114
object name() const { return attr("__name__"); }
115115

116116
protected:
117-
using unique_function_record = std::unique_ptr<detail::function_record, void (*)(detail::function_record *)>;
117+
struct InitializingFunctionRecordDeleter {
118+
// `destruct(function_record, false)`: `initialize_generic` copies strings and
119+
// takes care of cleaning up in case of exceptions. So pass `false` to `free_strings`.
120+
void operator()(detail::function_record * rec) { destruct(rec, false); }
121+
};
122+
using unique_function_record = std::unique_ptr<detail::function_record, InitializingFunctionRecordDeleter>;
118123

119124
/// Space optimization: don't inline this frequently instantiated fragment
120125
PYBIND11_NOINLINE unique_function_record make_function_record() {
121-
// `destruct(function_record, false)`: `initialize_generic` copies strings and
122-
// takes care of cleaning up in case of exceptions. So set `free_srings` to `false`.
123-
auto destruct_no_free_strings = [](detail::function_record * rec) { destruct(rec, false); };
124-
return unique_function_record(new detail::function_record(), destruct_no_free_strings);
126+
return unique_function_record(new detail::function_record());
125127
}
126128

127129
/// Special internal constructor for functors, lambda functions, etc.

0 commit comments

Comments
 (0)