diff options
author | Andy Wingo <wingo@pobox.com> | 2011-02-18 15:52:02 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-02-18 16:01:21 +0100 |
commit | dd0d987fbdf32387ff4b36631302918ca8ff36cb (patch) | |
tree | 5ca6a5bd578c304b28868d0e02bade560f85395f | |
parent | 7e23d9d0f1efd8d62e8fbe1341d0e1ea54b2eb57 (diff) | |
download | guile-dd0d987fbdf32387ff4b36631302918ca8ff36cb.tar.gz |
add (ice-9 binary-ports)
* module/ice-9/binary-ports.scm: New module.
* module/Makefile.am: Add to makefile.
* module/rnrs/io/ports.scm: Re-export bindings from (ice-9 binary
ports). This will allow the compiler to not pull (rnrs) into its
included module set.
-rw-r--r-- | module/Makefile.am | 1 | ||||
-rw-r--r-- | module/ice-9/binary-ports.scm | 49 | ||||
-rw-r--r-- | module/rnrs/io/ports.scm | 9 |
3 files changed, 54 insertions, 5 deletions
diff --git a/module/Makefile.am b/module/Makefile.am index 994090015..c0f68864f 100644 --- a/module/Makefile.am +++ b/module/Makefile.am @@ -180,6 +180,7 @@ ICE_9_SOURCES = \ ice-9/r5rs.scm \ ice-9/deprecated.scm \ ice-9/and-let-star.scm \ + ice-9/binary-ports.scm \ ice-9/calling.scm \ ice-9/common-list.scm \ ice-9/control.scm \ diff --git a/module/ice-9/binary-ports.scm b/module/ice-9/binary-ports.scm new file mode 100644 index 000000000..63d09cf21 --- /dev/null +++ b/module/ice-9/binary-ports.scm @@ -0,0 +1,49 @@ +;;;; binary-ports.scm --- Binary IO on ports + +;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. +;;;; +;;;; This library is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU Lesser General Public +;;;; License as published by the Free Software Foundation; either +;;;; version 3 of the License, or (at your option) any later version. +;;;; +;;;; This library is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;;; Lesser General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU Lesser General Public +;;;; License along with this library; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +;;; Author: Ludovic Courtès <ludo@gnu.org> + +;;; Commentary: +;;; +;;; The I/O port API of the R6RS is provided by this module. In many areas +;;; it complements or refines Guile's own historical port API. For instance, +;;; it allows for binary I/O with bytevectors. +;;; +;;; Code: + +(define-module (ice-9 binary-ports) + #:use-module (rnrs bytevectors) + #:export (eof-object + open-bytevector-input-port + make-custom-binary-input-port + get-u8 + lookahead-u8 + get-bytevector-n + get-bytevector-n! + get-bytevector-some + get-bytevector-all + put-u8 + put-bytevector + open-bytevector-output-port + make-custom-binary-output-port)) + +;; Note that this extension also defines %make-transcoded-port, which is +;; not exported but is used by (rnrs io ports). + +(load-extension (string-append "libguile-" (effective-version)) + "scm_init_r6rs_ports") diff --git a/module/rnrs/io/ports.scm b/module/rnrs/io/ports.scm index a5815c85f..d3a81b7c7 100644 --- a/module/rnrs/io/ports.scm +++ b/module/rnrs/io/ports.scm @@ -98,7 +98,8 @@ make-i/o-decoding-error &i/o-encoding-error i/o-encoding-error? make-i/o-encoding-error i/o-encoding-error-char) - (import (only (rnrs base) assertion-violation) + (import (ice-9 binary-ports) + (only (rnrs base) assertion-violation) (rnrs enums) (rnrs records syntactic) (rnrs exceptions) @@ -108,9 +109,6 @@ (ice-9 rdelim) (except (guile) raise)) -(load-extension (string-append "libguile-" (effective-version)) - "scm_init_r6rs_ports") - ;;; @@ -205,7 +203,8 @@ "Return a new textual port based on @var{port}, using @var{transcoder} to encode and decode data written to or read from its underlying binary port @var{port}." - (let ((result (%make-transcoded-port port))) + ;; Hackily get at %make-transcoded-port. + (let ((result ((@@ (ice-9 binary-ports) %make-transcoded-port) port))) (set-port-encoding! result (transcoder-codec transcoder)) (case (transcoder-error-handling-mode transcoder) ((raise) |