Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
7d6713a4
Unverified
Commit
7d6713a4
authored
Nov 02, 2020
by
Yannick Jadoul
Committed by
GitHub
Nov 02, 2020
Browse files
Use weakref to clean up captured function object in def_buffer (#2634)
parent
06a54018
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+6
-1
No files found.
include/pybind11/pybind11.h
View file @
7d6713a4
...
@@ -1315,7 +1315,8 @@ public:
...
@@ -1315,7 +1315,8 @@ public:
return
*
this
;
return
*
this
;
}
}
template
<
typename
Func
>
class_
&
def_buffer
(
Func
&&
func
)
{
template
<
typename
Func
>
class_
&
def_buffer
(
Func
&&
func
)
{
struct
capture
{
Func
func
;
};
struct
capture
{
Func
func
;
};
auto
*
ptr
=
new
capture
{
std
::
forward
<
Func
>
(
func
)
};
auto
*
ptr
=
new
capture
{
std
::
forward
<
Func
>
(
func
)
};
install_buffer_funcs
([](
PyObject
*
obj
,
void
*
ptr
)
->
buffer_info
*
{
install_buffer_funcs
([](
PyObject
*
obj
,
void
*
ptr
)
->
buffer_info
*
{
...
@@ -1324,6 +1325,10 @@ public:
...
@@ -1324,6 +1325,10 @@ public:
return
nullptr
;
return
nullptr
;
return
new
buffer_info
(((
capture
*
)
ptr
)
->
func
(
caster
));
return
new
buffer_info
(((
capture
*
)
ptr
)
->
func
(
caster
));
},
ptr
);
},
ptr
);
weakref
(
m_ptr
,
cpp_function
([
ptr
](
handle
wr
)
{
delete
ptr
;
wr
.
dec_ref
();
})).
release
();
return
*
this
;
return
*
this
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment