Skip to content

Commit

Permalink
char * type caster: turn null pointers into a Python None object (
Browse files Browse the repository at this point in the history
  • Loading branch information
huangweiwu authored Oct 9, 2023
1 parent 4dd7459 commit 30a6bac
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/nanobind/nb_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ template <> struct type_caster<char> {

static handle from_cpp(const char *value, rv_policy,
cleanup_list *) noexcept {
if (value == nullptr) {
PyObject* result = Py_None;
Py_INCREF(result);
return result;
}
return PyUnicode_FromString(value);
}

Expand Down

0 comments on commit 30a6bac

Please sign in to comment.