Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cleanup casters to avoid unnecessary ref counting #4269

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ struct void_caster {
return false;
}
static handle cast(T, return_value_policy /* policy */, handle /* parent */) {
return none().inc_ref();
return none().release();
}
PYBIND11_TYPE_CASTER(T, const_name("None"));
};
Expand Down Expand Up @@ -291,7 +291,7 @@ class type_caster<void> : public type_caster<void_type> {
if (ptr) {
return capsule(ptr).release();
}
return none().inc_ref();
return none().release();
}

template <typename T>
Expand Down Expand Up @@ -537,7 +537,7 @@ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {

static handle cast(const CharT *src, return_value_policy policy, handle parent) {
if (src == nullptr) {
return pybind11::none().inc_ref();
return pybind11::none().release();
}
return StringCaster::cast(StringType(src), policy, parent);
}
Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct type_caster<std::function<Return(Args...)>> {
template <typename Func>
static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) {
if (!f_) {
return none().inc_ref();
return none().release();
}

auto result = f_.template target<function_type>();
Expand Down
2 changes: 1 addition & 1 deletion include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ struct optional_caster {
template <typename T>
static handle cast(T &&src, return_value_policy policy, handle parent) {
if (!src) {
return none().inc_ref();
return none().release();
}
if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<Value>::policy(policy);
Expand Down