guile-devel
[Top][All Lists]
Advanced

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

[PATCH 1/1] Export (ice-9 ports) from (guile)


From: Rob Browning
Subject: [PATCH 1/1] Export (ice-9 ports) from (guile)
Date: Sat, 27 May 2023 14:58:31 -0500

Without this, bindings like current-output-port won't be available after
selectively importing (guile), e.g.

  (define-module (sandbox)
    #:pure
    #:use-module ((guile) #:hide (...))

* ice-9/boot-9.scm: export (ice-9 ports) exports from (guile).

Thanks to Andy Wingo for helping track down the problem.
---

 This works, but not positive it's right.  In particular, I
 wasn't sure about the bootstrap bindings.

 I also haven't thought carefully yet about whether this is OK for 3,
 or might need to wait for 4.

 module/ice-9/boot-9.scm | 21 +++++++++++++++++----
 module/ice-9/ports.scm  | 20 +++++++++++---------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 06c47cf37..c8f332dae 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -4650,10 +4650,23 @@ R7RS."
 ;;; {Ports}
 ;;;
 
-;; Allow code in (guile) to use port bindings.
-(module-use! the-root-module (resolve-interface '(ice-9 ports)))
-;; Allow users of (guile) to see port bindings.
-(module-use! the-scm-module (resolve-interface '(ice-9 ports)))
+;; The bootstrap bindings already exist in the current module.
+;; Resolving the interface rewrites them, but because they already
+;; existed, we must export rather than re-export them.
+(let* ((ports (resolve-interface '(ice-9 ports)))
+       (exports (module-map (lambda (name _) name) ports))
+       (bootstrap-set (@@ (ice-9 ports) bootstrap-bindings)))
+  ;; Allow code in (guile) to use port bindings.
+  (module-use! the-root-module ports)
+  (module-use! the-scm-module ports)
+  ;; These adjust the-scm-module too, since it shares the same
+  ;; public-interface.
+  (module-export! the-root-module
+                  (filter (lambda (s) (memq s bootstrap-set))
+                          exports))
+  (module-re-export! the-root-module
+                     (filter (lambda (s) (not (memq s bootstrap-set)))
+                             exports)))
 
 
 
diff --git a/module/ice-9/ports.scm b/module/ice-9/ports.scm
index b219feeae..42573a1db 100644
--- a/module/ice-9/ports.scm
+++ b/module/ice-9/ports.scm
@@ -136,15 +136,17 @@
          (module-add! iface sym var))))
    syms))
 
-(replace-bootstrap-bindings '(open-file
-                              open-input-file
-                              set-port-encoding!
-                              eof-object?
-                              force-output
-                              call-with-output-string
-                              close-port
-                              current-error-port
-                              current-warning-port))
+(define bootstrap-bindings '(open-file
+                             open-input-file
+                             set-port-encoding!
+                             eof-object?
+                             force-output
+                             call-with-output-string
+                             close-port
+                             current-error-port
+                             current-warning-port))
+
+(replace-bootstrap-bindings bootstrap-bindings)
 
 (load-extension (string-append "libguile-" (effective-version))
                 "scm_init_ice_9_ports")
-- 
2.39.2




reply via email to

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