mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
Cleanup casters to release none() to avoid ref counting (#4269)
This commit is contained in:
parent
36ccb08b0d
commit
2ce76f7833
@ -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:
|
|||||||
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:
|
|||||||
|
|
||||||
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:
|
|||||||
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 {
|
|||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user