mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
'port-position' works on CBIPs that do not support 'set-port-position!'.
* libguile/r6rs-ports.c (cbp_seek)[WHENCE == SEEK_CUR]: Break out of the switch statement when OFFSET is zero. Pass 'scm_wrong_type_arg_msg' a phrase suitable for use after "expecting". * test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports")["custom binary input port supports `port-position', not `set-port-position!'"]: New test.
This commit is contained in:
parent
7af706e36e
commit
c9d55a7e4e
2 changed files with 19 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2009, 2010, 2011, 2013 Free Software Foundation, Inc.
|
/* Copyright (C) 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public License
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
@ -224,10 +224,14 @@ cbp_seek (SCM port, scm_t_off offset, int whence)
|
||||||
result = scm_call_0 (get_position_proc);
|
result = scm_call_0 (get_position_proc);
|
||||||
else
|
else
|
||||||
scm_wrong_type_arg_msg (FUNC_NAME, 0, port,
|
scm_wrong_type_arg_msg (FUNC_NAME, 0, port,
|
||||||
"R6RS custom binary port does not "
|
"R6RS custom binary port with "
|
||||||
"support `port-position'");
|
"`port-position' support");
|
||||||
|
c_result = scm_to_int (result);
|
||||||
|
if (offset == 0)
|
||||||
|
/* We just want to know the current position. */
|
||||||
|
break;
|
||||||
|
|
||||||
offset += scm_to_int (result);
|
offset += c_result;
|
||||||
/* Fall through. */
|
/* Fall through. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,8 +244,7 @@ cbp_seek (SCM port, scm_t_off offset, int whence)
|
||||||
result = scm_call_1 (set_position_proc, scm_from_int (offset));
|
result = scm_call_1 (set_position_proc, scm_from_int (offset));
|
||||||
else
|
else
|
||||||
scm_wrong_type_arg_msg (FUNC_NAME, 0, port,
|
scm_wrong_type_arg_msg (FUNC_NAME, 0, port,
|
||||||
"R6RS custom binary port does not "
|
"seekable R6RS custom binary port");
|
||||||
"support `set-port-position!'");
|
|
||||||
|
|
||||||
/* Assuming setting the position succeeded. */
|
/* Assuming setting the position succeeded. */
|
||||||
c_result = offset;
|
c_result = offset;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
;;;; r6rs-ports.test --- R6RS I/O port tests. -*- coding: utf-8; -*-
|
;;;; r6rs-ports.test --- R6RS I/O port tests. -*- coding: utf-8; -*-
|
||||||
;;;;
|
;;;;
|
||||||
;;;; Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
;;;; Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
|
||||||
;;;; Ludovic Courtès
|
;;;; Ludovic Courtès
|
||||||
;;;;
|
;;;;
|
||||||
;;;; This library is free software; you can redistribute it and/or
|
;;;; This library is free software; you can redistribute it and/or
|
||||||
|
@ -411,6 +411,15 @@
|
||||||
(not (or (port-has-port-position? port)
|
(not (or (port-has-port-position? port)
|
||||||
(port-has-set-port-position!? port)))))
|
(port-has-set-port-position!? port)))))
|
||||||
|
|
||||||
|
(pass-if-equal "custom binary input port supports `port-position', \
|
||||||
|
not `set-port-position!'"
|
||||||
|
42
|
||||||
|
(let ((port (make-custom-binary-input-port "the port" (const 0)
|
||||||
|
(const 42) #f #f)))
|
||||||
|
(and (port-has-port-position? port)
|
||||||
|
(not (port-has-set-port-position!? port))
|
||||||
|
(port-position port))))
|
||||||
|
|
||||||
(pass-if "custom binary input port supports `port-position'"
|
(pass-if "custom binary input port supports `port-position'"
|
||||||
(let* ((str "Hello Port!")
|
(let* ((str "Hello Port!")
|
||||||
(source (open-bytevector-input-port
|
(source (open-bytevector-input-port
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue