[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 96bfe81: Refactor low-level printing for simplicity
From: |
Paul Eggert |
Subject: |
[Emacs-diffs] master 96bfe81: Refactor low-level printing for simplicity |
Date: |
Sun, 19 Apr 2015 15:55:42 +0000 |
branch: master
commit 96bfe816d8107003dba7fd824c2ac2b999a84ae9
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>
Refactor low-level printing for simplicity
* src/print.c (PRINTDECLARE): Remove. Move its contents into
PRINTPREPARE; doable now that we assume C99. All callers changed.
(PRINTCHAR): Remove, as it adds more mystery than clarity.
All callers changed.
(strout): Assume that caller computes length. All callers changed.
(print_c_string): New function.
(write_string, write_string_1): Compute length instead of asking
the caller to compute it. All callers changed.
(write_string): Simplify by using write_string_1.
(write_string_1): Simplify by using print_c_string.
(Fterpri): Compute default val more clearly.
(Fprin1_to_string, print_object):
Assume C99 to avoid unnecessary nesting.
(print_object): Prefer print_c_string to multiple printchar, or
to calling strout with -1 length. Coalesce into sprintf when
this is easy.
---
src/eval.c | 10 +-
src/lisp.h | 2 +-
src/print.c | 470 ++++++++++++++++++++++++++---------------------------------
3 files changed, 211 insertions(+), 271 deletions(-)
diff --git a/src/eval.c b/src/eval.c
index 11d0889..4902261 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3305,27 +3305,27 @@ Output stream used is value of `standard-output'. */)
while (backtrace_p (pdl))
{
- write_string (backtrace_debug_on_exit (pdl) ? "* " : " ", 2);
+ write_string (backtrace_debug_on_exit (pdl) ? "* " : " ");
if (backtrace_nargs (pdl) == UNEVALLED)
{
Fprin1 (Fcons (backtrace_function (pdl), *backtrace_args (pdl)),
Qnil);
- write_string ("\n", -1);
+ write_string ("\n");
}
else
{
tem = backtrace_function (pdl);
Fprin1 (tem, Qnil); /* This can QUIT. */
- write_string ("(", -1);
+ write_string ("(");
{
ptrdiff_t i;
for (i = 0; i < backtrace_nargs (pdl); i++)
{
- if (i) write_string (" ", -1);
+ if (i) write_string (" ");
Fprin1 (backtrace_args (pdl)[i], Qnil);
}
}
- write_string (")\n", -1);
+ write_string (")\n");
}
pdl = backtrace_next (pdl);
}
diff --git a/src/lisp.h b/src/lisp.h
index b730619..55c4c66 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3923,7 +3923,7 @@ extern Lisp_Object Vprin1_to_string_buffer;
extern void debug_print (Lisp_Object) EXTERNALLY_VISIBLE;
extern void temp_output_buffer_setup (const char *);
extern int print_level;
-extern void write_string (const char *, int);
+extern void write_string (const char *);
extern void print_error_message (Lisp_Object, Lisp_Object, const char *,
Lisp_Object);
extern Lisp_Object internal_with_output_to_temp_buffer
diff --git a/src/print.c b/src/print.c
index 58b9c70..916276b 100644
--- a/src/print.c
+++ b/src/print.c
@@ -83,12 +83,11 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
/* Lisp functions to do output using a stream
must have the stream in a variable called printcharfun
- and must start with PRINTPREPARE, end with PRINTFINISH,
- and use PRINTDECLARE to declare common variables.
- Use PRINTCHAR to output one character,
+ and must start with PRINTPREPARE, end with PRINTFINISH.
+ Use printchar to output one character,
or call strout to output a block of characters. */
-#define PRINTDECLARE \
+#define PRINTPREPARE \
struct buffer *old = current_buffer;
\
ptrdiff_t old_point = -1, start_point = -1; \
ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
@@ -96,10 +95,7 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
bool free_print_buffer = 0; \
bool multibyte \
= !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
- Lisp_Object original
-
-#define PRINTPREPARE \
- original = printcharfun; \
+ Lisp_Object original = printcharfun;
\
if (NILP (printcharfun)) printcharfun = Qt; \
if (BUFFERP (printcharfun)) \
{ \
@@ -189,8 +185,6 @@ bool print_output_debug_flag EXTERNALLY_VISIBLE = 1;
? PT_BYTE - start_point_byte : 0)); \
set_buffer_internal (old);
-#define PRINTCHAR(ch) printchar (ch, printcharfun)
-
/* This is used to restore the saved contents of print_buffer
when there is a recursive call to print. */
@@ -248,8 +242,7 @@ printchar (unsigned int ch, Lisp_Object fun)
/* Output SIZE characters, SIZE_BYTE bytes from string PTR using
- method PRINTCHARFUN. If SIZE < 0, use the string length of PTR for
- both SIZE and SIZE_BYTE. PRINTCHARFUN nil means output to
+ method PRINTCHARFUN. PRINTCHARFUN nil means output to
print_buffer. PRINTCHARFUN t means output to the echo area or to
stdout if non-interactive. If neither nil nor t, call Lisp
function PRINTCHARFUN for each character printed. MULTIBYTE
@@ -262,9 +255,6 @@ static void
strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
Lisp_Object printcharfun)
{
- if (size < 0)
- size_byte = size = strlen (ptr);
-
if (NILP (printcharfun))
{
ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
@@ -317,7 +307,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t
size_byte,
while (i < size_byte)
{
int ch = ptr[i++];
- PRINTCHAR (ch);
+ printchar (ch, printcharfun);
}
}
else
@@ -330,7 +320,7 @@ strout (const char *ptr, ptrdiff_t size, ptrdiff_t
size_byte,
int len;
int ch = STRING_CHAR_AND_LENGTH ((const unsigned char *) ptr + i,
len);
- PRINTCHAR (ch);
+ printchar (ch, printcharfun);
i += len;
}
}
@@ -407,7 +397,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
GCPRO1 (string);
if (size == size_byte)
for (i = 0; i < size; i++)
- PRINTCHAR (SREF (string, i));
+ printchar (SREF (string, i), printcharfun);
else
for (i = 0; i < size_byte; )
{
@@ -415,7 +405,7 @@ print_string (Lisp_Object string, Lisp_Object printcharfun)
corresponding character code before handing it to PRINTCHAR. */
int len;
int ch = STRING_CHAR_AND_LENGTH (SDATA (string) + i, len);
- PRINTCHAR (ch);
+ printchar (ch, printcharfun);
i += len;
}
UNGCPRO;
@@ -427,46 +417,45 @@ DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
PRINTCHARFUN defaults to the value of `standard-output' (which see). */)
(Lisp_Object character, Lisp_Object printcharfun)
{
- PRINTDECLARE;
-
if (NILP (printcharfun))
printcharfun = Vstandard_output;
CHECK_NUMBER (character);
PRINTPREPARE;
- PRINTCHAR (XINT (character));
+ printchar (XINT (character), printcharfun);
PRINTFINISH;
return character;
}
-/* Used from outside of print.c to print a block of SIZE
- single-byte chars at DATA on the default output stream.
+/* Print the contents of a unibyte C string STRING using PRINTCHARFUN.
+ The caller should arrange to put this inside PRINTPREPARE and PRINTFINISH.
Do not use this on the contents of a Lisp string. */
-void
-write_string (const char *data, int size)
+static void
+print_c_string (char const *string, Lisp_Object printcharfun)
{
- PRINTDECLARE;
- Lisp_Object printcharfun;
+ ptrdiff_t len = strlen (string);
+ strout (string, len, len, printcharfun);
+}
- printcharfun = Vstandard_output;
+/* Print unibyte C string at DATA on a specified stream PRINTCHARFUN.
+ Do not use this on the contents of a Lisp string. */
+static void
+write_string_1 (const char *data, Lisp_Object printcharfun)
+{
PRINTPREPARE;
- strout (data, size, size, printcharfun);
+ print_c_string (data, printcharfun);
PRINTFINISH;
}
-/* Used to print a block of SIZE single-byte chars at DATA on a
- specified stream PRINTCHARFUN.
+/* Used from outside of print.c to print a C unibyte
+ string at DATA on the default output stream.
Do not use this on the contents of a Lisp string. */
-static void
-write_string_1 (const char *data, int size, Lisp_Object printcharfun)
+void
+write_string (const char *data)
{
- PRINTDECLARE;
-
- PRINTPREPARE;
- strout (data, size, size, printcharfun);
- PRINTFINISH;
+ write_string_1 (data, Vstandard_output);
}
@@ -515,9 +504,8 @@ beginning of a line. Value is non-nil if a newline is
printed.
If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used. */)
(Lisp_Object printcharfun, Lisp_Object ensure)
{
- Lisp_Object val = Qnil;
+ Lisp_Object val;
- PRINTDECLARE;
if (NILP (printcharfun))
printcharfun = Vstandard_output;
PRINTPREPARE;
@@ -529,10 +517,11 @@ If PRINTCHARFUN is omitted or nil, the value of
`standard-output' is used. */)
signal_error ("Unsupported function argument", printcharfun);
else if (noninteractive && !NILP (printcharfun))
val = printchar_stdout_last == 10 ? Qnil : Qt;
- else if (NILP (Fbolp ()))
- val = Qt;
+ else
+ val = NILP (Fbolp ()) ? Qt : Qnil;
- if (!NILP (val)) PRINTCHAR ('\n');
+ if (!NILP (val))
+ printchar ('\n', printcharfun);
PRINTFINISH;
return val;
}
@@ -562,8 +551,6 @@ If PRINTCHARFUN is omitted, the value of `standard-output'
(which see)
is used instead. */)
(Lisp_Object object, Lisp_Object printcharfun)
{
- PRINTDECLARE;
-
if (NILP (printcharfun))
printcharfun = Vstandard_output;
PRINTPREPARE;
@@ -588,32 +575,24 @@ a list, a buffer, a window, a frame, etc.
A printed representation of an object is text which describes that object. */)
(Lisp_Object object, Lisp_Object noescape)
{
- Lisp_Object printcharfun;
- bool prev_abort_on_gc;
- Lisp_Object save_deactivate_mark;
ptrdiff_t count = SPECPDL_INDEX ();
- struct buffer *previous;
specbind (Qinhibit_modification_hooks, Qt);
- {
- PRINTDECLARE;
-
- /* Save and restore this--we are altering a buffer
- but we don't want to deactivate the mark just for that.
- No need for specbind, since errors deactivate the mark. */
- save_deactivate_mark = Vdeactivate_mark;
- prev_abort_on_gc = abort_on_gc;
- abort_on_gc = 1;
-
- printcharfun = Vprin1_to_string_buffer;
- PRINTPREPARE;
- print (object, printcharfun, NILP (noescape));
- /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
- PRINTFINISH;
- }
+ /* Save and restore this: we are altering a buffer
+ but we don't want to deactivate the mark just for that.
+ No need for specbind, since errors deactivate the mark. */
+ Lisp_Object save_deactivate_mark = Vdeactivate_mark;
+ bool prev_abort_on_gc = abort_on_gc;
+ abort_on_gc = true;
- previous = current_buffer;
+ Lisp_Object printcharfun = Vprin1_to_string_buffer;
+ PRINTPREPARE;
+ print (object, printcharfun, NILP (noescape));
+ /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINISH */
+ PRINTFINISH;
+
+ struct buffer *previous = current_buffer;
set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
object = Fbuffer_string ();
if (SBYTES (object) == SCHARS (object))
@@ -655,8 +634,6 @@ If PRINTCHARFUN is omitted, the value of `standard-output'
(which see)
is used instead. */)
(Lisp_Object object, Lisp_Object printcharfun)
{
- PRINTDECLARE;
-
if (NILP (printcharfun))
printcharfun = Vstandard_output;
PRINTPREPARE;
@@ -690,16 +667,15 @@ If PRINTCHARFUN is omitted, the value of
`standard-output' (which see)
is used instead. */)
(Lisp_Object object, Lisp_Object printcharfun)
{
- PRINTDECLARE;
struct gcpro gcpro1;
if (NILP (printcharfun))
printcharfun = Vstandard_output;
GCPRO1 (object);
PRINTPREPARE;
- PRINTCHAR ('\n');
+ printchar ('\n', printcharfun);
print (object, printcharfun, 1);
- PRINTCHAR ('\n');
+ printchar ('\n', printcharfun);
PRINTFINISH;
UNGCPRO;
return object;
@@ -869,7 +845,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream,
const char *context,
struct gcpro gcpro1;
if (context != 0)
- write_string_1 (context, -1, stream);
+ write_string_1 (context, stream);
/* If we know from where the error was signaled, show it in
*Messages*. */
@@ -916,7 +892,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream,
const char *context,
const char *sep = ": ";
if (!STRINGP (errmsg))
- write_string_1 ("peculiar error", -1, stream);
+ write_string_1 ("peculiar error", stream);
else if (SCHARS (errmsg))
Fprinc (errmsg, stream);
else
@@ -927,7 +903,7 @@ print_error_message (Lisp_Object data, Lisp_Object stream,
const char *context,
Lisp_Object obj;
if (sep)
- write_string_1 (sep, 2, stream);
+ write_string_1 (sep, stream);
obj = XCAR (tail);
if (!NILP (file_error)
|| EQ (errname, Qend_of_file) || EQ (errname, Quser_error))
@@ -1420,18 +1396,15 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
obj = print_prune_string_charset (obj);
if (string_intervals (obj))
- {
- PRINTCHAR ('#');
- PRINTCHAR ('(');
- }
+ print_c_string ("#(", printcharfun);
- PRINTCHAR ('\"');
+ printchar ('\"', printcharfun);
size_byte = SBYTES (obj);
for (i = 0, i_byte = 0; i_byte < size_byte;)
{
/* Here, we must convert each multi-byte form to the
- corresponding character code before handing it to PRINTCHAR.
*/
+ corresponding character code before handing it to printchar.
*/
int c;
FETCH_STRING_CHAR_ADVANCE (c, obj, i, i_byte);
@@ -1439,15 +1412,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
QUIT;
if (c == '\n' && print_escape_newlines)
- {
- PRINTCHAR ('\\');
- PRINTCHAR ('n');
- }
+ print_c_string ("\\n", printcharfun);
else if (c == '\f' && print_escape_newlines)
- {
- PRINTCHAR ('\\');
- PRINTCHAR ('f');
- }
+ print_c_string ("\\f", printcharfun);
else if (multibyte
&& (CHAR_BYTE8_P (c)
|| (! ASCII_CHAR_P (c) && print_escape_multibyte)))
@@ -1492,21 +1459,21 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
if ((c >= 'a' && c <= 'f')
|| (c >= 'A' && c <= 'F')
|| (c >= '0' && c <= '9'))
- strout ("\\ ", -1, -1, printcharfun);
+ print_c_string ("\\ ", printcharfun);
}
if (c == '\"' || c == '\\')
- PRINTCHAR ('\\');
- PRINTCHAR (c);
+ printchar ('\\', printcharfun);
+ printchar (c, printcharfun);
}
}
- PRINTCHAR ('\"');
+ printchar ('\"', printcharfun);
if (string_intervals (obj))
{
traverse_intervals (string_intervals (obj),
0, print_interval, printcharfun);
- PRINTCHAR (')');
+ printchar (')', printcharfun);
}
UNGCPRO;
@@ -1550,14 +1517,10 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
size_byte = SBYTES (name);
if (! NILP (Vprint_gensym) && !SYMBOL_INTERNED_P (obj))
- {
- PRINTCHAR ('#');
- PRINTCHAR (':');
- }
+ print_c_string ("#:", printcharfun);
else if (size_byte == 0)
{
- PRINTCHAR ('#');
- PRINTCHAR ('#');
+ print_c_string ("##", printcharfun);
break;
}
@@ -1575,9 +1538,12 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
|| c == ',' || c == '.' || c == '`'
|| c == '[' || c == ']' || c == '?' || c <= 040
|| confusing)
- PRINTCHAR ('\\'), confusing = 0;
+ {
+ printchar ('\\', printcharfun);
+ confusing = false;
+ }
}
- PRINTCHAR (c);
+ printchar (c, printcharfun);
}
}
break;
@@ -1586,18 +1552,17 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
/* If deeper than spec'd depth, print placeholder. */
if (INTEGERP (Vprint_level)
&& print_depth > XINT (Vprint_level))
- strout ("...", -1, -1, printcharfun);
+ print_c_string ("...", printcharfun);
else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
&& (EQ (XCAR (obj), Qquote)))
{
- PRINTCHAR ('\'');
+ printchar ('\'', printcharfun);
print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
}
else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
&& (EQ (XCAR (obj), Qfunction)))
{
- PRINTCHAR ('#');
- PRINTCHAR ('\'');
+ print_c_string ("#'", printcharfun);
print_object (XCAR (XCDR (obj)), printcharfun, escapeflag);
}
else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
@@ -1622,75 +1587,71 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
}
else
{
- PRINTCHAR ('(');
+ printchar ('(', printcharfun);
- {
- printmax_t i, print_length;
- Lisp_Object halftail = obj;
+ Lisp_Object halftail = obj;
- /* Negative values of print-length are invalid in CL.
- Treat them like nil, as CMUCL does. */
- if (NATNUMP (Vprint_length))
- print_length = XFASTINT (Vprint_length);
- else
- print_length = TYPE_MAXIMUM (printmax_t);
+ /* Negative values of print-length are invalid in CL.
+ Treat them like nil, as CMUCL does. */
+ printmax_t print_length = (NATNUMP (Vprint_length)
+ ? XFASTINT (Vprint_length)
+ : TYPE_MAXIMUM (printmax_t));
- i = 0;
- while (CONSP (obj))
- {
- /* Detect circular list. */
- if (NILP (Vprint_circle))
- {
- /* Simple but incomplete way. */
- if (i != 0 && EQ (obj, halftail))
- {
- int len = sprintf (buf, " . #%"pMd, i / 2);
- strout (buf, len, len, printcharfun);
- goto end_of_list;
- }
- }
- else
- {
- /* With the print-circle feature. */
- if (i != 0)
- {
- Lisp_Object num = Fgethash (obj, Vprint_number_table,
Qnil);
- if (INTEGERP (num))
- {
- strout (" . ", 3, 3, printcharfun);
- print_object (obj, printcharfun, escapeflag);
- goto end_of_list;
- }
- }
- }
+ printmax_t i = 0;
+ while (CONSP (obj))
+ {
+ /* Detect circular list. */
+ if (NILP (Vprint_circle))
+ {
+ /* Simple but incomplete way. */
+ if (i != 0 && EQ (obj, halftail))
+ {
+ int len = sprintf (buf, " . #%"pMd, i / 2);
+ strout (buf, len, len, printcharfun);
+ goto end_of_list;
+ }
+ }
+ else
+ {
+ /* With the print-circle feature. */
+ if (i != 0)
+ {
+ Lisp_Object num = Fgethash (obj, Vprint_number_table,
Qnil);
+ if (INTEGERP (num))
+ {
+ print_c_string (" . ", printcharfun);
+ print_object (obj, printcharfun, escapeflag);
+ goto end_of_list;
+ }
+ }
+ }
- if (i)
- PRINTCHAR (' ');
+ if (i)
+ printchar (' ', printcharfun);
- if (print_length <= i)
- {
- strout ("...", 3, 3, printcharfun);
- goto end_of_list;
- }
+ if (print_length <= i)
+ {
+ print_c_string ("...", printcharfun);
+ goto end_of_list;
+ }
- i++;
- print_object (XCAR (obj), printcharfun, escapeflag);
+ i++;
+ print_object (XCAR (obj), printcharfun, escapeflag);
- obj = XCDR (obj);
- if (!(i & 1))
- halftail = XCDR (halftail);
- }
+ obj = XCDR (obj);
+ if (!(i & 1))
+ halftail = XCDR (halftail);
}
/* OBJ non-nil here means it's the end of a dotted list. */
if (!NILP (obj))
{
- strout (" . ", 3, 3, printcharfun);
+ print_c_string (" . ", printcharfun);
print_object (obj, printcharfun, escapeflag);
}
end_of_list:
- PRINTCHAR (')');
+ printchar (')', printcharfun);
}
break;
@@ -1699,9 +1660,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
{
if (escapeflag)
{
- strout ("#<process ", -1, -1, printcharfun);
+ print_c_string ("#<process ", printcharfun);
print_string (XPROCESS (obj)->name, printcharfun);
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
else
print_string (XPROCESS (obj)->name, printcharfun);
@@ -1709,7 +1670,6 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
else if (BOOL_VECTOR_P (obj))
{
ptrdiff_t i;
- int len;
unsigned char c;
struct gcpro gcpro1;
EMACS_INT size = bool_vector_size (obj);
@@ -1717,11 +1677,8 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
ptrdiff_t real_size_in_chars = size_in_chars;
GCPRO1 (obj);
- PRINTCHAR ('#');
- PRINTCHAR ('&');
- len = sprintf (buf, "%"pI"d", size);
+ int len = sprintf (buf, "#&%"pI"d\"", size);
strout (buf, len, len, printcharfun);
- PRINTCHAR ('\"');
/* Don't print more characters than the specified maximum.
Negative values of print-length are invalid. Treat them
@@ -1735,42 +1692,34 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
QUIT;
c = bool_vector_uchar_data (obj)[i];
if (c == '\n' && print_escape_newlines)
- {
- PRINTCHAR ('\\');
- PRINTCHAR ('n');
- }
+ print_c_string ("\\n", printcharfun);
else if (c == '\f' && print_escape_newlines)
- {
- PRINTCHAR ('\\');
- PRINTCHAR ('f');
- }
+ print_c_string ("\\f", printcharfun);
else if (c > '\177')
{
/* Use octal escapes to avoid encoding issues. */
- PRINTCHAR ('\\');
- PRINTCHAR ('0' + ((c >> 6) & 3));
- PRINTCHAR ('0' + ((c >> 3) & 7));
- PRINTCHAR ('0' + (c & 7));
+ len = sprintf (buf, "\\%o", c);
+ strout (buf, len, len, printcharfun);
}
else
{
if (c == '\"' || c == '\\')
- PRINTCHAR ('\\');
- PRINTCHAR (c);
+ printchar ('\\', printcharfun);
+ printchar (c, printcharfun);
}
}
if (size_in_chars < real_size_in_chars)
- strout (" ...", 4, 4, printcharfun);
- PRINTCHAR ('\"');
+ print_c_string (" ...", printcharfun);
+ printchar ('\"', printcharfun);
UNGCPRO;
}
else if (SUBRP (obj))
{
- strout ("#<subr ", -1, -1, printcharfun);
- strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun);
- PRINTCHAR ('>');
+ print_c_string ("#<subr ", printcharfun);
+ print_c_string (XSUBR (obj)->symbol_name, printcharfun);
+ printchar ('>', printcharfun);
}
else if (WINDOWP (obj))
{
@@ -1779,25 +1728,23 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
strout (buf, len, len, printcharfun);
if (BUFFERP (XWINDOW (obj)->contents))
{
- strout (" on ", -1, -1, printcharfun);
+ print_c_string (" on ", printcharfun);
print_string (BVAR (XBUFFER (XWINDOW (obj)->contents), name),
printcharfun);
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
else if (TERMINALP (obj))
{
- int len;
struct terminal *t = XTERMINAL (obj);
- strout ("#<terminal ", -1, -1, printcharfun);
- len = sprintf (buf, "%d", t->id);
+ int len = sprintf (buf, "#<terminal %d", t->id);
strout (buf, len, len, printcharfun);
if (t->name)
{
- strout (" on ", -1, -1, printcharfun);
- strout (t->name, -1, -1, printcharfun);
+ print_c_string (" on ", printcharfun);
+ print_c_string (t->name, printcharfun);
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
else if (HASH_TABLE_P (obj))
{
@@ -1807,16 +1754,14 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
int len;
#if 0
void *ptr = h;
- strout ("#<hash-table", -1, -1, printcharfun);
+ print_c_string ("#<hash-table", printcharfun);
if (SYMBOLP (h->test))
{
- PRINTCHAR (' ');
- PRINTCHAR ('\'');
- strout (SDATA (SYMBOL_NAME (h->test)), -1, -1, printcharfun);
- PRINTCHAR (' ');
- strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
- PRINTCHAR (' ');
- len = sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
+ print_c_string (" '", printcharfun);
+ print_c_string (SSDATA (SYMBOL_NAME (h->test)), printcharfun);
+ printchar (' ', printcharfun);
+ print_c_string (SSDATA (SYMBOL_NAME (h->weak)), printcharfun);
+ len = sprintf (buf, " %"pD"d/%"pD"d", h->count, ASIZE (h->next));
strout (buf, len, len, printcharfun);
}
len = sprintf (buf, " %p>", ptr);
@@ -1830,29 +1775,29 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
if (!NILP (h->test.name))
{
- strout (" test ", -1, -1, printcharfun);
+ print_c_string (" test ", printcharfun);
print_object (h->test.name, printcharfun, escapeflag);
}
if (!NILP (h->weak))
{
- strout (" weakness ", -1, -1, printcharfun);
+ print_c_string (" weakness ", printcharfun);
print_object (h->weak, printcharfun, escapeflag);
}
if (!NILP (h->rehash_size))
{
- strout (" rehash-size ", -1, -1, printcharfun);
+ print_c_string (" rehash-size ", printcharfun);
print_object (h->rehash_size, printcharfun, escapeflag);
}
if (!NILP (h->rehash_threshold))
{
- strout (" rehash-threshold ", -1, -1, printcharfun);
+ print_c_string (" rehash-threshold ", printcharfun);
print_object (h->rehash_threshold, printcharfun, escapeflag);
}
- strout (" data ", -1, -1, printcharfun);
+ print_c_string (" data ", printcharfun);
/* Print the data here as a plist. */
real_size = HASH_TABLE_SIZE (h);
@@ -1863,49 +1808,47 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
&& XFASTINT (Vprint_length) < size)
size = XFASTINT (Vprint_length);
- PRINTCHAR ('(');
+ printchar ('(', printcharfun);
for (i = 0; i < size; i++)
if (!NILP (HASH_HASH (h, i)))
{
- if (i) PRINTCHAR (' ');
+ if (i) printchar (' ', printcharfun);
print_object (HASH_KEY (h, i), printcharfun, escapeflag);
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
print_object (HASH_VALUE (h, i), printcharfun, escapeflag);
}
if (size < real_size)
- strout (" ...", 4, 4, printcharfun);
+ print_c_string (" ...", printcharfun);
- PRINTCHAR (')');
- PRINTCHAR (')');
+ print_c_string ("))", printcharfun);
}
else if (BUFFERP (obj))
{
if (!BUFFER_LIVE_P (XBUFFER (obj)))
- strout ("#<killed buffer>", -1, -1, printcharfun);
+ print_c_string ("#<killed buffer>", printcharfun);
else if (escapeflag)
{
- strout ("#<buffer ", -1, -1, printcharfun);
+ print_c_string ("#<buffer ", printcharfun);
print_string (BVAR (XBUFFER (obj), name), printcharfun);
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
else
print_string (BVAR (XBUFFER (obj), name), printcharfun);
}
else if (WINDOW_CONFIGURATIONP (obj))
- {
- strout ("#<window-configuration>", -1, -1, printcharfun);
- }
+ print_c_string ("#<window-configuration>", printcharfun);
else if (FRAMEP (obj))
{
int len;
void *ptr = XFRAME (obj);
Lisp_Object frame_name = XFRAME (obj)->name;
- strout ((FRAME_LIVE_P (XFRAME (obj))
- ? "#<frame " : "#<dead frame "),
- -1, -1, printcharfun);
+ print_c_string ((FRAME_LIVE_P (XFRAME (obj))
+ ? "#<frame "
+ : "#<dead frame "),
+ printcharfun);
if (!STRINGP (frame_name))
{
/* A frame could be too young and have no name yet;
@@ -1926,12 +1869,12 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
if (! FONT_OBJECT_P (obj))
{
if (FONT_SPEC_P (obj))
- strout ("#<font-spec", -1, -1, printcharfun);
+ print_c_string ("#<font-spec", printcharfun);
else
- strout ("#<font-entity", -1, -1, printcharfun);
+ print_c_string ("#<font-entity", printcharfun);
for (i = 0; i < FONT_SPEC_MAX; i++)
{
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
if (i < FONT_WEIGHT_INDEX || i > FONT_WIDTH_INDEX)
print_object (AREF (obj, i), printcharfun, escapeflag);
else
@@ -1941,18 +1884,18 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
}
else
{
- strout ("#<font-object ", -1, -1, printcharfun);
+ print_c_string ("#<font-object ", printcharfun);
print_object (AREF (obj, FONT_NAME_INDEX), printcharfun,
escapeflag);
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
else
{
ptrdiff_t size = ASIZE (obj);
if (COMPILEDP (obj))
{
- PRINTCHAR ('#');
+ printchar ('#', printcharfun);
size &= PSEUDOVECTOR_SIZE_MASK;
}
if (CHAR_TABLE_P (obj) || SUB_CHAR_TABLE_P (obj))
@@ -1966,20 +1909,19 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
results in slow redisplay. */
if (SUB_CHAR_TABLE_P (obj)
&& XSUB_CHAR_TABLE (obj)->depth == 3)
- PRINTCHAR ('\n');
- PRINTCHAR ('#');
- PRINTCHAR ('^');
+ printchar ('\n', printcharfun);
+ print_c_string ("#^", printcharfun);
if (SUB_CHAR_TABLE_P (obj))
- PRINTCHAR ('^');
+ printchar ('^', printcharfun);
size &= PSEUDOVECTOR_SIZE_MASK;
}
if (size & PSEUDOVECTOR_FLAG)
goto badtype;
- PRINTCHAR ('[');
+ printchar ('[', printcharfun);
{
int i, idx = SUB_CHAR_TABLE_P (obj) ? SUB_CHAR_TABLE_OFFSET : 0;
- register Lisp_Object tem;
+ Lisp_Object tem;
ptrdiff_t real_size = size;
/* For a sub char-table, print heading non-Lisp data first. */
@@ -1997,14 +1939,14 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
for (i = idx; i < size; i++)
{
- if (i) PRINTCHAR (' ');
+ if (i) printchar (' ', printcharfun);
tem = AREF (obj, i);
print_object (tem, printcharfun, escapeflag);
}
if (size < real_size)
- strout (" ...", 4, 4, printcharfun);
+ print_c_string (" ...", printcharfun);
}
- PRINTCHAR (']');
+ printchar (']', printcharfun);
}
break;
@@ -2012,26 +1954,25 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
switch (XMISCTYPE (obj))
{
case Lisp_Misc_Marker:
- strout ("#<marker ", -1, -1, printcharfun);
+ print_c_string ("#<marker ", printcharfun);
/* Do you think this is necessary? */
if (XMARKER (obj)->insertion_type != 0)
- strout ("(moves after insertion) ", -1, -1, printcharfun);
+ print_c_string ("(moves after insertion) ", printcharfun);
if (! XMARKER (obj)->buffer)
- strout ("in no buffer", -1, -1, printcharfun);
+ print_c_string ("in no buffer", printcharfun);
else
{
- int len = sprintf (buf, "at %"pD"d", marker_position (obj));
+ int len = sprintf (buf, "at %"pD"d in ", marker_position (obj));
strout (buf, len, len, printcharfun);
- strout (" in ", -1, -1, printcharfun);
print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
break;
case Lisp_Misc_Overlay:
- strout ("#<overlay ", -1, -1, printcharfun);
+ print_c_string ("#<overlay ", printcharfun);
if (! XMARKER (OVERLAY_START (obj))->buffer)
- strout ("in no buffer", -1, -1, printcharfun);
+ print_c_string ("in no buffer", printcharfun);
else
{
int len = sprintf (buf, "from %"pD"d to %"pD"d in ",
@@ -2041,21 +1982,21 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
printcharfun);
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
break;
case Lisp_Misc_Finalizer:
- strout ("#<finalizer", -1, -1, printcharfun);
+ print_c_string ("#<finalizer", printcharfun);
if (NILP (XFINALIZER (obj)->function))
- strout (" used", -1, -1, printcharfun);
- strout (">", -1, -1, printcharfun);
+ print_c_string (" used", printcharfun);
+ printchar ('>', printcharfun);
break;
/* Remaining cases shouldn't happen in normal usage, but let's
print them anyway for the benefit of the debugger. */
case Lisp_Misc_Free:
- strout ("#<misc free cell>", -1, -1, printcharfun);
+ print_c_string ("#<misc free cell>", printcharfun);
break;
case Lisp_Misc_Save_Value:
@@ -2063,7 +2004,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
int i;
struct Lisp_Save_Value *v = XSAVE_VALUE (obj);
- strout ("#<save-value ", -1, -1, printcharfun);
+ print_c_string ("#<save-value ", printcharfun);
if (v->save_type == SAVE_TYPE_MEMORY)
{
@@ -2086,17 +2027,15 @@ print_object (Lisp_Object obj, Lisp_Object
printcharfun, bool escapeflag)
Lisp_Object maybe = area[i];
int valid = valid_lisp_object_p (maybe);
+ printchar (' ', printcharfun);
if (0 < valid)
- {
- PRINTCHAR (' ');
- print_object (maybe, printcharfun, escapeflag);
- }
+ print_object (maybe, printcharfun, escapeflag);
else
- strout (valid ? " <some>" : " <invalid>",
- -1, -1, printcharfun);
+ print_c_string (valid < 0 ? "<some>" : "<invalid>",
+ printcharfun);
}
if (i == limit && i < amount)
- strout (" ...", 4, 4, printcharfun);
+ print_c_string (" ...", printcharfun);
#else /* not GC_MARK_STACK */
@@ -2115,7 +2054,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
for (index = 0; index < SAVE_VALUE_SLOTS; index++)
{
if (index)
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
switch (save_type (v, index))
{
@@ -2151,7 +2090,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
strout (buf, i, i, printcharfun);
}
}
- PRINTCHAR ('>');
+ printchar ('>', printcharfun);
}
break;
@@ -2166,7 +2105,7 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
int len;
/* We're in trouble if this happens!
Probably should just emacs_abort (). */
- strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun);
+ print_c_string ("#<EMACS BUG: INVALID DATATYPE ", printcharfun);
if (MISCP (obj))
len = sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
else if (VECTORLIKEP (obj))
@@ -2174,8 +2113,9 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun,
bool escapeflag)
else
len = sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
strout (buf, len, len, printcharfun);
- strout (" Save your buffers immediately and please report this bug>",
- -1, -1, printcharfun);
+ print_c_string ((" Save your buffers immediately"
+ " and please report this bug>"),
+ printcharfun);
}
}
@@ -2191,12 +2131,12 @@ print_interval (INTERVAL interval, Lisp_Object
printcharfun)
{
if (NILP (interval->plist))
return;
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
print_object (make_number (interval->position), printcharfun, 1);
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
print_object (make_number (interval->position + LENGTH (interval)),
printcharfun, 1);
- PRINTCHAR (' ');
+ printchar (' ', printcharfun);
print_object (interval->plist, printcharfun, 1);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 96bfe81: Refactor low-level printing for simplicity,
Paul Eggert <=