From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?utf-8?Q?Ludovic_Court=C3=A8s?= Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Avoid malloc/free/dynwind for POSIX subrs that take strings Date: Fri, 22 May 2020 22:47:20 +0200 Message-ID: <87d06v8zon.fsf@gnu.org> References: <87h7x2qbxa.fsf@inria.fr> <87a72m26bv.fsf@igalia.com> <871rninskn.fsf@gnu.org> <87ftbxwxco.fsf@igalia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="80906"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri May 22 22:47:34 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jcEZp-000KvH-Vz for guile-devel@m.gmane-mx.org; Fri, 22 May 2020 22:47:33 +0200 Original-Received: from localhost ([::1]:45254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcEZp-0004VG-03 for guile-devel@m.gmane-mx.org; Fri, 22 May 2020 16:47:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcEZf-0004Uh-9S for guile-devel@gnu.org; Fri, 22 May 2020 16:47:23 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:56872) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcEZe-0007nL-IB; Fri, 22 May 2020 16:47:22 -0400 Original-Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=51048 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jcEZd-00026U-U3; Fri, 22 May 2020 16:47:22 -0400 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 4 Prairial an 228 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu In-Reply-To: <87ftbxwxco.fsf@igalia.com> (Andy Wingo's message of "Mon, 18 May 2020 08:50:15 +0200") X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20528 Archived-At: Hi! Andy Wingo skribis: > On Sun 17 May 2020 23:46, Ludovic Court=C3=A8s 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 >> =E2=80=98scm_to_stringn=E2=80=99 variant that takes a buffer, but it=E2= =80=99s not guaranteed >> that it=E2=80=99ll actually be used. All in all, it seems the added com= plexity >> is not warranted. The worst case of =E2=80=98scm_locale_string_data=E2= =80=99 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=E2=80= =99t really ensure there won=E2=80=99t be any malloc. Anyway, I=E2=80=99m putting this on hold for now! Thanks, Ludo=E2=80=99.