From: Rob Browning <rlb@defaultvalue.org>
To: guile-devel@gnu.org
Subject: [PATCH 1/1] Export (ice-9 ports) from (guile)
Date: Sat, 27 May 2023 14:58:31 -0500 [thread overview]
Message-ID: <20230527195831.368621-1-rlb@defaultvalue.org> (raw)
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)))
\f
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 other threads:[~2023-05-27 19:58 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230527195831.368621-1-rlb@defaultvalue.org \
--to=rlb@defaultvalue.org \
--cc=guile-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).