1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Move the port alist from the hash table to the internal port structure.

* libguile/ports-internal.h (struct scm_port_internal): Add 'alist'
  member.

* libguile/ports.c (scm_i_port_alist, scm_i_set_port_alist_x): New
  internal functions.
  (scm_i_port_weak_hash): Update comment: the hash table is no longer
  used to store the port's alist.
  (scm_new_port_table_entry): Initialize 'alist'.  Store SCM_BOOL_F in
  the port weak hash, not SCM_EOL.

* libguile/ports.h (scm_i_port_alist, scm_i_set_port_alist_x): Add
  protoypes.

* libguile/read.c (set_port_read_option, init_read_options): Access the
  port's alist via 'scm_i_port_alist' and 'scm_i_set_port_alist_x'.
This commit is contained in:
Mark H Weaver 2013-03-31 19:52:31 -04:00
parent 21bbe22a14
commit 05d7f76296
4 changed files with 25 additions and 13 deletions

View file

@ -48,6 +48,7 @@ struct scm_port_internal
{
scm_t_port_encoding_mode encoding_mode;
scm_t_iconv_descriptors *iconv_descriptors;
SCM alist;
};
typedef struct scm_port_internal scm_t_port_internal;

View file

@ -241,6 +241,18 @@ scm_set_port_input_waiting (scm_t_bits tc, int (*input_waiting) (SCM))
scm_ptobs[SCM_TC2PTOBNUM (tc)].input_waiting = input_waiting;
}
SCM
scm_i_port_alist (SCM port)
{
return SCM_PORT_GET_INTERNAL (port)->alist;
}
void
scm_i_set_port_alist_x (SCM port, SCM alist)
{
SCM_PORT_GET_INTERNAL (port)->alist = alist;
}
SCM_DEFINE (scm_char_ready_p, "char-ready?", 0, 1, 0,
@ -538,8 +550,7 @@ scm_i_dynwind_current_load_port (SCM port)
/*
We need a global registry of ports to flush them all at exit, and to
get all the ports matching a file descriptor. The associated values
are alists, where additional information can be associated with ports.
get all the ports matching a file descriptor.
*/
SCM scm_i_port_weak_hash;
@ -634,10 +645,12 @@ scm_new_port_table_entry (scm_t_bits tag)
entry->input_cd = pti; /* XXX pointer to the internal port structure */
entry->output_cd = NULL; /* XXX unused */
pti->alist = SCM_EOL;
SCM_SET_CELL_TYPE (z, tag);
SCM_SETPTAB_ENTRY (z, entry);
scm_hashq_set_x (scm_i_port_weak_hash, z, SCM_EOL);
scm_hashq_set_x (scm_i_port_weak_hash, z, SCM_BOOL_F);
/* For each new port, register a finalizer so that it port type's free
function can be invoked eventually. */

View file

@ -316,6 +316,8 @@ SCM_API SCM scm_port_column (SCM port);
SCM_API SCM scm_set_port_column_x (SCM port, SCM line);
SCM_API SCM scm_port_filename (SCM port);
SCM_API SCM scm_set_port_filename_x (SCM port, SCM filename);
SCM_INTERNAL SCM scm_i_port_alist (SCM port);
SCM_INTERNAL void scm_i_set_port_alist_x (SCM port, SCM alist);
SCM_INTERNAL const char *scm_i_default_port_encoding (void);
SCM_INTERNAL void scm_i_set_default_port_encoding (const char *);
SCM_INTERNAL void scm_i_set_port_encoding_x (SCM port, const char *str);

View file

@ -2143,9 +2143,9 @@ SCM_DEFINE (scm_file_encoding, "file-encoding", 1, 0, 0,
/* Per-port read options.
We store per-port read options in the 'port-read-options' key of the
port's alist, which is stored in 'scm_i_port_weak_hash'. The value
stored in the alist is a single integer that contains a two-bit field
for each read option.
port's alist, which is stored in the internal port structure. The
value stored in the alist is a single integer that contains a two-bit
field for each read option.
If a bit field contains READ_OPTION_INHERIT (3), that indicates that
the applicable value should be inherited from the corresponding
@ -2184,8 +2184,7 @@ set_port_read_option (SCM port, int option, int new_value)
unsigned int read_options;
new_value &= READ_OPTION_MASK;
scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
alist = scm_hashq_ref (scm_i_port_weak_hash, port, SCM_BOOL_F);
alist = scm_i_port_alist (port);
scm_read_options = scm_assq_ref (alist, sym_port_read_options);
if (scm_is_unsigned_integer (scm_read_options, 0, READ_OPTIONS_MAX_VALUE))
read_options = scm_to_uint (scm_read_options);
@ -2195,8 +2194,7 @@ set_port_read_option (SCM port, int option, int new_value)
read_options |= new_value << option;
scm_read_options = scm_from_uint (read_options);
alist = scm_assq_set_x (alist, sym_port_read_options, scm_read_options);
scm_hashq_set_x (scm_i_port_weak_hash, port, alist);
scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
scm_i_set_port_alist_x (port, alist);
}
/* Set OPTS and PORT's case-insensitivity according to VALUE. */
@ -2234,10 +2232,8 @@ init_read_options (SCM port, scm_t_read_opts *opts)
SCM alist, val, scm_read_options;
unsigned int read_options, x;
scm_i_scm_pthread_mutex_lock (&scm_i_port_table_mutex);
alist = scm_hashq_ref (scm_i_port_weak_hash, port, SCM_BOOL_F);
alist = scm_i_port_alist (port);
scm_read_options = scm_assq_ref (alist, sym_port_read_options);
scm_i_pthread_mutex_unlock (&scm_i_port_table_mutex);
if (scm_is_unsigned_integer (scm_read_options, 0, READ_OPTIONS_MAX_VALUE))
read_options = scm_to_uint (scm_read_options);