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
2ce76f78
Unverified
Commit
2ce76f78
authored
Oct 21, 2022
by
Aaron Gokaslan
Committed by
GitHub
Oct 21, 2022
Browse files
Cleanup casters to release none() to avoid ref counting (#4269)
parent
36ccb08b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
5 deletions
+5
-5
include/pybind11/cast.h
include/pybind11/cast.h
+3
-3
include/pybind11/functional.h
include/pybind11/functional.h
+1
-1
include/pybind11/stl.h
include/pybind11/stl.h
+1
-1
No files found.
include/pybind11/cast.h
View file @
2ce76f78
...
@@ -248,7 +248,7 @@ public:
...
@@ -248,7 +248,7 @@ public:
return
false
;
return
false
;
}
}
static
handle
cast
(
T
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
T
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
return
none
().
inc_ref
();
return
none
().
release
();
}
}
PYBIND11_TYPE_CASTER
(
T
,
const_name
(
"None"
));
PYBIND11_TYPE_CASTER
(
T
,
const_name
(
"None"
));
};
};
...
@@ -291,7 +291,7 @@ public:
...
@@ -291,7 +291,7 @@ public:
if
(
ptr
)
{
if
(
ptr
)
{
return
capsule
(
ptr
).
release
();
return
capsule
(
ptr
).
release
();
}
}
return
none
().
inc_ref
();
return
none
().
release
();
}
}
template
<
typename
T
>
template
<
typename
T
>
...
@@ -537,7 +537,7 @@ public:
...
@@ -537,7 +537,7 @@ public:
static
handle
cast
(
const
CharT
*
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
const
CharT
*
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
src
==
nullptr
)
{
if
(
src
==
nullptr
)
{
return
pybind11
::
none
().
inc_ref
();
return
pybind11
::
none
().
release
();
}
}
return
StringCaster
::
cast
(
StringType
(
src
),
policy
,
parent
);
return
StringCaster
::
cast
(
StringType
(
src
),
policy
,
parent
);
}
}
...
...
include/pybind11/functional.h
View file @
2ce76f78
...
@@ -110,7 +110,7 @@ public:
...
@@ -110,7 +110,7 @@ public:
template
<
typename
Func
>
template
<
typename
Func
>
static
handle
cast
(
Func
&&
f_
,
return_value_policy
policy
,
handle
/* parent */
)
{
static
handle
cast
(
Func
&&
f_
,
return_value_policy
policy
,
handle
/* parent */
)
{
if
(
!
f_
)
{
if
(
!
f_
)
{
return
none
().
inc_ref
();
return
none
().
release
();
}
}
auto
result
=
f_
.
template
target
<
function_type
>();
auto
result
=
f_
.
template
target
<
function_type
>();
...
...
include/pybind11/stl.h
View file @
2ce76f78
...
@@ -311,7 +311,7 @@ struct optional_caster {
...
@@ -311,7 +311,7 @@ struct optional_caster {
template
<
typename
T
>
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
!
src
)
{
if
(
!
src
)
{
return
none
().
inc_ref
();
return
none
().
release
();
}
}
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
{
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
{
policy
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
policy
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
...
...
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