From 682d78d05e567a46b1c443c5f852c575ab529f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 15 Oct 2009 00:56:56 +0200 Subject: [PATCH] Use GC-managed memory for port->encoding. * libguile/ports.c (scm_new_port_table_entry): Use `scm_gc_strdup ()' instead of `strdup ()' for `entry->encoding'. (scm_i_set_port_encoding_x): Likewise. Remove free(3) call. (scm_i_remove_port): Don't explicitly free memory. (scm_unget_byte): Remove outdated and misleading comment. --- libguile/ports.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/libguile/ports.c b/libguile/ports.c index 53f64e3eb..c3415c770 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -587,7 +587,7 @@ scm_new_port_table_entry (scm_t_bits tag) if ((enc = scm_i_get_port_encoding (SCM_BOOL_F)) == NULL) entry->encoding = NULL; else - entry->encoding = strdup (enc); + entry->encoding = scm_gc_strdup (enc, "port"); entry->ilseq_handler = scm_i_get_conversion_strategy (SCM_BOOL_F); SCM_SET_CELL_TYPE (z, tag); @@ -627,14 +627,11 @@ scm_i_remove_port (SCM port) #define FUNC_NAME "scm_remove_port" { scm_t_port *p = SCM_PTAB_ENTRY (port); - if (p->putback_buf) - scm_gc_free (p->putback_buf, p->putback_buf_size, "putback buffer"); - if (p->encoding) - { - free (p->encoding); - p->encoding = NULL; - } - scm_gc_free (p, sizeof (scm_t_port), "port"); + + scm_port_non_buffer (p); + + p->putback_buf = NULL; + p->putback_buf_size = 0; SCM_SETPTAB_ENTRY (port, 0); scm_hashq_remove_x (scm_i_port_weak_hash, port); @@ -1498,8 +1495,6 @@ scm_unget_byte (int c, SCM port) { size_t new_size = pt->read_buf_size * 2; unsigned char *tmp = (unsigned char *) - /* XXX: Can we use `GC_REALLOC' with `GC_MALLOC_ATOMIC'-allocated - data? (Ludo) */ scm_gc_realloc (pt->putback_buf, pt->read_buf_size, new_size, "putback buffer"); @@ -2024,12 +2019,10 @@ scm_i_set_port_encoding_x (SCM port, const char *enc) { /* Set the character encoding for this port. */ pt = SCM_PTAB_ENTRY (port); - if (pt->encoding) - free (pt->encoding); if (valid_enc == NULL) pt->encoding = NULL; else - pt->encoding = strdup (valid_enc); + pt->encoding = scm_gc_strdup (valid_enc, "port"); } }