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.
This commit is contained in:
parent
2c02bdda19
commit
69ca2bb221
10 changed files with 114 additions and 49 deletions
|
|
@ -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 */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue