nanobind icon indicating copy to clipboard operation
nanobind copied to clipboard

add support for std::wstring following std::string

Open kayama-shift opened this issue 1 year ago • 1 comments

In some cases, wchar_t strings are preferable to UTF-8 strings for non-ascii string. So add support for std::wstring following std::string using provided Python API.

kayama-shift avatar May 05 '24 11:05 kayama-shift

The caster looks good, but this PR will need test coverage to be considered for inclusion.

wjakob avatar May 07 '24 07:05 wjakob

(nvm, I will ad them myself)

wjakob avatar May 22 '24 08:05 wjakob

Doesn't the PyUnicode_AsWideCharString(src.ptr(), &size) call in this conversion leak memory?

PyUnicode_AsWideCharString returns a buffer allocated by PyMem_New (use PyMem_Free() to free it) on success. On error, returns NULL and *size is undefined. Raises a MemoryError if memory allocation is failed.

For context, I'm writing a caster for std::u32string and std::u32string_view types and was thinking of using this std::wstring caster as a reference.

valgur avatar Oct 09 '24 07:10 valgur