From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#12216: peek-char incorrectly *CONSUMES* eof Date: Mon, 01 Apr 2013 17:27:14 -0400 Message-ID: <87li920wnh.fsf@tines.lan> References: <87sj49vld2.fsf@pobox.com> <87ip52ew09.fsf@pobox.com> <87ehfjimug.fsf@pobox.com> <87r4jjfjya.fsf@pobox.com> <87r4jj188o.fsf@tines.lan> <87sj3zdury.fsf@pobox.com> <87obe07bvx.fsf@tines.lan> <87bo9z3szq.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1364851698 10623 80.91.229.3 (1 Apr 2013 21:28:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 21:28:18 +0000 (UTC) Cc: dwheeler@dwheeler.com, almkglor , 12216 <12216@debbugs.gnu.org> To: Andy Wingo Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Apr 01 23:28:44 2013 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMmHQ-0002AW-Dk for guile-bugs@m.gmane.org; Mon, 01 Apr 2013 23:28:40 +0200 Original-Received: from localhost ([::1]:38496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMmH1-0007jD-Rc for guile-bugs@m.gmane.org; Mon, 01 Apr 2013 17:28:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMmGy-0007j8-4h for bug-guile@gnu.org; Mon, 01 Apr 2013 17:28:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMmGt-0006eL-Q6 for bug-guile@gnu.org; Mon, 01 Apr 2013 17:28:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52493) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMmGt-0006e9-MB for bug-guile@gnu.org; Mon, 01 Apr 2013 17:28:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UMmJi-0000aL-0F for bug-guile@gnu.org; Mon, 01 Apr 2013 17:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 01 Apr 2013 21:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 12216-submit@debbugs.gnu.org id=B12216.13648518412216 (code B ref 12216); Mon, 01 Apr 2013 21:31:01 +0000 Original-Received: (at 12216) by debbugs.gnu.org; 1 Apr 2013 21:30:41 +0000 Original-Received: from localhost ([127.0.0.1]:56601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMmJN-0000Zf-4X for submit@debbugs.gnu.org; Mon, 01 Apr 2013 17:30:41 -0400 Original-Received: from world.peace.net ([96.39.62.75]:55223) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMmJK-0000ZX-Hx for 12216@debbugs.gnu.org; Mon, 01 Apr 2013 17:30:39 -0400 Original-Received: from 74-94-165-125-newengland.hfc.comcastbusiness.net ([74.94.165.125] helo=tines.lan) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1UMmGN-0004yh-Ib; Mon, 01 Apr 2013 17:27:35 -0400 In-Reply-To: <87bo9z3szq.fsf@tines.lan> (Mark H. Weaver's message of "Sun, 31 Mar 2013 22:05:45 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7050 Archived-At: --=-=-= Content-Type: text/plain The prerequisite patches are now in stable-2.0. Here's an updated patch that applies against current stable-2.0. Otherwise it has not changed. Mark --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Peeks-do-not-consume-EOFs.patch Content-Description: [PATCH] Peeks do not consume EOFs >From 7d9ebc691519af7236e1fec8dfefd5fc8784f875 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Sun, 31 Mar 2013 19:06:51 -0400 Subject: [PATCH] Peeks do not consume EOFs. Fixes . * libguile/ports-internal.h (struct scm_port_internal): Add 'pending_eof' flag. * libguile/inline.h (scm_peek_byte_or_eof): Set 'pending_eof' flag before returning EOF. * libguile/ports.c (scm_i_set_pending_eof): New function. (scm_i_clear_pending_eof): New static function. (scm_new_port_table_entry): Initialize 'pending_eof'. (scm_fill_input): Check for 'pending_eof'. (scm_end_input, scm_unget_byte, scm_seek): Clear 'pending_eof'. (scm_peek_char): Set 'pending_eof' flag before returning EOF. * libguile/ports.h (scm_i_set_pending_eof): Add prototype. --- libguile/inline.h | 5 ++++- libguile/ports-internal.h | 1 + libguile/ports.c | 32 ++++++++++++++++++++++++++++++-- libguile/ports.h | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libguile/inline.h b/libguile/inline.h index 88ba7f7..fffe101 100644 --- a/libguile/inline.h +++ b/libguile/inline.h @@ -134,7 +134,10 @@ scm_peek_byte_or_eof (SCM port) if (pt->read_pos >= pt->read_end) { if (SCM_UNLIKELY (scm_fill_input (port) == EOF)) - return EOF; + { + scm_i_set_pending_eof (port); + return EOF; + } } c = *pt->read_pos; diff --git a/libguile/ports-internal.h b/libguile/ports-internal.h index 73a788f..333d4fb 100644 --- a/libguile/ports-internal.h +++ b/libguile/ports-internal.h @@ -48,6 +48,7 @@ struct scm_port_internal { scm_t_port_encoding_mode encoding_mode; scm_t_iconv_descriptors *iconv_descriptors; + int pending_eof; SCM alist; }; diff --git a/libguile/ports.c b/libguile/ports.c index becdbed..65e2e6f 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -241,6 +241,18 @@ scm_set_port_input_waiting (scm_t_bits tc, int (*input_waiting) (SCM)) scm_ptobs[SCM_TC2PTOBNUM (tc)].input_waiting = input_waiting; } +void +scm_i_set_pending_eof (SCM port) +{ + SCM_PORT_GET_INTERNAL (port)->pending_eof = 1; +} + +static void +scm_i_clear_pending_eof (SCM port) +{ + SCM_PORT_GET_INTERNAL (port)->pending_eof = 0; +} + SCM scm_i_port_alist (SCM port) { @@ -645,6 +657,7 @@ scm_new_port_table_entry (scm_t_bits tag) entry->input_cd = pti; /* XXX pointer to the internal port structure */ entry->output_cd = NULL; /* XXX unused */ + pti->pending_eof = 0; pti->alist = SCM_EOL; SCM_SET_CELL_TYPE (z, tag); @@ -1423,9 +1436,16 @@ int scm_fill_input (SCM port) { scm_t_port *pt = SCM_PTAB_ENTRY (port); + scm_t_port_internal *pti = SCM_PORT_GET_INTERNAL (port); assert (pt->read_pos == pt->read_end); + if (pti->pending_eof) + { + pti->pending_eof = 0; + return EOF; + } + if (pt->read_buf == pt->putback_buf) { /* finished reading put-back chars. */ @@ -1665,6 +1685,7 @@ scm_end_input (SCM port) long offset; scm_t_port *pt = SCM_PTAB_ENTRY (port); + scm_i_clear_pending_eof (port); if (pt->read_buf == pt->putback_buf) { offset = pt->read_end - pt->read_pos; @@ -1688,6 +1709,7 @@ scm_unget_byte (int c, SCM port) { scm_t_port *pt = SCM_PTAB_ENTRY (port); + scm_i_clear_pending_eof (port); if (pt->read_buf == pt->putback_buf) /* already using the put-back buffer. */ { @@ -1859,7 +1881,10 @@ SCM_DEFINE (scm_peek_char, "peek-char", 0, 1, 0, result = SCM_BOOL_F; } else if (c == EOF) - result = SCM_EOF_VAL; + { + scm_i_set_pending_eof (port); + result = SCM_EOF_VAL; + } else result = SCM_MAKE_CHAR (c); @@ -1958,7 +1983,10 @@ SCM_DEFINE (scm_seek, "seek", 3, 0, 0, SCM_MISC_ERROR ("port is not seekable", scm_cons (fd_port, SCM_EOL)); else - rv = ptob->seek (fd_port, off, how); + { + scm_i_clear_pending_eof (fd_port); + rv = ptob->seek (fd_port, off, how); + } return scm_from_off_t_or_off64_t (rv); } else /* file descriptor?. */ diff --git a/libguile/ports.h b/libguile/ports.h index 53d5081..5c9334a 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -316,6 +316,7 @@ SCM_API SCM scm_port_column (SCM port); SCM_API SCM scm_set_port_column_x (SCM port, SCM line); SCM_API SCM scm_port_filename (SCM port); SCM_API SCM scm_set_port_filename_x (SCM port, SCM filename); +SCM_INTERNAL void scm_i_set_pending_eof (SCM port); SCM_INTERNAL SCM scm_i_port_alist (SCM port); SCM_INTERNAL void scm_i_set_port_alist_x (SCM port, SCM alist); SCM_INTERNAL const char *scm_i_default_port_encoding (void); -- 1.7.10.4 --=-=-=--