Skip to content

Commit 2ce76f7

Browse files
authored
Cleanup casters to release none() to avoid ref counting (#4269)
1 parent 36ccb08 commit 2ce76f7

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

include/pybind11/cast.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ struct void_caster {
248248
return false;
249249
}
250250
static handle cast(T, return_value_policy /* policy */, handle /* parent */) {
251-
return none().inc_ref();
251+
return none().release();
252252
}
253253
PYBIND11_TYPE_CASTER(T, const_name("None"));
254254
};
@@ -291,7 +291,7 @@ class type_caster<void> : public type_caster<void_type> {
291291
if (ptr) {
292292
return capsule(ptr).release();
293293
}
294-
return none().inc_ref();
294+
return none().release();
295295
}
296296

297297
template <typename T>
@@ -537,7 +537,7 @@ struct type_caster<CharT, enable_if_t<is_std_char_type<CharT>::value>> {
537537

538538
static handle cast(const CharT *src, return_value_policy policy, handle parent) {
539539
if (src == nullptr) {
540-
return pybind11::none().inc_ref();
540+
return pybind11::none().release();
541541
}
542542
return StringCaster::cast(StringType(src), policy, parent);
543543
}

include/pybind11/functional.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct type_caster<std::function<Return(Args...)>> {
110110
template <typename Func>
111111
static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) {
112112
if (!f_) {
113-
return none().inc_ref();
113+
return none().release();
114114
}
115115

116116
auto result = f_.template target<function_type>();

include/pybind11/stl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ struct optional_caster {
311311
template <typename T>
312312
static handle cast(T &&src, return_value_policy policy, handle parent) {
313313
if (!src) {
314-
return none().inc_ref();
314+
return none().release();
315315
}
316316
if (!std::is_lvalue_reference<T>::value) {
317317
policy = return_value_policy_override<Value>::policy(policy);

0 commit comments

Comments
 (0)