Commit 251516bc by Aaron Gokaslan Committed by Henry Schreiner

Cleanup casters to release none() to avoid ref counting (#4269)

parent a8f21107
...@@ -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);
} }
......
...@@ -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>();
......
...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment