summaryrefslogtreecommitdiff
path: root/src/terminal.c
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2007-09-20 21:32:07 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2007-09-20 21:32:07 +0000
commit0d82a52284c401199023109c413b626c601747ae (patch)
tree7d56db6254a8e61748df61ded40cc0384374b3d3 /src/terminal.c
parent6b17b3326b606c0b6995524d50b8e063e10db229 (diff)
downloademacs-0d82a52284c401199023109c413b626c601747ae.tar.gz
(get_terminal): Handle terminals.
Make sure the terminal returned is live. (create_terminal): Use allocate_terminal. (mark_terminals): Move to alloc.c. (delete_terminal): Use terminal->name as liveness status. NULL out fields after freeing their contents. Don't deallocate the object. (Fframe_terminal): Use FRAME_TERMINAL. Return the terminal object rather than an int. (Fterminal_live_p): Accept non-integer arguments. (Fterminal_list): Return terminal objects rather than an ints.
Diffstat (limited to 'src/terminal.c')
-rw-r--r--src/terminal.c78
1 files changed, 36 insertions, 42 deletions
diff --git a/src/terminal.c b/src/terminal.c
index c7d3da5d935..39407507108 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -205,8 +205,12 @@ get_terminal (Lisp_Object terminal, int throw)
if (NILP (terminal))
terminal = selected_frame;
- if (INTEGERP (terminal))
+ if (TERMINALP (terminal))
+ result = XTERMINAL (terminal);
+
+ else if (INTEGERP (terminal))
{
+ /* FIXME: Get rid of the use of integers to represent terminals. */
struct terminal *t;
for (t = terminal_list; t; t = t->next_terminal)
@@ -214,6 +218,7 @@ get_terminal (Lisp_Object terminal, int throw)
if (t->id == XINT (terminal))
{
result = t;
+ eassert (t->name != NULL);
break;
}
}
@@ -223,6 +228,9 @@ get_terminal (Lisp_Object terminal, int throw)
result = FRAME_TERMINAL (XFRAME (terminal));
}
+ if (result && !result->name)
+ result = NULL;
+
if (result == NULL && throw)
wrong_type_argument (Qterminal_live_p, terminal);
@@ -236,9 +244,9 @@ get_terminal (Lisp_Object terminal, int throw)
struct terminal *
create_terminal (void)
{
- struct terminal *terminal = (struct terminal *) xmalloc (sizeof (struct terminal));
-
- bzero (terminal, sizeof (struct terminal));
+ struct terminal *terminal = allocate_terminal ();
+
+ terminal->name = NULL;
terminal->next_terminal = terminal_list;
terminal_list = terminal;
@@ -256,20 +264,6 @@ create_terminal (void)
return terminal;
}
-/* Mark the Lisp pointers in the terminal objects.
- Called by the Fgarbage_collector. */
-
-void
-mark_terminals (void)
-{
- struct terminal *t;
- for (t = terminal_list; t; t = t->next_terminal)
- {
- mark_object (t->param_alist);
- }
-}
-
-
/* Low-level function to close all frames on a terminal, remove it
from the terminal list and free its memory. */
@@ -281,9 +275,10 @@ delete_terminal (struct terminal *terminal)
/* Protect against recursive calls. Fdelete_frame calls the
delete_terminal_hook when we delete our last frame. */
- if (terminal->deleted)
+ if (!terminal->name)
return;
- terminal->deleted = 1;
+ xfree (terminal->name);
+ terminal->name = NULL;
/* Check for live frames that are still on this terminal. */
FOR_EACH_FRAME (tail, frame)
@@ -300,20 +295,18 @@ delete_terminal (struct terminal *terminal)
abort ();
*tp = terminal->next_terminal;
- if (terminal->keyboard_coding)
- xfree (terminal->keyboard_coding);
- if (terminal->terminal_coding)
- xfree (terminal->terminal_coding);
- if (terminal->name)
- xfree (terminal->name);
+ xfree (terminal->keyboard_coding);
+ terminal->keyboard_coding = NULL;
+ xfree (terminal->terminal_coding);
+ terminal->terminal_coding = NULL;
#ifdef MULTI_KBOARD
if (terminal->kboard && --terminal->kboard->reference_count == 0)
- delete_kboard (terminal->kboard);
+ {
+ delete_kboard (terminal->kboard);
+ terminal->kboard = NULL;
+ }
#endif
-
- bzero (terminal, sizeof (struct terminal));
- xfree (terminal);
}
DEFUN ("delete-terminal", Fdelete_terminal, Sdelete_terminal, 0, 2, 0,
@@ -364,12 +357,16 @@ The terminal device is represented by its integer identifier. */)
CHECK_LIVE_FRAME (frame);
- t = get_terminal (frame, 0);
+ t = FRAME_TERMINAL (XFRAME (frame));
if (!t)
return Qnil;
else
- return make_number (t->id);
+ {
+ Lisp_Object terminal;
+ XSETTERMINAL (terminal, t);
+ return terminal;
+ }
}
DEFUN ("terminal-live-p", Fterminal_live_p, Sterminal_live_p, 1, 1, 0,
@@ -377,17 +374,12 @@ DEFUN ("terminal-live-p", Fterminal_live_p, Sterminal_live_p, 1, 1, 0,
Value is nil if OBJECT is not a live display terminal.
If object is a live display terminal, the return value indicates what
sort of output terminal it uses. See the documentation of `framep' for
-possible return values.
-
-Display terminals are represented by their integer identifiers. */)
+possible return values. */)
(object)
Lisp_Object object;
{
struct terminal *t;
- if (!INTEGERP (object))
- return Qnil;
-
t = get_terminal (object, 0);
if (!t)
@@ -412,15 +404,17 @@ Display terminals are represented by their integer identifiers. */)
}
DEFUN ("terminal-list", Fterminal_list, Sterminal_list, 0, 0, 0,
- doc: /* Return a list of all terminal devices.
-Terminal devices are represented by their integer identifiers. */)
+ doc: /* Return a list of all terminal devices. */)
()
{
- Lisp_Object terminals = Qnil;
+ Lisp_Object terminal, terminals = Qnil;
struct terminal *t;
for (t = terminal_list; t; t = t->next_terminal)
- terminals = Fcons (make_number (t->id), terminals);
+ {
+ XSETTERMINAL (terminal, t);
+ terminals = Fcons (terminal, terminals);
+ }
return terminals;
}