guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 05/18: Move line-buffing machinery to ports.c


From: Andy Wingo
Subject: [Guile-commits] 05/18: Move line-buffing machinery to ports.c
Date: Wed, 06 Apr 2016 17:27:07 +0000

wingo pushed a commit to branch wip-port-refactor
in repository guile.

commit 4eb9fd47c47fcd3d9da8aaced8b729a9cd303ab4
Author: Andy Wingo <address@hidden>
Date:   Sun Apr 3 10:51:58 2016 +0200

    Move line-buffing machinery to ports.c
    
    * libguile/ports.c (scm_lfwrite_unlocked):
    * libguile/fports.c (fport_write): Move line-buffering from fport_write
      to scm_lfwrite_unlocked.
---
 libguile/fports.c |    4 ----
 libguile/ports.c  |   16 +++++++---------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/libguile/fports.c b/libguile/fports.c
index ff6d49d..8ad8ba0 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -784,10 +784,6 @@ fport_write (SCM port, const void *data, size_t size)
            }
        }
       }
-
-    /* handle line buffering.  */     
-    if ((SCM_CELL_WORD_0 (port) & SCM_BUFLINE) && memchr (data, '\n', size))
-      fport_flush (port);
   }
 }
 #undef FUNC_NAME
diff --git a/libguile/ports.c b/libguile/ports.c
index d394193..da8b4d2 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -2753,23 +2753,21 @@ scm_c_write (SCM port, const void *ptr, size_t size)
 /* scm_lfwrite
  *
  * This function differs from scm_c_write; it updates port line and
- * column. */
+ * column, flushing line-buffered ports when appropriate. */
 void
 scm_lfwrite_unlocked (const char *ptr, size_t size, SCM port)
 {
-  scm_t_port *pt = SCM_PTAB_ENTRY (port);
-  scm_t_ptob_descriptor *ptob = SCM_PORT_DESCRIPTOR (port);
+  int saved_line;
 
-  if (pt->rw_active == SCM_PORT_READ)
-    scm_end_input_unlocked (port);
-
-  ptob->write (port, ptr, size);
+  scm_c_write_unlocked (port, ptr, size);
 
+  saved_line = SCM_LINUM (port);
   for (; size; ptr++, size--)
     update_port_lf ((scm_t_wchar) (unsigned char) *ptr, port);
 
-  if (pt->rw_random)
-    pt->rw_active = SCM_PORT_WRITE;
+  /* Handle line buffering.  */
+  if ((SCM_CELL_WORD_0 (port) & SCM_BUFLINE) && saved_line != SCM_LINUM (port))
+    scm_flush_unlocked (port);
 }
 
 void



reply via email to

[Prev in Thread] Current Thread [Next in Thread]