From 21f161a67039a2f5b3beddc6653fb4527e24b019 Mon Sep 17 00:00:00 2001 From: Ludovic Court`es Date: Mon, 26 Feb 2007 13:42:16 +0000 Subject: [PATCH] I/O: Small fixes in `get-bytevector-n' and `get-bytevector-n!'. * src/ports.c (scm_r6rs_get_bytevector_n): Don't invoke `scm_c_read ()' when C_COUNT is zero since it may block. Don't return EOF when both C_READ and C_COUNT are zero; return the empty bytevector instead. (scm_r6rs_get_bytevector_n_x): Likewise. git-archimport-id: lcourtes@laas.fr--2006-libre/guile-r6rs-libs--devo--0--patch-31 --- ChangeLog | 16 ++++++++++++++++ src/ports.c | 25 +++++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae67e32..d40ccde 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,22 @@ # arch-tag: automatic-ChangeLog--lcourtes@laas.fr--2006-libre/guile-r6rs-libs--devo--0 # +2007-02-26 13:42:16 GMT Ludovic Court`es patch-31 + + Summary: + I/O: Small fixes in `get-bytevector-n' and `get-bytevector-n!'. + Revision: + guile-r6rs-libs--devo--0--patch-31 + + * src/ports.c (scm_r6rs_get_bytevector_n): Don't invoke `scm_c_read ()' + when C_COUNT is zero since it may block. Don't return EOF when both + C_READ and C_COUNT are zero; return the empty bytevector instead. + (scm_r6rs_get_bytevector_n_x): Likewise. + + modified files: + ChangeLog src/ports.c + + 2007-02-25 15:40:53 GMT Ludovic Courtes patch-30 Summary: diff --git a/src/ports.c b/src/ports.c index 0818e30..539d3c0 100644 --- a/src/ports.c +++ b/src/ports.c @@ -455,7 +455,7 @@ SCM_DEFINE (scm_r6rs_get_bytevector_n, "get-bytevector-n", 2, 0, 0, SCM result; char *c_bv; unsigned c_count; - size_t read; + size_t c_read; SCM_VALIDATE_R6RS_BINARY_INPUT_PORT (1, port); c_count = scm_to_uint (count); @@ -463,10 +463,14 @@ SCM_DEFINE (scm_r6rs_get_bytevector_n, "get-bytevector-n", 2, 0, 0, result = scm_r6rs_c_make_bytevector (c_count); c_bv = (char *) SCM_R6RS_BYTEVECTOR_CONTENTS (result); - /* XXX: `scm_c_read ()' does not update the port position. */ - read = scm_c_read (port, c_bv, c_count); + if (EXPECT_TRUE (c_count > 0)) + /* XXX: `scm_c_read ()' does not update the port position. */ + c_read = scm_c_read (port, c_bv, c_count); + else + /* Don't invoke `scm_c_read ()' since it may block. */ + c_read = 0; - if (read == 0) + if ((c_read == 0) && (c_count > 0)) { if (SCM_EOF_OBJECT_P (scm_peek_char (port))) result = SCM_EOF_VAL; @@ -475,8 +479,8 @@ SCM_DEFINE (scm_r6rs_get_bytevector_n, "get-bytevector-n", 2, 0, 0, } else { - if (read < c_count) - result = scm_r6rs_c_shrink_bytevector (result, read); + if (c_read < c_count) + result = scm_r6rs_c_shrink_bytevector (result, c_read); } return result; @@ -507,8 +511,13 @@ SCM_DEFINE (scm_r6rs_get_bytevector_n_x, "get-bytevector-n!", 4, 0, 0, if (EXPECT_FALSE (c_start + c_count > c_len)) scm_out_of_range (FUNC_NAME, count); - c_read = scm_c_read (port, c_bv + c_start, c_count); - if (c_read == 0) + if (EXPECT_TRUE (c_count > 0)) + c_read = scm_c_read (port, c_bv + c_start, c_count); + else + /* Don't invoke `scm_c_read ()' since it may block. */ + c_read = 0; + + if ((c_read == 0) && (c_count > 0)) { if (SCM_EOF_OBJECT_P (scm_peek_char (port))) result = SCM_EOF_VAL; -- 2.11.4.GIT