#include <stdio.h>
#include <setjmp.h>
#include "lisp.h"
-#include "buffer.h"
#include "character.h"
+#include "buffer.h"
#include "charset.h"
#include "keyboard.h"
#include "frame.h"
#endif
/* Avoid actual stack overflow in print. */
-static int print_depth;
+static ptrdiff_t print_depth;
/* Level of nesting inside outputting backquote in new style. */
-static int new_backquote_output;
+static ptrdiff_t new_backquote_output;
/* Detect most circularities to print finite output. */
#define PRINT_CIRCLE 200
static char *print_buffer;
/* Size allocated in print_buffer. */
-static EMACS_INT print_buffer_size;
+static ptrdiff_t print_buffer_size;
/* Chars stored in print_buffer. */
-static EMACS_INT print_buffer_pos;
+static ptrdiff_t print_buffer_pos;
/* Bytes stored in print_buffer. */
-static EMACS_INT print_buffer_pos_byte;
+static ptrdiff_t print_buffer_pos_byte;
Lisp_Object Qprint_escape_newlines;
static Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
N the object has been printed so we can refer to it as #N#.
print_number_index holds the largest N already used.
N has to be striclty larger than 0 since we need to distinguish -N. */
-static int print_number_index;
+static ptrdiff_t print_number_index;
static void print_interval (INTERVAL interval, Lisp_Object printcharfun);
/* GDB resets this to zero on W32 to disable OutputDebugString calls. */
#define PRINTDECLARE \
struct buffer *old = current_buffer; \
- EMACS_INT old_point = -1, start_point = -1; \
- EMACS_INT old_point_byte = -1, start_point_byte = -1; \
- int specpdl_count = SPECPDL_INDEX (); \
+ ptrdiff_t old_point = -1, start_point = -1; \
+ ptrdiff_t old_point_byte = -1, start_point_byte = -1; \
+ ptrdiff_t specpdl_count = SPECPDL_INDEX (); \
int free_print_buffer = 0; \
int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); \
Lisp_Object original
} \
if (MARKERP (printcharfun)) \
{ \
- EMACS_INT marker_pos; \
+ ptrdiff_t marker_pos; \
if (! XMARKER (printcharfun)->buffer) \
error ("Marker does not point anywhere"); \
if (XMARKER (printcharfun)->buffer != current_buffer) \
} \
else \
{ \
- ptrdiff_t new_size = 1000; \
+ int new_size = 1000; \
print_buffer = (char *) xmalloc (new_size); \
print_buffer_size = new_size; \
free_print_buffer = 1; \
if (NILP (fun))
{
- if (print_buffer_size - len <= print_buffer_pos_byte)
- {
- ptrdiff_t new_size;
- if (STRING_BYTES_BOUND / 2 < print_buffer_size)
- string_overflow ();
- new_size = print_buffer_size * 2;
- print_buffer = (char *) xrealloc (print_buffer, new_size);
- print_buffer_size = new_size;
- }
+ ptrdiff_t incr = len - (print_buffer_size - print_buffer_pos_byte);
+ if (0 < incr)
+ print_buffer =
+ xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
memcpy (print_buffer + print_buffer_pos_byte, str, len);
print_buffer_pos += 1;
print_buffer_pos_byte += len;
to data in a Lisp string. Otherwise that is not safe. */
static void
-strout (const char *ptr, EMACS_INT size, EMACS_INT size_byte,
+strout (const char *ptr, ptrdiff_t size, ptrdiff_t size_byte,
Lisp_Object printcharfun)
{
if (size < 0)
if (NILP (printcharfun))
{
- if (print_buffer_size - size_byte < print_buffer_pos_byte)
- {
- ptrdiff_t new_size;
- if (STRING_BYTES_BOUND / 2 - size_byte < print_buffer_size)
- string_overflow ();
- new_size = print_buffer_size * 2 + size_byte;
- print_buffer = (char *) xrealloc (print_buffer, new_size);
- print_buffer_size = new_size;
- }
+ ptrdiff_t incr = size_byte - (print_buffer_size - print_buffer_pos_byte);
+ if (0 < incr)
+ print_buffer = xpalloc (print_buffer, &print_buffer_size, incr, -1, 1);
memcpy (print_buffer + print_buffer_pos_byte, ptr, size_byte);
print_buffer_pos += size;
print_buffer_pos_byte += size_byte;
else
{
/* PRINTCHARFUN is a Lisp function. */
- EMACS_INT i = 0;
+ ptrdiff_t i = 0;
if (size == size_byte)
{
{
if (EQ (printcharfun, Qt) || NILP (printcharfun))
{
- EMACS_INT chars;
+ ptrdiff_t chars;
if (print_escape_nonascii)
string = string_escape_byte8 (string);
convert STRING to a multibyte string containing the same
character codes. */
Lisp_Object newstr;
- EMACS_INT bytes;
+ ptrdiff_t bytes;
chars = SBYTES (string);
bytes = count_size_as_multibyte (SDATA (string), chars);
if (EQ (printcharfun, Qt))
{
/* Output to echo area. */
- EMACS_INT nbytes = SBYTES (string);
+ ptrdiff_t nbytes = SBYTES (string);
char *buffer;
/* Copy the string contents so that relocation of STRING by
{
/* Otherwise, string may be relocated by printing one char.
So re-fetch the string address for each character. */
- EMACS_INT i;
- EMACS_INT size = SCHARS (string);
- EMACS_INT size_byte = SBYTES (string);
+ ptrdiff_t i;
+ ptrdiff_t size = SCHARS (string);
+ ptrdiff_t size_byte = SBYTES (string);
struct gcpro gcpro1;
GCPRO1 (string);
if (size == size_byte)
void
temp_output_buffer_setup (const char *bufname)
{
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
register struct buffer *old = current_buffer;
register Lisp_Object buf;
Lisp_Object printcharfun;
/* struct gcpro gcpro1, gcpro2; */
Lisp_Object save_deactivate_mark;
- int count = SPECPDL_INDEX ();
+ ptrdiff_t count = SPECPDL_INDEX ();
struct buffer *previous;
specbind (Qinhibit_modification_hooks, Qt);
(Lisp_Object character)
{
CHECK_NUMBER (character);
- putc ((int) XINT (character), stderr);
+ putc (XINT (character) & 0xFF, stderr);
#ifdef WINDOWSNT
/* Send the output to a debugger (nothing happens if there isn't one). */
{
Lisp_Object errname, errmsg, file_error, tail;
struct gcpro gcpro1;
- int i;
if (context != 0)
write_string_1 (context, -1, stream);
if (!NILP (caller) && SYMBOLP (caller))
{
Lisp_Object cname = SYMBOL_NAME (caller);
- char *name = alloca (SBYTES (cname));
+ char *name;
+ USE_SAFE_ALLOCA;
+ SAFE_ALLOCA (name, char *, SBYTES (cname));
memcpy (name, SDATA (cname), SBYTES (cname));
message_dolog (name, SBYTES (cname), 0, 0);
message_dolog (": ", 2, 0, 0);
+ SAFE_FREE ();
}
errname = Fcar (data);
}
else
{
- Lisp_Object error_conditions;
+ Lisp_Object error_conditions = Fget (errname, Qerror_conditions);
errmsg = Fget (errname, Qerror_message);
- error_conditions = Fget (errname, Qerror_conditions);
file_error = Fmemq (Qfile_error, error_conditions);
}
if (!NILP (file_error) && CONSP (tail))
errmsg = XCAR (tail), tail = XCDR (tail);
- if (STRINGP (errmsg))
- Fprinc (errmsg, stream);
- else
- write_string_1 ("peculiar error", -1, stream);
+ {
+ const char *sep = ": ";
- for (i = 0; CONSP (tail); tail = XCDR (tail), i = 1)
- {
- Lisp_Object obj;
+ if (!STRINGP (errmsg))
+ write_string_1 ("peculiar error", -1, stream);
+ else if (SCHARS (errmsg))
+ Fprinc (errmsg, stream);
+ else
+ sep = NULL;
- write_string_1 (i ? ", " : ": ", 2, stream);
- obj = XCAR (tail);
- if (!NILP (file_error) || EQ (errname, Qend_of_file))
- Fprinc (obj, stream);
- else
- Fprin1 (obj, stream);
- }
+ for (; CONSP (tail); tail = XCDR (tail), sep = ", ")
+ {
+ Lisp_Object obj;
+
+ if (sep)
+ write_string_1 (sep, 2, stream);
+ obj = XCAR (tail);
+ if (!NILP (file_error)
+ || EQ (errname, Qend_of_file) || EQ (errname, Quser_error))
+ Fprinc (obj, stream);
+ else
+ Fprin1 (obj, stream);
+ }
+ }
UNGCPRO;
}
if (HASH_TABLE_P (Vprint_number_table))
{ /* Remove unnecessary objects, which appear only once in OBJ;
- that is, whose status is Qt.
- Maybe a better way to do that is to copy elements to
- a new hash table. */
+ that is, whose status is Qt. */
struct Lisp_Hash_Table *h = XHASH_TABLE (Vprint_number_table);
- EMACS_INT i;
+ ptrdiff_t i;
for (i = 0; i < HASH_TABLE_SIZE (h); ++i)
if (!NILP (HASH_HASH (h, i))
print_preprocess (Lisp_Object obj)
{
int i;
- EMACS_INT size;
+ ptrdiff_t size;
int loop_count = 0;
Lisp_Object halftail;
|| ! (print_check_string_result & PRINT_STRING_UNSAFE_CHARSET_FOUND))
{
int i, c;
- EMACS_INT charpos = interval->position;
- EMACS_INT bytepos = string_char_to_byte (string, charpos);
+ ptrdiff_t charpos = interval->position;
+ ptrdiff_t bytepos = string_char_to_byte (string, charpos);
Lisp_Object charset;
charset = XCAR (XCDR (val));
print_string (obj, printcharfun);
else
{
- register EMACS_INT i_byte;
+ register ptrdiff_t i_byte;
struct gcpro gcpro1;
unsigned char *str;
- EMACS_INT size_byte;
+ ptrdiff_t size_byte;
/* 1 means we must ensure that the next character we output
cannot be taken as part of a hex character escape. */
int need_nonhex = 0;
register unsigned char *p = SDATA (SYMBOL_NAME (obj));
register unsigned char *end = p + SBYTES (SYMBOL_NAME (obj));
register int c;
- int i, i_byte;
- EMACS_INT size_byte;
+ ptrdiff_t i, i_byte;
+ ptrdiff_t size_byte;
Lisp_Object name;
name = SYMBOL_NAME (obj);
ptrdiff_t i;
register unsigned char c;
struct gcpro gcpro1;
- EMACS_INT size_in_chars
+ ptrdiff_t size_in_chars
= ((XBOOL_VECTOR (obj)->size + BOOL_VECTOR_BITS_PER_CHAR - 1)
/ BOOL_VECTOR_BITS_PER_CHAR);
else if (HASH_TABLE_P (obj))
{
struct Lisp_Hash_Table *h = XHASH_TABLE (obj);
- int i;
- EMACS_INT real_size, size;
+ ptrdiff_t i;
+ ptrdiff_t real_size, size;
#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, "%"pI"d/%"pI"d", h->count, ASIZE (h->next));
+ sprintf (buf, "%"pD"d/%"pD"d", h->count, ASIZE (h->next));
strout (buf, -1, -1, printcharfun);
}
sprintf (buf, " %p", h);
/* 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 %"pI"d", ASIZE (h->next));
+ sprintf (buf, "#s(hash-table size %"pD"d", ASIZE (h->next));
strout (buf, -1, -1, printcharfun);
if (!NILP (h->test))
}
else if (FONTP (obj))
{
- EMACS_INT i;
+ int i;
if (! FONT_OBJECT_P (obj))
{
}
else
{
- EMACS_INT size = ASIZE (obj);
+ ptrdiff_t size = ASIZE (obj);
if (COMPILEDP (obj))
{
PRINTCHAR ('#');
{
register int i;
register Lisp_Object tem;
- EMACS_INT real_size = size;
+ ptrdiff_t real_size = size;
/* Don't print more elements than the specified maximum. */
if (NATNUMP (Vprint_length)
strout ("in no buffer", -1, -1, printcharfun);
else
{
- sprintf (buf, "at %"pI"d", marker_position (obj));
+ sprintf (buf, "at %"pD"d", marker_position (obj));
strout (buf, -1, -1, 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 %"pI"d to %"pI"d in ",
+ sprintf (buf, "from %"pD"d to %"pD"d in ",
marker_position (OVERLAY_START (obj)),
marker_position (OVERLAY_END (obj)));
strout (buf, -1, -1, printcharfun);
if (MISCP (obj))
sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
else if (VECTORLIKEP (obj))
- sprintf (buf, "(PVEC 0x%08"pI"x)", ASIZE (obj));
+ sprintf (buf, "(PVEC 0x%08"pD"x)", ASIZE (obj));
else
sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
strout (buf, -1, -1, printcharfun);