#include <config.h>
#include <stdio.h>
-#include <setjmp.h>
+
#include "lisp.h"
#include "character.h"
#include "buffer.h"
static Lisp_Object Qfloat_output_format;
-#include <math.h>
#include <float.h>
#include <ftoastr.h>
-/* Default to values appropriate for IEEE floating point. */
-#ifndef DBL_DIG
-#define DBL_DIG 15
-#endif
-
/* Avoid actual stack overflow in print. */
static ptrdiff_t print_depth;
else \
{ \
int new_size = 1000; \
- print_buffer = (char *) xmalloc (new_size); \
+ print_buffer = xmalloc (new_size); \
print_buffer_size = new_size; \
free_print_buffer = 1; \
} \
if (print_buffer_pos != print_buffer_pos_byte \
&& NILP (BVAR (current_buffer, enable_multibyte_characters))) \
{ \
- unsigned char *temp \
- = (unsigned char *) alloca (print_buffer_pos + 1); \
+ unsigned char *temp = alloca (print_buffer_pos + 1); \
copy_text ((unsigned char *) print_buffer, temp, \
print_buffer_pos_byte, 1, 0); \
insert_1_both ((char *) temp, print_buffer_pos, \
? PT - start_point : 0), \
old_point_byte + (old_point_byte >= start_point_byte \
? PT_BYTE - start_point_byte : 0)); \
- if (old != current_buffer) \
- set_buffer_internal (old);
+ set_buffer_internal (old);
#define PRINTCHAR(ch) printchar (ch, printcharfun)
{
/* Output to echo area. */
ptrdiff_t nbytes = SBYTES (string);
- char *buffer;
/* Copy the string contents so that relocation of STRING by
GC does not cause trouble. */
USE_SAFE_ALLOCA;
-
- SAFE_ALLOCA (buffer, char *, nbytes);
+ char *buffer = SAFE_ALLOCA (nbytes);
memcpy (buffer, SDATA (string), nbytes);
- strout (buffer, chars, SBYTES (string), printcharfun);
+ strout (buffer, chars, nbytes, printcharfun);
SAFE_FREE ();
}
register struct buffer *old = current_buffer;
register Lisp_Object buf;
- record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
+ record_unwind_current_buffer ();
Fset_buffer (Fget_buffer_create (build_string (bufname)));
Fkill_all_local_variables ();
delete_all_overlays (current_buffer);
- BVAR (current_buffer, directory) = BVAR (old, directory);
- BVAR (current_buffer, read_only) = Qnil;
- BVAR (current_buffer, filename) = Qnil;
- BVAR (current_buffer, undo_list) = Qt;
+ bset_directory (current_buffer, BVAR (old, directory));
+ bset_read_only (current_buffer, Qnil);
+ bset_filename (current_buffer, Qnil);
+ bset_undo_list (current_buffer, Qt);
eassert (current_buffer->overlays_before == NULL);
eassert (current_buffer->overlays_after == NULL);
- BVAR (current_buffer, enable_multibyte_characters)
- = BVAR (&buffer_defaults, enable_multibyte_characters);
+ bset_enable_multibyte_characters
+ (current_buffer, BVAR (&buffer_defaults, enable_multibyte_characters));
specbind (Qinhibit_read_only, Qt);
specbind (Qinhibit_modification_hooks, Qt);
Ferase_buffer ();
(Lisp_Object object, Lisp_Object noescape)
{
Lisp_Object printcharfun;
+ bool prev_abort_on_gc;
/* struct gcpro gcpro1, gcpro2; */
Lisp_Object save_deactivate_mark;
ptrdiff_t count = SPECPDL_INDEX ();
No need for specbind, since errors deactivate the mark. */
save_deactivate_mark = Vdeactivate_mark;
/* GCPRO2 (object, save_deactivate_mark); */
- abort_on_gc++;
+ prev_abort_on_gc = abort_on_gc;
+ abort_on_gc = 1;
printcharfun = Vprin1_to_string_buffer;
PRINTPREPARE;
Vdeactivate_mark = save_deactivate_mark;
/* UNGCPRO; */
- abort_on_gc--;
+ abort_on_gc = prev_abort_on_gc;
return unbind_to (count, object);
}
{
if (initial_stderr_stream != NULL)
{
- BLOCK_INPUT;
+ block_input ();
fclose (stderr);
- UNBLOCK_INPUT;
+ unblock_input ();
}
stderr = initial_stderr_stream;
initial_stderr_stream = NULL;
else
fprintf (stderr, "#<%s_LISP_OBJECT 0x%08"pI"x>\r\n",
!valid ? "INVALID" : "SOME",
- XHASH (arg));
+ XLI (arg));
}
\f
if (!NILP (caller) && SYMBOLP (caller))
{
Lisp_Object cname = SYMBOL_NAME (caller);
- char *name;
+ ptrdiff_t cnamelen = SBYTES (cname);
USE_SAFE_ALLOCA;
- SAFE_ALLOCA (name, char *, SBYTES (cname));
- memcpy (name, SDATA (cname), SBYTES (cname));
- message_dolog (name, SBYTES (cname), 0, 0);
+ char *name = SAFE_ALLOCA (cnamelen);
+ memcpy (name, SDATA (cname), cnamelen);
+ message_dolog (name, cnamelen, 0, 0);
message_dolog (": ", 2, 0, 0);
SAFE_FREE ();
}
for (; CONSP (tail); tail = XCDR (tail), sep = ", ")
{
Lisp_Object obj;
-
+
if (sep)
write_string_1 (sep, 2, stream);
obj = XCAR (tail);
* Given the above, the buffer must be least FLOAT_TO_STRING_BUFSIZE bytes.
*/
-void
+int
float_to_string (char *buf, double data)
{
char *cp;
int width;
+ int len;
/* Check for plus infinity in a way that won't lose
if there is no plus infinity. */
if (data == data / 2 && data > 1.0)
{
- strcpy (buf, "1.0e+INF");
- return;
+ static char const infinity_string[] = "1.0e+INF";
+ strcpy (buf, infinity_string);
+ return sizeof infinity_string - 1;
}
/* Likewise for minus infinity. */
if (data == data / 2 && data < -1.0)
{
- strcpy (buf, "-1.0e+INF");
- return;
+ static char const minus_infinity_string[] = "-1.0e+INF";
+ strcpy (buf, minus_infinity_string);
+ return sizeof minus_infinity_string - 1;
}
/* Check for NaN in a way that won't fail if there are no NaNs. */
if (! (data * 0.0 >= 0.0))
{
/* Prepend "-" if the NaN's sign bit is negative.
The sign bit of a double is the bit that is 1 in -0.0. */
+ static char const NaN_string[] = "0.0e+NaN";
int i;
union { double d; char c[sizeof (double)]; } u_data, u_minus_zero;
+ int negative = 0;
u_data.d = data;
u_minus_zero.d = - 0.0;
for (i = 0; i < sizeof (double); i++)
if (u_data.c[i] & u_minus_zero.c[i])
{
- *buf++ = '-';
+ *buf = '-';
+ negative = 1;
break;
}
- strcpy (buf, "0.0e+NaN");
- return;
+ strcpy (buf + negative, NaN_string);
+ return negative + sizeof NaN_string - 1;
}
if (NILP (Vfloat_output_format)
{
/* Generate the fewest number of digits that represent the
floating point value without losing information. */
- dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data);
+ len = dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data);
/* The decimal point must be printed, or the byte compiler can
get confused (Bug#8033). */
width = 1;
if (cp[1] != 0)
goto lose;
- sprintf (buf, SSDATA (Vfloat_output_format), data);
+ len = sprintf (buf, SSDATA (Vfloat_output_format), data);
}
/* Make sure there is a decimal point with digit after, or an
{
cp[1] = '0';
cp[2] = 0;
+ len++;
}
else if (*cp == 0)
{
*cp++ = '.';
*cp++ = '0';
*cp++ = 0;
+ len += 2;
}
}
+
+ return len;
}
\f
{
case Lisp_String:
/* A string may have text properties, which can be circular. */
- traverse_intervals_noorder (STRING_INTERVALS (obj),
+ traverse_intervals_noorder (string_intervals (obj),
print_preprocess_string, Qnil);
break;
print_prune_string_charset (Lisp_Object string)
{
print_check_string_result = 0;
- traverse_intervals (STRING_INTERVALS (string), 0,
+ traverse_intervals (string_intervals (string), 0,
print_check_string_charset_prop, string);
if (! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
{
for (i = 0; i < print_depth; i++)
if (EQ (obj, being_printed[i]))
{
- sprintf (buf, "#%d", i);
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, "#%d", i);
+ strout (buf, len, len, printcharfun);
return;
}
being_printed[print_depth] = obj;
if (n < 0)
{ /* Add a prefix #n= if OBJ has not yet been printed;
that is, its status field is nil. */
- sprintf (buf, "#%"pI"d=", -n);
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, "#%"pI"d=", -n);
+ strout (buf, len, len, printcharfun);
/* OBJ is going to be printed. Remember that fact. */
Fputhash (obj, make_number (- n), Vprint_number_table);
}
else
{
/* Just print #n# if OBJ has already been printed. */
- sprintf (buf, "#%"pI"d#", n);
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, "#%"pI"d#", n);
+ strout (buf, len, len, printcharfun);
return;
}
}
switch (XTYPE (obj))
{
case_Lisp_Int:
- sprintf (buf, "%"pI"d", XINT (obj));
- strout (buf, -1, -1, printcharfun);
+ {
+ int len = sprintf (buf, "%"pI"d", XINT (obj));
+ strout (buf, len, len, printcharfun);
+ }
break;
case Lisp_Float:
{
char pigbuf[FLOAT_TO_STRING_BUFSIZE];
-
- float_to_string (pigbuf, XFLOAT_DATA (obj));
- strout (pigbuf, -1, -1, printcharfun);
+ int len = float_to_string (pigbuf, XFLOAT_DATA (obj));
+ strout (pigbuf, len, len, printcharfun);
}
break;
if (! EQ (Vprint_charset_text_property, Qt))
obj = print_prune_string_charset (obj);
- if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
+ if (string_intervals (obj))
{
PRINTCHAR ('#');
PRINTCHAR ('(');
when found in a multibyte string, always use a hex escape
so it reads back as multibyte. */
char outbuf[50];
+ int len;
if (CHAR_BYTE8_P (c))
- sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c));
+ len = sprintf (outbuf, "\\%03o", CHAR_TO_BYTE8 (c));
else
{
- sprintf (outbuf, "\\x%04x", c);
+ len = sprintf (outbuf, "\\x%04x", c);
need_nonhex = 1;
}
- strout (outbuf, -1, -1, printcharfun);
+ strout (outbuf, len, len, printcharfun);
}
else if (! multibyte
&& SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
print single-byte non-ASCII string chars
using octal escapes. */
char outbuf[5];
- sprintf (outbuf, "\\%03o", c);
- strout (outbuf, -1, -1, printcharfun);
+ int len = sprintf (outbuf, "\\%03o", c);
+ strout (outbuf, len, len, printcharfun);
}
else
{
}
PRINTCHAR ('\"');
- if (!NULL_INTERVAL_P (STRING_INTERVALS (obj)))
+ if (string_intervals (obj))
{
- traverse_intervals (STRING_INTERVALS (obj),
+ traverse_intervals (string_intervals (obj),
0, print_interval, printcharfun);
PRINTCHAR (')');
}
/* Simple but incomplete way. */
if (i != 0 && EQ (obj, halftail))
{
- sprintf (buf, " . #%"pMd, i / 2);
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, " . #%"pMd, i / 2);
+ strout (buf, len, len, printcharfun);
goto end_of_list;
}
}
else if (BOOL_VECTOR_P (obj))
{
ptrdiff_t i;
- register unsigned char c;
+ int len;
+ unsigned char c;
struct gcpro gcpro1;
ptrdiff_t size_in_chars
= ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
PRINTCHAR ('#');
PRINTCHAR ('&');
- sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size);
- strout (buf, -1, -1, printcharfun);
+ len = sprintf (buf, "%"pI"d", XBOOL_VECTOR (obj)->size);
+ strout (buf, len, len, printcharfun);
PRINTCHAR ('\"');
/* Don't print more characters than the specified maximum.
}
else if (WINDOWP (obj))
{
+ int len;
strout ("#<window ", -1, -1, printcharfun);
- sprintf (buf, "%"pI"d", XFASTINT (XWINDOW (obj)->sequence_number));
- strout (buf, -1, -1, printcharfun);
+ len = sprintf (buf, "%d", XWINDOW (obj)->sequence_number);
+ strout (buf, len, len, printcharfun);
if (!NILP (XWINDOW (obj)->buffer))
{
strout (" on ", -1, -1, printcharfun);
- print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name), printcharfun);
+ print_string (BVAR (XBUFFER (XWINDOW (obj)->buffer), name),
+ printcharfun);
}
PRINTCHAR ('>');
}
else if (TERMINALP (obj))
{
+ int len;
struct terminal *t = XTERMINAL (obj);
strout ("#<terminal ", -1, -1, printcharfun);
- sprintf (buf, "%d", t->id);
- strout (buf, -1, -1, printcharfun);
+ len = sprintf (buf, "%d", t->id);
+ strout (buf, len, len, printcharfun);
if (t->name)
{
strout (" on ", -1, -1, printcharfun);
struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
ptrdiff_t i;
ptrdiff_t real_size, size;
+ int len;
#if 0
strout ("#<hash-table", -1, -1, printcharfun);
if (SYMBOLP (h->test))
PRINTCHAR (' ');
strout (SDATA (SYMBOL_NAME (h->weak)), -1, -1, printcharfun);
PRINTCHAR (' ');
- sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
- strout (buf, -1, -1, printcharfun);
+ len = sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
+ strout (buf, len, len, printcharfun);
}
- sprintf (buf, " %p", h);
- strout (buf, -1, -1, printcharfun);
+ len = sprintf (buf, " %p", h);
+ strout (buf, len, len, printcharfun);
PRINTCHAR ('>');
#endif
/* Implement a readable output, e.g.:
#s(hash-table size 2 test equal data (k1 v1 k2 v2)) */
- /* Always print the size. */
- sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next));
- strout (buf, -1, -1, printcharfun);
+ /* Always print the size. */
+ len = sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next));
+ strout (buf, len, len, printcharfun);
- if (!NILP (h->test))
+ if (!NILP (h->test.name))
{
strout (" test ", -1, -1, printcharfun);
- print_object (h->test, printcharfun, escapeflag);
+ print_object (h->test.name, printcharfun, escapeflag);
}
if (!NILP (h->weak))
}
else if (BUFFERP (obj))
{
- if (NILP (BVAR (XBUFFER (obj), name)))
+ if (!BUFFER_LIVE_P (XBUFFER (obj)))
strout ("#<killed buffer>", -1, -1, printcharfun);
else if (escapeflag)
{
}
else if (FRAMEP (obj))
{
+ int len;
+ Lisp_Object frame_name = XFRAME (obj)->name;
+
strout ((FRAME_LIVE_P (XFRAME (obj))
? "#<frame " : "#<dead frame "),
-1, -1, printcharfun);
- print_string (XFRAME (obj)->name, printcharfun);
- sprintf (buf, " %p", XFRAME (obj));
- strout (buf, -1, -1, printcharfun);
+ if (!STRINGP (frame_name))
+ {
+ /* A frame could be too young and have no name yet;
+ don't crash. */
+ if (SYMBOLP (frame_name))
+ frame_name = Fsymbol_name (frame_name);
+ else /* can't happen: name should be either nil or string */
+ frame_name = build_string ("*INVALID*FRAME*NAME*");
+ }
+ print_string (frame_name, printcharfun);
+ len = sprintf (buf, " %p", XFRAME (obj));
+ strout (buf, len, len, printcharfun);
PRINTCHAR ('>');
}
else if (FONTP (obj))
strout ("in no buffer", -1, -1, printcharfun);
else
{
- sprintf (buf, "at %"pD"d", marker_position (obj));
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, "at %"pD"d", marker_position (obj));
+ strout (buf, len, len, printcharfun);
strout (" in ", -1, -1, printcharfun);
print_string (BVAR (XMARKER (obj)->buffer, name), printcharfun);
}
strout ("in no buffer", -1, -1, printcharfun);
else
{
- sprintf (buf, "from %"pD"d to %"pD"d in ",
- marker_position (OVERLAY_START (obj)),
- marker_position (OVERLAY_END (obj)));
- strout (buf, -1, -1, printcharfun);
+ int len = sprintf (buf, "from %"pD"d to %"pD"d in ",
+ marker_position (OVERLAY_START (obj)),
+ marker_position (OVERLAY_END (obj)));
+ strout (buf, len, len, printcharfun);
print_string (BVAR (XMARKER (OVERLAY_START (obj))->buffer, name),
printcharfun);
}
case Lisp_Misc_Save_Value:
strout ("#<save_value ", -1, -1, printcharfun);
- sprintf (buf, "ptr=%p int=%"pD"d",
- XSAVE_VALUE (obj)->pointer,
- XSAVE_VALUE (obj)->integer);
- strout (buf, -1, -1, printcharfun);
+ {
+ int len = sprintf (buf, "ptr=%p int=%"pD"d",
+ XSAVE_VALUE (obj)->pointer,
+ XSAVE_VALUE (obj)->integer);
+ strout (buf, len, len, printcharfun);
+ }
PRINTCHAR ('>');
break;
default:
badtype:
{
+ int len;
/* We're in trouble if this happens!
- Probably should just abort () */
+ Probably should just emacs_abort (). */
strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun);
if (MISCP (obj))
- sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
+ len = sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
else if (VECTORLIKEP (obj))
- sprintf (buf, "(PVEC 0x%08"pD"x)", ASIZE (obj));
+ len = sprintf (buf, "(PVEC 0x%08"pD"x)", ASIZE (obj));
else
- sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
- strout (buf, -1, -1, printcharfun);
+ 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 a description of INTERVAL using PRINTCHARFUN.
This is part of printing a string that has text properties. */
-void
+static void
print_interval (INTERVAL interval, Lisp_Object printcharfun)
{
if (NILP (interval->plist))