1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

port GC fix

This commit is contained in:
Han-Wen Nienhuys 2002-08-04 15:25:07 +00:00
parent c2cbcc5768
commit 402788a938
6 changed files with 41 additions and 31 deletions

View file

@ -1,4 +1,12 @@
2002-08-04 Han-Wen <hanwen@cs.uu.nl>
2002-08-04 Han-Wen Nienhuys <hanwen@cs.uu.nl>
* ports.c (scm_new_port_table_entry): change function from
scm_add_to_port_table. This prevents cells with null-pointers from
being exposed to GC.
* vports.c (s_scm_make_soft_port) strports.c (scm_mkstrport),
fports.c (scm_fdes_to_port): Use scm_new_port_table_entry().
* gc.c (s_scm_gc_stats): add cell-yield and malloc-yield statistic
to gc-stats.

View file

@ -436,12 +436,11 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
SCM_MISC_ERROR ("requested file mode not available on fdes", SCM_EOL);
}
port = scm_cell (scm_tc16_fport, 0);
SCM_DEFER_INTS;
pt = scm_add_to_port_table (port);
SCM_SETPTAB_ENTRY (port, pt);
SCM_SET_CELL_TYPE (port, (scm_tc16_fport | mode_bits));
pt = scm_new_port_table_entry ();
port = scm_cell (scm_tc16_fport | mode_bits, (scm_t_bits) pt);
pt->port = port;
{
scm_t_fport *fp
= (scm_t_fport *) scm_gc_malloc (sizeof (scm_t_fport), "file port");

View file

@ -451,13 +451,12 @@ scm_t_port **scm_port_table;
long scm_port_table_size = 0; /* Number of ports in scm_port_table. */
long scm_port_table_room = 20; /* Size of the array. */
/* Add a port to the table. */
scm_t_port *
scm_add_to_port_table (SCM port)
#define FUNC_NAME "scm_add_to_port_table"
scm_new_port_table_entry (void)
#define FUNC_NAME "scm_new_port_table_entry"
{
scm_t_port *entry;
scm_t_port *entry = (scm_t_port *) scm_gc_malloc (sizeof (scm_t_port), "port");
if (scm_port_table_size == scm_port_table_room)
{
@ -469,9 +468,8 @@ scm_add_to_port_table (SCM port)
scm_port_table = (scm_t_port **) newt;
scm_port_table_room *= 2;
}
entry = (scm_t_port *) scm_gc_malloc (sizeof (scm_t_port), "port");
entry->port = port;
entry->port = SCM_EOL;
entry->entry = scm_port_table_size;
entry->revealed = 0;
entry->stream = 0;
@ -491,7 +489,6 @@ scm_add_to_port_table (SCM port)
#undef FUNC_NAME
/* Remove a port from the table and destroy it. */
void
scm_remove_from_port_table (SCM port)
#define FUNC_NAME "scm_remove_from_port_table"
@ -1527,20 +1524,22 @@ write_void_port (SCM port SCM_UNUSED,
SCM
scm_void_port (char *mode_str)
{
int mode_bits;
SCM answer;
scm_t_port * pt;
answer = scm_cell (scm_tc16_void_port, 0);
SCM_DEFER_INTS;
mode_bits = scm_mode_bits (mode_str);
pt = scm_add_to_port_table (answer);
scm_port_non_buffer (pt);
SCM_SETPTAB_ENTRY (answer, pt);
SCM_SETSTREAM (answer, 0);
SCM_SET_CELL_TYPE (answer, scm_tc16_void_port | mode_bits);
SCM_ALLOW_INTS;
return answer;
{
int mode_bits = scm_mode_bits (mode_str);
scm_t_port * pt = scm_new_port_table_entry ();
SCM answer;
scm_port_non_buffer (pt);
answer = scm_cell (scm_tc16_void_port, 0);
SCM_SETPTAB_ENTRY (answer, pt);
pt->port = answer;
SCM_SETSTREAM (answer, 0);
SCM_SET_CELL_TYPE (answer, scm_tc16_void_port | mode_bits);
SCM_ALLOW_INTS;
return answer;
}
}
SCM_DEFINE (scm_sys_make_void_port, "%make-void-port", 1, 0, 0,

View file

@ -257,7 +257,7 @@ SCM_API SCM scm_current_load_port (void);
SCM_API SCM scm_set_current_input_port (SCM port);
SCM_API SCM scm_set_current_output_port (SCM port);
SCM_API SCM scm_set_current_error_port (SCM port);
SCM_API scm_t_port * scm_add_to_port_table (SCM port);
SCM_API scm_t_port * scm_new_port_table_entry (void);
SCM_API void scm_remove_from_port_table (SCM port);
SCM_API void scm_grow_port_cbuf (SCM port, size_t requested);
SCM_API SCM scm_pt_size (void);

View file

@ -281,9 +281,11 @@ scm_mkstrport (SCM pos, SCM str, long modes, const char *caller)
scm_misc_error ("scm_mkstrport", "port must read or write", SCM_EOL);
z = scm_cell (scm_tc16_strport, 0);
SCM_DEFER_INTS;
pt = scm_add_to_port_table (z);
pt = scm_new_port_table_entry ();
SCM_SET_CELL_TYPE (z, scm_tc16_strport | modes);
SCM_SETPTAB_ENTRY (z, pt);
pt->port = z;
SCM_SETSTREAM (z, SCM_UNPACK (str));
pt->write_buf = pt->read_buf = SCM_STRING_UCHARS (str);
pt->read_pos = pt->write_pos = pt->read_buf + SCM_INUM (pos);

View file

@ -189,12 +189,14 @@ SCM_DEFINE (scm_make_soft_port, "make-soft-port", 2, 0, 0,
SCM z;
SCM_VALIDATE_VECTOR_LEN (1, pv,5);
SCM_VALIDATE_STRING (2, modes);
z = scm_cell (scm_tc16_sfport, 0);
SCM_DEFER_INTS;
pt = scm_add_to_port_table (z);
pt = scm_new_port_table_entry ();
scm_port_non_buffer (pt);
SCM_SET_CELL_TYPE (z, scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)));
z = scm_cell (scm_tc16_sfport | scm_mode_bits (SCM_STRING_CHARS (modes)), 0);
SCM_SETPTAB_ENTRY (z, pt);
pt->port = z;
SCM_SETSTREAM (z, SCM_UNPACK (pv));
SCM_ALLOW_INTS;
return z;