variables. These values may be undefined, or unreasonably large.
Instead, allocate small tables and grow them as needed.
/* -*-C-*-
-$Id: ntproc.c,v 1.12 2007/01/05 21:19:25 cph Exp $
+$Id: ntproc.c,v 1.13 2008/01/03 00:30:38 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
int
OS_process_valid_p (Tprocess process)
{
+ if (process > OS_process_table_size)
+ return (0);
switch (PROCESS_RAW_STATUS (process))
{
case process_status_exited:
/* -*-C-*-
-$Id: os2proc.c,v 1.11 2007/01/05 21:19:25 cph Exp $
+$Id: os2proc.c,v 1.12 2008/01/03 00:30:39 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
int
OS_process_valid_p (Tprocess process)
{
+ if (process > OS_process_table_size)
+ return (0);
switch (PROCESS_RAW_STATUS (process))
{
case process_status_exited:
/* -*-C-*-
-$Id: osio.h,v 1.22 2007/04/22 16:31:23 cph Exp $
+$Id: osio.h,v 1.23 2008/01/03 00:30:40 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
};
extern size_t OS_channel_table_size;
-#define NO_CHANNEL OS_channel_table_size
+#define NO_CHANNEL ((size_t) -1)
extern int OS_channel_open_p (Tchannel channel);
extern void OS_channel_close (Tchannel channel);
extern void OS_channel_close_noerror (Tchannel channel);
/* -*-C-*-
-$Id: osproc.h,v 1.15 2007/04/22 16:31:23 cph Exp $
+$Id: osproc.h,v 1.16 2008/01/03 00:30:41 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
};
extern size_t OS_process_table_size;
-#define NO_PROCESS OS_process_table_size
+#define NO_PROCESS ((size_t) -1)
extern enum process_jc_status scheme_jc_status;
/* OS_make_subprocess is obsolete; use OS-specific procedure. */
/* -*-C-*-
-$Id: prosio.c,v 1.28 2007/04/22 16:31:23 cph Exp $
+$Id: prosio.c,v 1.29 2008/01/03 00:30:42 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
#endif
\f
Tchannel
-arg_to_channel (SCHEME_OBJECT argument,
- int arg_number)
+arg_to_channel (SCHEME_OBJECT argument, int arg_number)
{
- if (! ((INTEGER_P (argument)) && (integer_to_ulong_p (argument))))
+ unsigned long channel = (arg_ulong_integer (arg_number));
+ if (! (channel < OS_channel_table_size))
error_wrong_type_arg (arg_number);
- {
- unsigned long channel = (integer_to_ulong (argument));
- if (! (channel < OS_channel_table_size))
- error_wrong_type_arg (arg_number);
- return (channel);
- }
+ return (channel);
}
Tchannel
/* -*-C-*-
-$Id: prosproc.c,v 1.25 2007/04/22 16:31:23 cph Exp $
+$Id: prosproc.c,v 1.26 2008/01/03 00:30:43 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
static Tprocess
arg_process (int argument_number)
{
- Tprocess process
- = (arg_index_integer (argument_number, OS_process_table_size));
- if (! (OS_process_valid_p (process)))
+ Tprocess process = (arg_ulong_integer (argument_number));
+ if (!OS_process_valid_p (process))
error_bad_range_arg (argument_number);
return (process);
}
obstack_grow ((&scratch_obstack), (&process), (sizeof (Tprocess)));
}
{
- unsigned int n_processes =
- ((obstack_object_size ((&scratch_obstack))) / (sizeof (Tprocess)));
+ unsigned int n_processes
+ = ((obstack_object_size ((&scratch_obstack))) / (sizeof (Tprocess)));
if (n_processes == 0)
PRIMITIVE_RETURN (SHARP_F);
{
Tprocess * processes = (obstack_finish (&scratch_obstack));
Tprocess * scan_processes = processes;
- SCHEME_OBJECT vector =
- (allocate_marked_vector (TC_VECTOR, n_processes, 1));
+ SCHEME_OBJECT vector
+ = (allocate_marked_vector (TC_VECTOR, n_processes, 1));
SCHEME_OBJECT * scan_vector = (VECTOR_LOC (vector, 0));
SCHEME_OBJECT * end_vector = (scan_vector + n_processes);
while (scan_vector < end_vector)
/* -*-C-*-
-$Id: ux.h,v 1.86 2007/09/04 03:35:19 riastradh Exp $
+$Id: ux.h,v 1.87 2008/01/03 00:30:44 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
extern cc_t UX_PC_VDISABLE (int fildes);
extern clock_t UX_SC_CLK_TCK (void);
# define UX_SC_OPEN_MAX() ((size_t) (sysconf (_SC_OPEN_MAX)))
-# define UX_SC_CHILD_MAX() ((size_t) (sysconf (_SC_CHILD_MAX)))
# ifdef _POSIX_JOB_CONTROL
# define UX_SC_JOB_CONTROL() 1
# endif
# endif
-# ifdef CHILD_MAX
-# define UX_SC_CHILD_MAX() CHILD_MAX
-# else
-# define UX_SC_CHILD_MAX() 6
-# endif
-
# ifdef CLK_TCK
# define UX_SC_CLK_TCK() CLK_TCK
# else
/* -*-C-*-
-$Id: uxio.c,v 1.57 2007/04/22 16:31:23 cph Exp $
+$Id: uxio.c,v 1.58 2008/01/03 00:30:45 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
void
UX_initialize_channels (void)
{
- OS_channel_table_size = (UX_SC_OPEN_MAX ());
- channel_table =
- (UX_malloc (OS_channel_table_size * (sizeof (struct channel))));
+ OS_channel_table_size = 64;
+ channel_table
+ = (UX_malloc (OS_channel_table_size * (sizeof (struct channel))));
if (channel_table == 0)
{
fprintf (stderr, "\nUnable to allocate channel table.\n");
Tchannel
channel_allocate (void)
{
- Tchannel channel = 0;
- while (1)
- {
- if (channel == OS_channel_table_size)
+ Tchannel channel;
+ for (channel = 0; (channel < OS_channel_table_size); channel += 1)
+ if (CHANNEL_CLOSED_P (channel))
+ return (channel);
+ {
+ size_t old_size = OS_channel_table_size;
+ size_t new_size = ((old_size * 5) / 4);
+ struct channel * new_table
+ = (UX_realloc (channel_table, (new_size * (sizeof (struct channel)))));
+ if (new_table == 0)
+ {
error_out_of_channels ();
- if (CHANNEL_CLOSED_P (channel))
- return (channel);
- channel += 1;
- }
+ return (NO_CHANNEL);
+ }
+ OS_channel_table_size = new_size;
+ channel_table = new_table;
+ for (channel = old_size; (channel < new_size); channel += 1)
+ MARK_CHANNEL_CLOSED (channel);
+ return (old_size);
+ }
}
\f
int
/* -*-C-*-
-$Id: uxproc.c,v 1.35 2007/04/22 16:31:23 cph Exp $
+$Id: uxproc.c,v 1.36 2008/01/03 00:30:46 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
void
UX_initialize_processes (void)
{
- OS_process_table_size = (UX_SC_CHILD_MAX ());
- process_table =
- (UX_malloc (OS_process_table_size * (sizeof (struct process))));
+ OS_process_table_size = 64;
+ process_table
+ = (UX_malloc (OS_process_table_size * (sizeof (struct process))));
if (process_table == 0)
{
fprintf (stderr, "\nUnable to allocate process table.\n");
for (process = 0; (process < OS_process_table_size); process += 1)
if ((PROCESS_RAW_STATUS (process)) == process_status_free)
{
- Tprocess * pp = (dstack_alloc (sizeof (Tprocess)));
- (*pp) = process;
- transaction_record_action (tat_abort, process_allocate_abort, pp);
(PROCESS_RAW_STATUS (process)) = process_status_allocated;
- return (process);
+ break;
}
- error_out_of_processes ();
- return (NO_PROCESS);
+ if (process == OS_process_table_size)
+ {
+ size_t old_size = OS_process_table_size;
+ size_t new_size = ((old_size * 5) / 4);
+ struct process * new_table
+ = (UX_realloc (process_table, (new_size * (sizeof (struct process)))));
+ if (new_table == 0)
+ {
+ error_out_of_processes ();
+ return (NO_PROCESS);
+ }
+ OS_process_table_size = new_size;
+ process_table = new_table;
+ for (process = old_size; (process < new_size); process += 1)
+ OS_process_deallocate (process);
+ process = old_size;
+ }
+ {
+ Tprocess * pp = (dstack_alloc (sizeof (Tprocess)));
+ (*pp) = process;
+ transaction_record_action (tat_abort, process_allocate_abort, pp);
+ }
+ return (process);
}
void
}
{
/* Close all other file descriptors. */
- int fd = 0;
int open_max = (UX_SC_OPEN_MAX ());
- while (fd < open_max)
- {
- if ((fd == STDIN_FILENO)
- ? (channel_in_type == process_channel_type_none)
- : (fd == STDOUT_FILENO)
- ? (channel_out_type == process_channel_type_none)
- : (fd == STDERR_FILENO)
- ? (channel_err_type == process_channel_type_none)
- : 1)
- UX_close (fd);
- fd += 1;
- }
+ int fd;
+ for (fd = 0; (fd < open_max); fd += 1)
+ if ((fd == STDIN_FILENO)
+ ? (channel_in_type == process_channel_type_none)
+ : (fd == STDOUT_FILENO)
+ ? (channel_out_type == process_channel_type_none)
+ : (fd == STDERR_FILENO)
+ ? (channel_err_type == process_channel_type_none)
+ : 1)
+ UX_close (fd);
}
/* Put the signal mask and handlers in a normal state. */
int
OS_process_valid_p (Tprocess process)
{
+ if (process > OS_process_table_size)
+ return (0);
switch (PROCESS_RAW_STATUS (process))
{
case process_status_exited:
/* -*-C-*-
-$Id: uxterm.c,v 1.34 2007/04/22 16:31:23 cph Exp $
+$Id: uxterm.c,v 1.35 2008/01/03 00:30:47 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
Ttty_state state;
};
+static size_t terminal_table_size;
static struct terminal_state * terminal_table;
#define TERMINAL_BUFFER(channel) ((terminal_table[(channel)]) . buffer)
#define TERMINAL_ORIGINAL_STATE(channel) ((terminal_table[(channel)]) . state)
void
UX_initialize_terminals (void)
{
- terminal_table =
- (UX_malloc (OS_channel_table_size * (sizeof (struct terminal_state))));
+ terminal_table_size = OS_channel_table_size;
+ terminal_table
+ = (UX_malloc (terminal_table_size * (sizeof (struct terminal_state))));
if (terminal_table == 0)
{
fprintf (stderr, "\nUnable to allocate terminal table.\n");
{
UX_free (terminal_table);
terminal_table = 0;
+ terminal_table_size = 0;
}
/* This is called from the file-opening code. */
void
terminal_open (Tchannel channel)
{
+ if (terminal_table_size != OS_channel_table_size)
+ {
+ terminal_table_size = OS_channel_table_size;
+ terminal_table
+ = (OS_realloc (terminal_table,
+ (terminal_table_size
+ * (sizeof (struct terminal_state)))));
+ }
(TERMINAL_BUFFER (channel)) = (-1);
get_terminal_state (channel, (& (TERMINAL_ORIGINAL_STATE (channel))));
}