From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: RE: [PATCH] Make get-bytevector-all suspendable. Date: Sat, 1 Jun 2024 11:40:40 +0200 Message-ID: <20240601114041.W9gg2C00G4Gw7VF069ghiP@michel.telenet-ops.be> References: <20230720140103.23221-1-mail@cbaines.net> <87bk4lqb85.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_DD4E1E0A-7685-4C29-8239-88D95DE234DA_" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5318"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "guile-devel@gnu.org" To: =?utf-8?Q?Ludovic_Court=C3=A8s?= , Christopher Baines Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sat Jun 01 11:46:22 2024 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 1sDLJd-0001GA-Mg for guile-devel@m.gmane-mx.org; Sat, 01 Jun 2024 11:46:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDLJA-0002VZ-M1; Sat, 01 Jun 2024 05:45:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sDLJ9-0002TY-1s for guile-devel@gnu.org; Sat, 01 Jun 2024 05:45:51 -0400 Original-Received: from michel.telenet-ops.be ([2a02:1800:110:4::f00:18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sDLJ6-00085b-6Z for guile-devel@gnu.org; Sat, 01 Jun 2024 05:45:50 -0400 Original-Received: from [IPv6:2a02:1811:8c0e:ef00:a025:1d00:d6fa:6b8e] ([IPv6:2a02:1811:8c0e:ef00:a025:1d00:d6fa:6b8e]) by michel.telenet-ops.be with bizsmtp id W9gg2C00G4Gw7VF069ghiP; Sat, 01 Jun 2024 11:40:41 +0200 Importance: normal X-Priority: 3 In-Reply-To: <87bk4lqb85.fsf@gnu.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=telenet.be; s=r24; t=1717234841; bh=661Q2garwPUXl3oAnhjuuxXoomMD5ym3NfhwpN8ziZo=; h=To:Cc:From:Subject:Date:In-Reply-To:References; b=ils75mdfC/D5TcRVPqwojNVRttzQygUOcjrqrAGK4hny5UYiookoyS4HTRp1851ic 72FeAjwhTT+/yxZb5ndwz9vvpEBCCQWYOk4j4MzVfPTB/xe9ecd0mGV5EUP1Ffumvv AzK+Kc7PlrAdkbll5gSL8AdblVRs+AmuyYa/UqVcoamNFMRch3GUJVlOisiJyATR3G Bjh/pDsoas1QoxIvkhDAA3TuTAgdPB08mwXSzNbcNHZD/R0zjQntUswBbQlFppPkTI mR14qZw5wXSjAyXa8E2t3oeKIiUdpPnRmcQMmUvPUTJFYNJ0VhusVQtCH/iy0HsJN9 tRcCdsZQvvz7w== Received-SPF: pass client-ip=2a02:1800:110:4::f00:18; envelope-from=maximedevos@telenet.be; helo=michel.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22425 Archived-At: --_DD4E1E0A-7685-4C29-8239-88D95DE234DA_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" >Given that =E2=80=98get-bytevector-n!=E2=80=99 already has a variant in suspendable-ports.scm, my preference would be to rewrite =E2=80=98get-bytevector-all=E2=80=99 in Scheme (patch attached). That way,= it would naturally be suspendable. (It=E2=80=99s also in line with the general stra= tegy of moving things to Scheme.) It currently is difficult to write a correct implementation of get-bytevect= or-all in pure Scheme, because =E2=80=98get-bytevector-all=E2=80=99 needs t= o return a _fresh_ bytevector and could return twice (e.g. in case of syste= m-async-mark + call-with-prompt shenanigans). I think the proposed implemen= tation is incorrect in this way. Could be resolved with call-with-blocked-asyncs, but given the title of the= patch, that=E2=80=99s against the point. However, given the sequential and stateful nature of ports, I don=E2=80=99t= think it=E2=80=99s useful to implement support for these =E2=80=98return t= wice=E2=80=99 situations, so I think it would be best to simply adjust the = documentation to disallow this situation. Since it is not unique to get-bytevector-all, maybe it could be mentioned i= n https://www.gnu.org/software/guile/manual/html_node/Ports.html that it is= n=E2=80=99t allowed to put any non-pure operation (where we include allocat= ions as a side-effect, e.g. for open-input-bytevector etc, ) related to por= ts in such a situations? +(define (get-bytevector-all port) + (define %initial-length 4096) + + (let read-loop ((total 0) + (result-length %initial-length) + (result (make-bytevector %initial-length))) I sense a lack of tests for the test suite ... Also, to avoid avoidable allocations and copying, it would be nice if %init= ial-length could be overridden (optional #:initial-length keyword argument)= , in case the user has a better guess available. Best regards, Maxime Devos --_DD4E1E0A-7685-4C29-8239-88D95DE234DA_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

>G= iven that =E2=80=98get-bytevector-n!=E2=80=99 already has a variant in

<= p class=3DMsoNormal>suspendable-ports.scm, my preference would be to rewrit= e

=E2=80=98get-bytevector-all=E2=80=99 in Scheme (p= atch attached).=C2=A0 That way, it would

naturally = be suspendable.=C2=A0 (It=E2=80=99s also in line with the general strategy<= /p>

of moving things to Scheme.)

 

It currently is difficult to wr= ite a correct implementation of get-bytevector-all in pure Scheme, because = =E2=80=98get-bytevector-all=E2=80=99 needs to return a _fresh_ bytev= ector and could return twice (e.g. in case of system-async-mark + call-with= -prompt shenanigans). I think the proposed implementation is incorrect in t= his way.

 

= Could be resolved with call-with-blocked-asyncs, but given the title of the= patch, that=E2=80=99s against the point.

&nbs= p;

However, given the sequential and stateful= nature of ports, I don=E2=80=99t think it=E2=80=99s useful to implement su= pport for these =E2=80=98return twice=E2=80=99 situations, so I think it wo= uld be best to simply adjust the documentation to disallow this situation.<= /p>

 

Since it = is not unique to get-bytevector-all, maybe it could be mentioned in https:/= /www.gnu.org/software/guile/manual/html_node/Ports.html that it isn=E2= =80=99t allowed to put any non-pure operation (where we include allocations= as a side-effect, e.g. for open-input-bytevector etc, ) related to ports i= n such a situations?

 

+(define (get-bytevector-all port)

+= =C2=A0 (define %initial-length 4096)

+

+=C2=A0 (let read-loop ((total 0)

+=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (result-length %initial-length)

+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (result (make-bytevector %initial-leng= th)))

 

I s= ense a lack of tests for the test suite ...

Also, t= o avoid avoidable allocations and copying, it would be nice if %initial-len= gth could be overridden (optional #:initial-length keyword argument), in ca= se the user has a better guess available.

&nbs= p;

Best regards,

Maxi= me Devos

= --_DD4E1E0A-7685-4C29-8239-88D95DE234DA_--