unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Fix make-custom-port in case encoding is #f
@ 2025-02-02 19:51 H. Müller
  2025-02-02 20:01 ` Maxime Devos
  0 siblings, 1 reply; 2+ messages in thread
From: H. Müller @ 2025-02-02 19:51 UTC (permalink / raw)
  To: guile-devel

From 72b85f8e6a369e6aef4c6bd6bb233c0cacb80b03 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hannes=20M=C3=BCller?= <>
Date: Sat, 21 Dec 2024 16:55:13 +0100
Subject: [PATCH] Fix make-custom-port in case encoding is #f

* module/ice-9/custom-ports.scm (make-custom-port): Code fails if
(fluid-ref %default-port-encoding) returns #f. In fact this was the
case why readline support on MSYS2 failed for guile 3.0.10, ref.
https://github.com/msys2/MSYS2-packages/issues/5079
But later used canonicalize-encoding is prepared to handle #f for
encoding. So allow encoding to also handle this case.
---
 module/ice-9/custom-ports.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/module/ice-9/custom-ports.scm b/module/ice-9/custom-ports.scm
index 6010fd94f..bc9de8f64 100644
--- a/module/ice-9/custom-ports.scm
+++ b/module/ice-9/custom-ports.scm
@@ -127,7 +127,9 @@
           (id "custom-port")
           (print (make-default-print #:id id))
           (truncate default-truncate)
-          (encoding (string->symbol (fluid-ref %default-port-encoding)))
+          (encoding (if (string? (fluid-ref %default-port-encoding))
+                        (string->symbol (fluid-ref %default-port-encoding))
+                        (fluid-ref %default-port-encoding)))
           (conversion-strategy (fluid-ref %default-port-conversion-strategy))
           (close-on-gc? #f))
   "Create a custom port whose behavior is determined by the methods passed
--
2.45.2




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix make-custom-port in case encoding is #f
  2025-02-02 19:51 [PATCH] Fix make-custom-port in case encoding is #f H. Müller
@ 2025-02-02 20:01 ` Maxime Devos
  0 siblings, 0 replies; 2+ messages in thread
From: Maxime Devos @ 2025-02-02 20:01 UTC (permalink / raw)
  To: H. Müller, guile-devel

On 2/02/2025 20:51, H. Müller wrote:
> -          (encoding (string->symbol (fluid-ref %default-port-encoding)))
> +          (encoding (if (string? (fluid-ref %default-port-encoding))
> +                        (string->symbol (fluid-ref %default-port-encoding))
> +                        (fluid-ref %default-port-encoding)))

Probably 'and=>' would be clearer - as-is, it looks like it expects a 
symbol but also accepts a string (to be converted into a symbol). But 
that's not the case - it accepts strings, but also the boolean #false.  
'and=>' is specifically about apply a function to non-false things and 
leaving false in-place, so 'and=>' would avoid the potential misconception.

There is TOCTTOU bug here -  an async could mutate the current value of 
the %default-port-encoding fluid in-between the first fluid-ref 
invocation and the second fluid-ref invocation. and=> would avoid that.

Best regards,
Maxime Devos




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-02 20:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02 19:51 [PATCH] Fix make-custom-port in case encoding is #f H. Müller
2025-02-02 20:01 ` Maxime Devos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).