diff --git a/libguile/ports-internal.h b/libguile/ports-internal.h index bd25f3e52..73a788f39 100644 --- a/libguile/ports-internal.h +++ b/libguile/ports-internal.h @@ -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; diff --git a/libguile/ports.c b/libguile/ports.c index 8f3df9cd5..becdbed8b 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -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. */ diff --git a/libguile/ports.h b/libguile/ports.h index 95545cd21..53d508180 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -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); diff --git a/libguile/read.c b/libguile/read.c index 222891b7f..645795243 100644 --- a/libguile/read.c +++ b/libguile/read.c @@ -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);