guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 17/18: Port close functions return void


From: Andy Wingo
Subject: [Guile-commits] 17/18: Port close functions return void
Date: Wed, 06 Apr 2016 17:27:08 +0000

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

commit e8eeeeb1d4743fce89b28fa9360e71f6efd6a4e8
Author: Andy Wingo <address@hidden>
Date:   Tue Apr 5 15:13:36 2016 +0200

    Port close functions return void
    
    * libguile/ports.h (scm_t_ptob_descriptor): The port close function now
      returns void.
      (scm_set_port_close): Adapt prototype.
    * libguile/ports.c (scm_close_port): Always return true if we managed to
      call the close function.  There's no other sensible result; exceptions
      are handled, well, exceptionally.
    
    * libguile/fports.c (fport_close)
    * libguile/r6rs-ports.c (custom_binary_port_close, transcoded_port_close):
    * libguile/vports.c (soft_port_close): Adapt.
    
    * doc/ref/api-io.texi (Port Implementation): Update.
---
 doc/ref/api-io.texi   |    2 +-
 libguile/fports.c     |    8 ++------
 libguile/ports.c      |    8 +++-----
 libguile/ports.h      |    4 ++--
 libguile/r6rs-ports.c |    8 +++-----
 libguile/vports.c     |    7 +++----
 6 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/doc/ref/api-io.texi b/doc/ref/api-io.texi
index 759d339..4e4d59b 100644
--- a/doc/ref/api-io.texi
+++ b/doc/ref/api-io.texi
@@ -2317,7 +2317,7 @@ argument @var{dest_port} is where its description should 
go.
 Called when the port is closed.  It should free any resources used by
 the port.  Set using
 
address@hidden void scm_set_port_close (scm_t_bits tc, int (*close) (SCM port))
address@hidden void scm_set_port_close (scm_t_bits tc, void (*close) (SCM port))
 @end deftypefun
 
 By default, ports that are garbage collected just go away without
diff --git a/libguile/fports.c b/libguile/fports.c
index e33bfe5..963c1ea 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -794,11 +794,10 @@ close_the_fd (void *data)
   errno = 0;
 }
 
-static int
+static void
 fport_close (SCM port)
 {
   scm_t_fport *fp = SCM_FSTREAM (port);
-  int rv;
 
   scm_dynwind_begin (0);
   scm_dynwind_unwind_handler (close_the_fd, fp, 0);
@@ -807,15 +806,12 @@ fport_close (SCM port)
 
   scm_port_non_buffer (SCM_PTAB_ENTRY (port));
 
-  rv = close (fp->fdes);
-  if (rv)
+  if (close (fp->fdes) != 0)
     /* It's not useful to retry after EINTR, as the file descriptor is
        in an undefined state.  See http://lwn.net/Articles/365294/.
        Instead just throw an error if close fails, trusting that the fd
        was cleaned up.  */
     scm_syserror ("fport_close");
-
-  return 0;
 }
 
 static scm_t_bits
diff --git a/libguile/ports.c b/libguile/ports.c
index 202f7f9..b8d2616 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -275,7 +275,7 @@ scm_set_port_print (scm_t_bits tc, int (*print) (SCM exp, 
SCM port,
 }
 
 void
-scm_set_port_close (scm_t_bits tc, int (*close) (SCM))
+scm_set_port_close (scm_t_bits tc, void (*close) (SCM))
 {
   scm_c_port_type_ref (SCM_TC2PTOBNUM (tc))->close = close;
 }
@@ -834,9 +834,7 @@ SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0,
   if (SCM_PORT_DESCRIPTOR (port)->close)
     /* Note!  This may throw an exception.  Anything after this point
        should be resilient to non-local exits.  */
-    rv = SCM_PORT_DESCRIPTOR (port)->close (port);
-  else
-    rv = 0;
+    SCM_PORT_DESCRIPTOR (port)->close (port);
 
   if (pti->iconv_descriptors)
     {
@@ -846,7 +844,7 @@ SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0,
       pti->iconv_descriptors = NULL;
     }
 
-  return scm_from_bool (rv >= 0);
+  return SCM_BOOL_T;
 }
 #undef FUNC_NAME
 
diff --git a/libguile/ports.h b/libguile/ports.h
index 6b9a006..0196753 100644
--- a/libguile/ports.h
+++ b/libguile/ports.h
@@ -187,7 +187,7 @@ typedef struct scm_t_ptob_descriptor
 {
   char *name;
   int (*print) (SCM exp, SCM port, scm_print_state *pstate);
-  int (*close) (SCM port);
+  void (*close) (SCM port);
 
   void (*write) (SCM port, const void *data, size_t size);
   void (*flush) (SCM port);
@@ -227,7 +227,7 @@ SCM_API void scm_set_port_print (scm_t_bits tc,
                                 int (*print) (SCM exp,
                                               SCM port,
                                               scm_print_state *pstate));
-SCM_API void scm_set_port_close (scm_t_bits tc, int (*close) (SCM));
+SCM_API void scm_set_port_close (scm_t_bits tc, void (*close) (SCM));
 SCM_API void scm_set_port_needs_close_on_gc (scm_t_bits tc, int needs_close_p);
 
 SCM_API void scm_set_port_flush (scm_t_bits tc, void (*flush) (SCM port));
diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c
index 5a752bb..9e12b5a 100644
--- a/libguile/r6rs-ports.c
+++ b/libguile/r6rs-ports.c
@@ -257,7 +257,7 @@ custom_binary_port_seek (SCM port, scm_t_off offset, int 
whence)
 }
 #undef FUNC_NAME
 
-static int
+static void
 custom_binary_port_close (SCM port)
 {
   struct custom_binary_port *stream = (void *) SCM_STREAM (port);
@@ -265,8 +265,6 @@ custom_binary_port_close (SCM port)
   if (scm_is_true (stream->close))
     /* Invoke the `close' thunk.  */
     scm_call_0 (stream->close);
-
-  return 1;
 }
 
 
@@ -1238,13 +1236,13 @@ transcoded_port_flush (SCM port)
     scm_force_output (binary_port);
 }
 
-static int
+static void
 transcoded_port_close (SCM port)
 {
   SCM bport = SCM_TRANSCODED_PORT_BINARY_PORT (port);
   if (SCM_OUTPUT_PORT_P (port))
     transcoded_port_flush (port);
-  return scm_is_true (scm_close_port (bport)) ? 0 : -1;
+  scm_close_port (bport);
 }
 
 static inline void
diff --git a/libguile/vports.c b/libguile/vports.c
index b46f9f7..6504128 100644
--- a/libguile/vports.c
+++ b/libguile/vports.c
@@ -128,13 +128,12 @@ soft_port_fill_input (SCM port)
 }
 
 
-static int 
+static void
 soft_port_close (SCM port)
 {
   struct soft_port *stream = (void *) SCM_STREAM (port);
-  if (scm_is_false (stream->close))
-    return 0;
-  return scm_is_false (scm_call_0 (stream->close)) ? EOF : 0;
+  if (scm_is_true (stream->close))
+    scm_call_0 (stream->close);
 }
 
 



reply via email to

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