diff options
author | Andy Wingo <wingo@pobox.com> | 2017-02-14 21:57:35 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2017-02-14 22:03:21 +0100 |
commit | 69ca2bb2217303b2556b131f3995ca4f6af81234 (patch) | |
tree | a8ef7e23995f35b974db988254aabe5a37c72922 /libguile/fports.h | |
parent | 2c02bdda191eecd998c33b00c56752b8ec7378ab (diff) | |
download | guile-69ca2bb2217303b2556b131f3995ca4f6af81234.tar.gz |
Elide syscalls in fdes->port
* libguile/fports.h (scm_t_fport): Add options field.
(SCM_FDES_RANDOM_P): Deprecate.
(scm_i_fdes_to_port): Add options argument.
* libguile/fports.c (scm_i_fdes_to_port): Add options argument. Only
verify FD if SCM_FPORT_OPTION_VERIFY is there.
(scm_fdes_to_port, scm_open_file_with_encoding): Adapt to
scm_i_fdes_to_port changes.
(fport_random_access_p): Don't try to seek if NOT_SEEKABLE option is
set.
* libguile/deprecated.h:
* libguile/deprecated.c (SCM_FDES_RANDOM_P): Deprecate.
* NEWS: Add deprecation.
* libguile/filesys.c:
* libguile/ioext.c:
* libguile/posix.c:
* libguile/read.c:
* libguile/socket.c: Adapt callers.
Diffstat (limited to 'libguile/fports.h')
-rw-r--r-- | libguile/fports.h | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/libguile/fports.h b/libguile/fports.h index ee9bf7cbd..afb8ba771 100644 --- a/libguile/fports.h +++ b/libguile/fports.h @@ -31,10 +31,13 @@ /* struct allocated for each buffered FPORT. */ typedef struct scm_t_fport { - int fdes; /* file descriptor. */ - int revealed; /* 0 not revealed, > 1 revealed. - * Revealed ports do not get GC'd. - */ + /* The file descriptor. */ + int fdes; + /* Revealed count; 0 indicates not revealed, > 1 revealed. Revealed + ports do not get garbage-collected. */ + int revealed; + /* Set of scm_fport_option flags. */ + unsigned options; } scm_t_fport; SCM_API scm_t_port_type *scm_file_port_type; @@ -48,9 +51,6 @@ SCM_API scm_t_port_type *scm_file_port_type; #define SCM_OPINFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_RDNG)) #define SCM_OPOUTFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_WRTNG)) -/* test whether fdes supports random access. */ -#define SCM_FDES_RANDOM_P(fdes) ((lseek (fdes, 0, SEEK_CUR) == -1) ? 0 : 1) - SCM_API void scm_evict_ports (int fd); SCM_INTERNAL int scm_i_mode_to_open_flags (SCM mode, int *is_binary, @@ -74,8 +74,19 @@ SCM_INTERNAL void scm_init_fports (void); /* internal functions */ -SCM_INTERNAL SCM scm_i_fdes_to_port (int fdes, long mode_bits, SCM name); - +#ifdef BUILDING_LIBGUILE +enum scm_fport_option + { + /* FD's that aren't created by Guile probably need to be checked for + validity. We also check that the open mode is valid. */ + SCM_FPORT_OPTION_VERIFY = 1U<<0, + /* We know some ports aren't seekable and can elide a syscall in + that case. */ + SCM_FPORT_OPTION_NOT_SEEKABLE = 1U<<1 + }; +SCM_INTERNAL SCM scm_i_fdes_to_port (int fdes, long mode_bits, SCM name, + unsigned options); +#endif /* BUILDING_LIBGUILE */ #endif /* SCM_FPORTS_H */ |