Skip to content

Commit 9d7f7a3

Browse files
committed
fixed Py_None reference couting
1 parent 5812d64 commit 9d7f7a3

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/pybind11/cast.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class type_caster_generic {
185185
const void *existing_holder = nullptr) {
186186
void *src = const_cast<void *>(_src);
187187
if (src == nullptr)
188-
return none();
188+
return none().inc_ref();
189189

190190
auto &internals = get_internals();
191191

@@ -414,7 +414,7 @@ template <> class type_caster<void_type> {
414414
public:
415415
bool load(handle, bool) { return false; }
416416
static handle cast(void_type, return_value_policy /* policy */, handle /* parent */) {
417-
return none();
417+
return none().inc_ref();
418418
}
419419
PYBIND11_TYPE_CASTER(void_type, _("None"));
420420
};
@@ -452,7 +452,7 @@ template <> class type_caster<void> : public type_caster<void_type> {
452452
if (ptr)
453453
return capsule(ptr).release();
454454
else
455-
return none();
455+
return none().inc_ref();
456456
}
457457

458458
template <typename T> using cast_op_type = void*&;
@@ -569,7 +569,7 @@ template <> class type_caster<char> : public type_caster<std::string> {
569569
}
570570

571571
static handle cast(const char *src, return_value_policy /* policy */, handle /* parent */) {
572-
if (src == nullptr) return none();
572+
if (src == nullptr) return none().inc_ref();
573573
return PyUnicode_FromString(src);
574574
}
575575

@@ -592,7 +592,7 @@ template <> class type_caster<wchar_t> : public type_caster<std::wstring> {
592592
}
593593

594594
static handle cast(const wchar_t *src, return_value_policy /* policy */, handle /* parent */) {
595-
if (src == nullptr) return none();
595+
if (src == nullptr) return none().inc_ref();
596596
return PyUnicode_FromWideChar(src, (ssize_t) wcslen(src));
597597
}
598598

include/pybind11/functional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ template <typename Return, typename... Args> struct type_caster<std::function<Re
6262
template <typename Func>
6363
static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) {
6464
if (!f_)
65-
return none();
65+
return none().inc_ref();
6666

6767
auto result = f_.template target<Return (*)(Args...)>();
6868
if (result)

0 commit comments

Comments
 (0)