Skip to content

Commit 3033bca

Browse files
committed
Resolve comments
1 parent 70000b8 commit 3033bca

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ struct string_caster {
435435
auto nbytes = ssize_t(src.size() * sizeof(CharT));
436436
handle s;
437437
if (policy == return_value_policy::return_as_bytes) {
438-
s = PYBIND11_BYTES_FROM_STRING_AND_SIZE(buffer, nbytes);
438+
s = PyBytes_FromStringAndSize(buffer, nbytes);
439439
} else {
440440
s = decode_utfN(buffer, nbytes);
441441
}

include/pybind11/detail/common.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,13 @@ enum class return_value_policy : uint8_t {
461461
return_value_policy::reference and the keep_alive call policy */
462462
reference_internal,
463463

464-
/** Use this policy to make C++ functions return bytes to Python instead of
465-
str. This is useful when C++ function returns nested type of string,
466-
where we cannot apply `py::bytes` easily. Note that when C++ function
467-
returns string, we don't have to deal ownership for sure, because we
468-
are always copying the C++ string to a new Python str/bytes object.*/
464+
/** With this policy, C++ string types are converted to Python bytes,
465+
instead of str. This is most useful when a C++ function returns a
466+
container-like type with nested C++ string types, and py::bytes cannot
467+
be applied easily. Note that this return_value_policy is not concerned
468+
with lifetime/ownership semantics, like the other policies, but the
469+
purpose of return_as_bytes is certain to be orthogonal, because C++
470+
strings are always copied to Python bytes or str. */
469471
return_as_bytes
470472
};
471473

0 commit comments

Comments
 (0)