mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +02:00
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.
This commit is contained in:
parent
c0d5f8b555
commit
e8eeeeb1d4
6 changed files with 14 additions and 23 deletions
|
@ -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
|
Called when the port is closed. It should free any resources used by
|
||||||
the port. Set using
|
the port. Set using
|
||||||
|
|
||||||
@deftypefun void scm_set_port_close (scm_t_bits tc, int (*close) (SCM port))
|
@deftypefun void scm_set_port_close (scm_t_bits tc, void (*close) (SCM port))
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
By default, ports that are garbage collected just go away without
|
By default, ports that are garbage collected just go away without
|
||||||
|
|
|
@ -794,11 +794,10 @@ close_the_fd (void *data)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
fport_close (SCM port)
|
fport_close (SCM port)
|
||||||
{
|
{
|
||||||
scm_t_fport *fp = SCM_FSTREAM (port);
|
scm_t_fport *fp = SCM_FSTREAM (port);
|
||||||
int rv;
|
|
||||||
|
|
||||||
scm_dynwind_begin (0);
|
scm_dynwind_begin (0);
|
||||||
scm_dynwind_unwind_handler (close_the_fd, fp, 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));
|
scm_port_non_buffer (SCM_PTAB_ENTRY (port));
|
||||||
|
|
||||||
rv = close (fp->fdes);
|
if (close (fp->fdes) != 0)
|
||||||
if (rv)
|
|
||||||
/* It's not useful to retry after EINTR, as the file descriptor is
|
/* It's not useful to retry after EINTR, as the file descriptor is
|
||||||
in an undefined state. See http://lwn.net/Articles/365294/.
|
in an undefined state. See http://lwn.net/Articles/365294/.
|
||||||
Instead just throw an error if close fails, trusting that the fd
|
Instead just throw an error if close fails, trusting that the fd
|
||||||
was cleaned up. */
|
was cleaned up. */
|
||||||
scm_syserror ("fport_close");
|
scm_syserror ("fport_close");
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static scm_t_bits
|
static scm_t_bits
|
||||||
|
|
|
@ -275,7 +275,7 @@ scm_set_port_print (scm_t_bits tc, int (*print) (SCM exp, SCM port,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
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)
|
if (SCM_PORT_DESCRIPTOR (port)->close)
|
||||||
/* Note! This may throw an exception. Anything after this point
|
/* Note! This may throw an exception. Anything after this point
|
||||||
should be resilient to non-local exits. */
|
should be resilient to non-local exits. */
|
||||||
rv = SCM_PORT_DESCRIPTOR (port)->close (port);
|
SCM_PORT_DESCRIPTOR (port)->close (port);
|
||||||
else
|
|
||||||
rv = 0;
|
|
||||||
|
|
||||||
if (pti->iconv_descriptors)
|
if (pti->iconv_descriptors)
|
||||||
{
|
{
|
||||||
|
@ -846,7 +844,7 @@ SCM_DEFINE (scm_close_port, "close-port", 1, 0, 0,
|
||||||
pti->iconv_descriptors = NULL;
|
pti->iconv_descriptors = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return scm_from_bool (rv >= 0);
|
return SCM_BOOL_T;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
|
@ -187,7 +187,7 @@ typedef struct scm_t_ptob_descriptor
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int (*print) (SCM exp, SCM port, scm_print_state *pstate);
|
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 (*write) (SCM port, const void *data, size_t size);
|
||||||
void (*flush) (SCM port);
|
void (*flush) (SCM port);
|
||||||
|
@ -227,7 +227,7 @@ SCM_API void scm_set_port_print (scm_t_bits tc,
|
||||||
int (*print) (SCM exp,
|
int (*print) (SCM exp,
|
||||||
SCM port,
|
SCM port,
|
||||||
scm_print_state *pstate));
|
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_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));
|
SCM_API void scm_set_port_flush (scm_t_bits tc, void (*flush) (SCM port));
|
||||||
|
|
|
@ -257,7 +257,7 @@ custom_binary_port_seek (SCM port, scm_t_off offset, int whence)
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
static int
|
static void
|
||||||
custom_binary_port_close (SCM port)
|
custom_binary_port_close (SCM port)
|
||||||
{
|
{
|
||||||
struct custom_binary_port *stream = (void *) SCM_STREAM (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))
|
if (scm_is_true (stream->close))
|
||||||
/* Invoke the `close' thunk. */
|
/* Invoke the `close' thunk. */
|
||||||
scm_call_0 (stream->close);
|
scm_call_0 (stream->close);
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1238,13 +1236,13 @@ transcoded_port_flush (SCM port)
|
||||||
scm_force_output (binary_port);
|
scm_force_output (binary_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
transcoded_port_close (SCM port)
|
transcoded_port_close (SCM port)
|
||||||
{
|
{
|
||||||
SCM bport = SCM_TRANSCODED_PORT_BINARY_PORT (port);
|
SCM bport = SCM_TRANSCODED_PORT_BINARY_PORT (port);
|
||||||
if (SCM_OUTPUT_PORT_P (port))
|
if (SCM_OUTPUT_PORT_P (port))
|
||||||
transcoded_port_flush (port);
|
transcoded_port_flush (port);
|
||||||
return scm_is_true (scm_close_port (bport)) ? 0 : -1;
|
scm_close_port (bport);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
|
@ -128,13 +128,12 @@ soft_port_fill_input (SCM port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static void
|
||||||
soft_port_close (SCM port)
|
soft_port_close (SCM port)
|
||||||
{
|
{
|
||||||
struct soft_port *stream = (void *) SCM_STREAM (port);
|
struct soft_port *stream = (void *) SCM_STREAM (port);
|
||||||
if (scm_is_false (stream->close))
|
if (scm_is_true (stream->close))
|
||||||
return 0;
|
scm_call_0 (stream->close);
|
||||||
return scm_is_false (scm_call_0 (stream->close)) ? EOF : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue