mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-08 13:10:19 +02:00
Remove weak set usage in ports.c
* libguile/ephemerons.h: * libguile/ephemerons.c (scm_c_ephemeron_load, scm_c_ephemeron_push): New routines. * libguile/ioext.c (scm_fdes_to_ports): Rework in terms of scm_c_port_for_each. * libguile/ports-internal.h (struct scm_t_port): Add pointer to entry on weak ports list, so that we can cancel it easily. * libguile/ports.c (release_port): Mark weak ports list entry as dead. (all_ports_needing_close, for_each_port_needing_close): Rework as ephemeron chain. (scm_c_make_port_with_encoding, close_port, scm_c_port_for_each): Adapt API. (scm_init_ports): No more weak set.
This commit is contained in:
parent
2a6f6ec354
commit
dbc384a6ba
6 changed files with 67 additions and 51 deletions
|
@ -1,4 +1,4 @@
|
|||
/* Copyright 1995-2001,2003,2006,2011,2014,2018
|
||||
/* Copyright 1995-2001,2003,2006,2011,2014,2018,2025
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Guile.
|
||||
|
@ -282,15 +282,19 @@ SCM_DEFINE (scm_primitive_move_to_fdes, "primitive-move->fdes", 2, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
get_matching_port (void *closure, SCM port, SCM result)
|
||||
struct scm_fdes_to_ports_data
|
||||
{
|
||||
int fd = * (int *) closure;
|
||||
|
||||
if (SCM_OPFPORTP (port) && SCM_FSTREAM (port)->fdes == fd)
|
||||
result = scm_cons (port, result);
|
||||
SCM ports;
|
||||
int fd;
|
||||
};
|
||||
|
||||
return result;
|
||||
static void
|
||||
collect_matching_ports (void *closure, SCM port)
|
||||
{
|
||||
struct scm_fdes_to_ports_data *data = closure;
|
||||
|
||||
if (SCM_OPFPORTP (port) && SCM_FSTREAM (port)->fdes == data->fd)
|
||||
data->ports = scm_cons (port, data->ports);
|
||||
}
|
||||
|
||||
/* Return a list of ports using a given file descriptor. */
|
||||
|
@ -301,13 +305,13 @@ SCM_DEFINE (scm_fdes_to_ports, "fdes->ports", 1, 0, 0,
|
|||
"counts.")
|
||||
#define FUNC_NAME s_scm_fdes_to_ports
|
||||
{
|
||||
SCM result = SCM_EOL;
|
||||
int int_fd = scm_to_int (fd);
|
||||
struct scm_fdes_to_ports_data data;
|
||||
data.ports = SCM_EOL;
|
||||
data.fd = scm_to_int (fd);
|
||||
|
||||
result = scm_c_weak_set_fold (get_matching_port,
|
||||
(void*) &int_fd, result,
|
||||
scm_i_port_weak_set);
|
||||
return result;
|
||||
scm_c_port_for_each (collect_matching_ports, &data);
|
||||
|
||||
return data.ports;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue