guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Avoid malloc/free/dynwind for POSIX subrs that take strings


From: Andy Wingo
Subject: Re: [PATCH] Avoid malloc/free/dynwind for POSIX subrs that take strings
Date: Mon, 18 May 2020 08:50:15 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

On Sun 17 May 2020 23:46, Ludovic Courtès <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]