File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -1315,7 +1315,8 @@ class class_ : public detail::generic_type {
1315
1315
return *this ;
1316
1316
}
1317
1317
1318
- template <typename Func> class_& def_buffer (Func &&func) {
1318
+ template <typename Func>
1319
+ class_& def_buffer (Func &&func) {
1319
1320
struct capture { Func func; };
1320
1321
auto *ptr = new capture { std::forward<Func>(func) };
1321
1322
install_buffer_funcs ([](PyObject *obj, void *ptr) -> buffer_info* {
@@ -1324,6 +1325,10 @@ class class_ : public detail::generic_type {
1324
1325
return nullptr ;
1325
1326
return new buffer_info (((capture *) ptr)->func (caster));
1326
1327
}, ptr);
1328
+ weakref (m_ptr, cpp_function ([ptr](handle wr) {
1329
+ delete ptr;
1330
+ wr.dec_ref ();
1331
+ })).release ();
1327
1332
return *this ;
1328
1333
}
1329
1334
You can’t perform that action at this time.
0 commit comments