mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-13 07:10:20 +02:00
* gc.c (scm_must_malloc): changed the comment explaining when
scm_must variants of malloc/free etc., should be used, based on explanation from Dirk Herrmann. * fports.c (scm_fport_buffer_add): use FUNC_NAME instead of a local string with procedure name. use scm_must_malloc instead of malloc. (scm_setvbuf, scm_fdes_to_port, fport_close): use scm_must variants of malloc/free. * ports.c (scm_add_to_port_table, scm_remove_from_port_table, scm_ungetc): use scm_must variants of malloc/realloc/free. (scm_add_to_port_table, scm_ungetc): define FUNC_NAME.
This commit is contained in:
parent
cf7a5ee536
commit
c6c79933b5
4 changed files with 45 additions and 32 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2001-03-17 Gary Houston <ghouston@arglist.com>
|
||||||
|
|
||||||
|
* gc.c (scm_must_malloc): changed the comment explaining when
|
||||||
|
scm_must variants of malloc/free etc., should be used, based on
|
||||||
|
explanation from Dirk Herrmann.
|
||||||
|
* fports.c (scm_fport_buffer_add): use FUNC_NAME instead of a local
|
||||||
|
string with procedure name. use scm_must_malloc instead of malloc.
|
||||||
|
(scm_setvbuf, scm_fdes_to_port, fport_close): use scm_must variants
|
||||||
|
of malloc/free.
|
||||||
|
* ports.c (scm_add_to_port_table, scm_remove_from_port_table,
|
||||||
|
scm_ungetc): use scm_must variants of malloc/realloc/free.
|
||||||
|
(scm_add_to_port_table, scm_ungetc): define FUNC_NAME.
|
||||||
|
|
||||||
2001-03-17 Dirk Herrmann <D.Herrmann@tu-bs.de>
|
2001-03-17 Dirk Herrmann <D.Herrmann@tu-bs.de>
|
||||||
|
|
||||||
* __scm.h (SCM_ASSERT, SCM_WTA_DISPATCH_0, SCM_WTA_DISPATCH_1,
|
* __scm.h (SCM_ASSERT, SCM_WTA_DISPATCH_0, SCM_WTA_DISPATCH_1,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 1995,1996,1997,1998,1999, 2000 Free Software Foundation, Inc.
|
/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -80,10 +80,10 @@ static const int default_buffer_size = 1024;
|
||||||
0 for no buffer. */
|
0 for no buffer. */
|
||||||
static void
|
static void
|
||||||
scm_fport_buffer_add (SCM port, int read_size, int write_size)
|
scm_fport_buffer_add (SCM port, int read_size, int write_size)
|
||||||
|
#define FUNC_NAME "scm_fport_buffer_add"
|
||||||
{
|
{
|
||||||
struct scm_fport *fp = SCM_FSTREAM (port);
|
struct scm_fport *fp = SCM_FSTREAM (port);
|
||||||
scm_port *pt = SCM_PTAB_ENTRY (port);
|
scm_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
char *s_scm_fport_buffer_add = "scm_fport_buffer_add";
|
|
||||||
|
|
||||||
if (read_size == -1 || write_size == -1)
|
if (read_size == -1 || write_size == -1)
|
||||||
{
|
{
|
||||||
|
@ -104,9 +104,7 @@ scm_fport_buffer_add (SCM port, int read_size, int write_size)
|
||||||
|
|
||||||
if (SCM_INPUT_PORT_P (port) && read_size > 0)
|
if (SCM_INPUT_PORT_P (port) && read_size > 0)
|
||||||
{
|
{
|
||||||
pt->read_buf = malloc (read_size);
|
pt->read_buf = scm_must_malloc (read_size, FUNC_NAME);
|
||||||
if (pt->read_buf == NULL)
|
|
||||||
scm_memory_error (s_scm_fport_buffer_add);
|
|
||||||
pt->read_pos = pt->read_end = pt->read_buf;
|
pt->read_pos = pt->read_end = pt->read_buf;
|
||||||
pt->read_buf_size = read_size;
|
pt->read_buf_size = read_size;
|
||||||
}
|
}
|
||||||
|
@ -118,9 +116,7 @@ scm_fport_buffer_add (SCM port, int read_size, int write_size)
|
||||||
|
|
||||||
if (SCM_OUTPUT_PORT_P (port) && write_size > 0)
|
if (SCM_OUTPUT_PORT_P (port) && write_size > 0)
|
||||||
{
|
{
|
||||||
pt->write_buf = malloc (write_size);
|
pt->write_buf = scm_must_malloc (write_size, FUNC_NAME);
|
||||||
if (pt->write_buf == NULL)
|
|
||||||
scm_memory_error (s_scm_fport_buffer_add);
|
|
||||||
pt->write_pos = pt->write_buf;
|
pt->write_pos = pt->write_buf;
|
||||||
pt->write_buf_size = write_size;
|
pt->write_buf_size = write_size;
|
||||||
}
|
}
|
||||||
|
@ -136,6 +132,7 @@ scm_fport_buffer_add (SCM port, int read_size, int write_size)
|
||||||
else
|
else
|
||||||
SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0);
|
SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0);
|
||||||
}
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
||||||
(SCM port, SCM mode, SCM size),
|
(SCM port, SCM mode, SCM size),
|
||||||
|
@ -189,9 +186,9 @@ SCM_DEFINE (scm_setvbuf, "setvbuf", 2, 1, 0,
|
||||||
|
|
||||||
/* silently discards buffered chars. */
|
/* silently discards buffered chars. */
|
||||||
if (pt->read_buf != &pt->shortbuf)
|
if (pt->read_buf != &pt->shortbuf)
|
||||||
free (pt->read_buf);
|
scm_must_free (pt->read_buf);
|
||||||
if (pt->write_buf != &pt->shortbuf)
|
if (pt->write_buf != &pt->shortbuf)
|
||||||
free (pt->write_buf);
|
scm_must_free (pt->write_buf);
|
||||||
|
|
||||||
scm_fport_buffer_add (port, csize, csize);
|
scm_fport_buffer_add (port, csize, csize);
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
|
@ -386,9 +383,9 @@ scm_fdes_to_port (int fdes, char *mode, SCM name)
|
||||||
|
|
||||||
{
|
{
|
||||||
struct scm_fport *fp
|
struct scm_fport *fp
|
||||||
= (struct scm_fport *) malloc (sizeof (struct scm_fport));
|
= (struct scm_fport *) scm_must_malloc (sizeof (struct scm_fport),
|
||||||
if (fp == NULL)
|
FUNC_NAME);
|
||||||
SCM_MEMORY_ERROR;
|
|
||||||
fp->fdes = fdes;
|
fp->fdes = fdes;
|
||||||
pt->rw_random = SCM_FDES_RANDOM_P (fdes);
|
pt->rw_random = SCM_FDES_RANDOM_P (fdes);
|
||||||
SCM_SETSTREAM (port, fp);
|
SCM_SETSTREAM (port, fp);
|
||||||
|
@ -768,10 +765,10 @@ fport_close (SCM port)
|
||||||
if (pt->read_buf == pt->putback_buf)
|
if (pt->read_buf == pt->putback_buf)
|
||||||
pt->read_buf = pt->saved_read_buf;
|
pt->read_buf = pt->saved_read_buf;
|
||||||
if (pt->read_buf != &pt->shortbuf)
|
if (pt->read_buf != &pt->shortbuf)
|
||||||
free (pt->read_buf);
|
scm_must_free (pt->read_buf);
|
||||||
if (pt->write_buf != &pt->shortbuf)
|
if (pt->write_buf != &pt->shortbuf)
|
||||||
free (pt->write_buf);
|
scm_must_free (pt->write_buf);
|
||||||
free ((char *) fp);
|
scm_must_free ((char *) fp);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1839,10 +1839,11 @@ scm_gc_sweep ()
|
||||||
* scm_must_malloc, scm_must_realloc, scm_must_free, scm_done_malloc,
|
* scm_must_malloc, scm_must_realloc, scm_must_free, scm_done_malloc,
|
||||||
* scm_done_free
|
* scm_done_free
|
||||||
*
|
*
|
||||||
* These functions provide services comperable to malloc, realloc, and
|
* These functions provide services comparable to malloc, realloc, and
|
||||||
* free. They are for allocating malloced parts of scheme objects.
|
* free. They should be used when allocating memory that will be under
|
||||||
* The primary purpose of the front end is to impose calls to gc. */
|
* control of the garbage collector, i.e., if the memory may be freed
|
||||||
|
* during garbage collection.
|
||||||
|
*/
|
||||||
|
|
||||||
/* scm_must_malloc
|
/* scm_must_malloc
|
||||||
* Return newly malloced storage or throw an error.
|
* Return newly malloced storage or throw an error.
|
||||||
|
|
|
@ -431,11 +431,14 @@ int scm_port_table_room = 20; /* Size of the array. */
|
||||||
|
|
||||||
scm_port *
|
scm_port *
|
||||||
scm_add_to_port_table (SCM port)
|
scm_add_to_port_table (SCM port)
|
||||||
|
#define FUNC_NAME "scm_add_to_port_table"
|
||||||
{
|
{
|
||||||
scm_port *entry;
|
scm_port *entry;
|
||||||
|
|
||||||
if (scm_port_table_size == scm_port_table_room)
|
if (scm_port_table_size == scm_port_table_room)
|
||||||
{
|
{
|
||||||
|
/* initial malloc is in gc.c. this doesn't use scm_must_malloc etc.,
|
||||||
|
since it can never be freed during gc. */
|
||||||
void *newt = realloc ((char *) scm_port_table,
|
void *newt = realloc ((char *) scm_port_table,
|
||||||
(scm_sizet) (sizeof (scm_port *)
|
(scm_sizet) (sizeof (scm_port *)
|
||||||
* scm_port_table_room * 2));
|
* scm_port_table_room * 2));
|
||||||
|
@ -444,9 +447,7 @@ scm_add_to_port_table (SCM port)
|
||||||
scm_port_table = (scm_port **) newt;
|
scm_port_table = (scm_port **) newt;
|
||||||
scm_port_table_room *= 2;
|
scm_port_table_room *= 2;
|
||||||
}
|
}
|
||||||
entry = (scm_port *) malloc (sizeof (scm_port));
|
entry = (scm_port *) scm_must_malloc (sizeof (scm_port), FUNC_NAME);
|
||||||
if (entry == NULL)
|
|
||||||
scm_memory_error ("scm_add_to_port_table");
|
|
||||||
|
|
||||||
entry->port = port;
|
entry->port = port;
|
||||||
entry->entry = scm_port_table_size;
|
entry->entry = scm_port_table_size;
|
||||||
|
@ -465,6 +466,7 @@ scm_add_to_port_table (SCM port)
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
/* Remove a port from the table and destroy it. */
|
/* Remove a port from the table and destroy it. */
|
||||||
|
|
||||||
|
@ -478,8 +480,8 @@ scm_remove_from_port_table (SCM port)
|
||||||
if (i >= scm_port_table_size)
|
if (i >= scm_port_table_size)
|
||||||
SCM_MISC_ERROR ("Port not in table: ~S", SCM_LIST1 (port));
|
SCM_MISC_ERROR ("Port not in table: ~S", SCM_LIST1 (port));
|
||||||
if (p->putback_buf)
|
if (p->putback_buf)
|
||||||
free (p->putback_buf);
|
scm_must_free (p->putback_buf);
|
||||||
free (p);
|
scm_must_free (p);
|
||||||
/* Since we have just freed slot i we can shrink the table by moving
|
/* Since we have just freed slot i we can shrink the table by moving
|
||||||
the last entry to that slot... */
|
the last entry to that slot... */
|
||||||
if (i < scm_port_table_size - 1)
|
if (i < scm_port_table_size - 1)
|
||||||
|
@ -1101,6 +1103,7 @@ scm_end_input (SCM port)
|
||||||
|
|
||||||
void
|
void
|
||||||
scm_ungetc (int c, SCM port)
|
scm_ungetc (int c, SCM port)
|
||||||
|
#define FUNC_NAME "scm_ungetc"
|
||||||
{
|
{
|
||||||
scm_port *pt = SCM_PTAB_ENTRY (port);
|
scm_port *pt = SCM_PTAB_ENTRY (port);
|
||||||
|
|
||||||
|
@ -1112,11 +1115,10 @@ scm_ungetc (int c, SCM port)
|
||||||
&& pt->read_buf == pt->read_pos)
|
&& pt->read_buf == pt->read_pos)
|
||||||
{
|
{
|
||||||
int new_size = pt->read_buf_size * 2;
|
int new_size = pt->read_buf_size * 2;
|
||||||
unsigned char *tmp =
|
unsigned char *tmp = (unsigned char *)
|
||||||
(unsigned char *) realloc (pt->putback_buf, new_size);
|
scm_must_realloc (pt->putback_buf, pt->read_buf_size, new_size,
|
||||||
|
FUNC_NAME);
|
||||||
|
|
||||||
if (tmp == NULL)
|
|
||||||
scm_memory_error ("scm_ungetc");
|
|
||||||
pt->read_pos = pt->read_buf = pt->putback_buf = tmp;
|
pt->read_pos = pt->read_buf = pt->putback_buf = tmp;
|
||||||
pt->read_end = pt->read_buf + pt->read_buf_size;
|
pt->read_end = pt->read_buf + pt->read_buf_size;
|
||||||
pt->read_buf_size = pt->putback_buf_size = new_size;
|
pt->read_buf_size = pt->putback_buf_size = new_size;
|
||||||
|
@ -1141,9 +1143,8 @@ scm_ungetc (int c, SCM port)
|
||||||
if (pt->putback_buf == NULL)
|
if (pt->putback_buf == NULL)
|
||||||
{
|
{
|
||||||
pt->putback_buf
|
pt->putback_buf
|
||||||
= (unsigned char *) malloc (SCM_INITIAL_PUTBACK_BUF_SIZE);
|
= (unsigned char *) scm_must_malloc (SCM_INITIAL_PUTBACK_BUF_SIZE,
|
||||||
if (pt->putback_buf == NULL)
|
FUNC_NAME);
|
||||||
scm_memory_error ("scm_ungetc");
|
|
||||||
pt->putback_buf_size = SCM_INITIAL_PUTBACK_BUF_SIZE;
|
pt->putback_buf_size = SCM_INITIAL_PUTBACK_BUF_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,6 +1173,7 @@ scm_ungetc (int c, SCM port)
|
||||||
else
|
else
|
||||||
SCM_COL(port) -= 1;
|
SCM_COL(port) -= 1;
|
||||||
}
|
}
|
||||||
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue