On Sun 17 May 2020 23:46, Ludovic Courtès <l...@gnu.org> writes: > The libunistring functions can take a pre-allocated buffer, but they > always malloc a fresh one if needed. So the best we could do is have a > ‘scm_to_stringn’ variant that takes a buffer, but it’s not guaranteed > that it’ll actually be used. All in all, it seems the added complexity > is not warranted. The worst case of ‘scm_locale_string_data’ is also > rare enough. > > Thoughts?
Interesting. Probably we want to make a public scm_to_{,locale_,utf8_}gc_string{,n} API and use that as a fallback. GC-managed character buffers are less error-prone and probably just as fast. We can mostly avoid the double-copy by inline conversions, as we do with UTF-8. For narrow strings scm_to_gc_stringn can always run iconv in a mode that just calculates output byte size; surely equivalent functionality is available from unistring, also. Andy