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: Ludovic Courtès
Subject: Re: [PATCH] Avoid malloc/free/dynwind for POSIX subrs that take strings
Date: Fri, 22 May 2020 22:47:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi!

Andy Wingo <address@hidden> skribis:

> 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.

Yeah.

> 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.

Like I wrote, libunistring functions always malloc if the provided
buffer is not large enough to hold the converted string.  So we can’t
really ensure there won’t be any malloc.

Anyway, I’m putting this on hold for now!

Thanks,
Ludo’.



reply via email to

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