+2011-04-09 Paul Eggert <eggert@cs.ucla.edu>
+
+ * lib/allocator.c: New file, automatically generated by gnulib.
+
2011-04-07 Glenn Morris <rgm@gnu.org>
* autogen/update_autogen: Ignore comment diffs in ldefs-boot.el.
+2011-04-07 Paul Eggert <eggert@cs.ucla.edu>
+
+ Remove the doprnt implementation, as Emacs now uses vsnprintf.
+ * MAINTAINERS: Remove src/doprnt.c.
+
2011-03-07 Chong Yidong <cyd@stupidchicken.com>
* Version 23.3 released.
src/data.c
src/dispnew.c
src/doc.c
-src/doprnt.c
src/ecrt0.c
src/emacs.c
src/epaths.in
src/xrdb.c
src/xselect.c
src/xterm.c
-
--- /dev/null
+#define _GL_USE_STDLIB_ALLOC 1
+#include <config.h>
+#include "allocator.h"
+#include <stdlib.h>
+struct allocator const stdlib_allocator = { malloc, realloc, free, NULL };
attributes do not work with pointers to functions. See
<http://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00007.html>. */
- /* Call MALLOC to allocate memory, like 'malloc'. On failure MALLOC
+ /* Call ALLOCATE to allocate memory, like 'malloc'. On failure ALLOCATE
should return NULL, though not necessarily set errno. When given
a zero size it may return NULL even if successful. */
- void *(*malloc) (size_t);
+ void *(*allocate) (size_t);
- /* If nonnull, call REALLOC to reallocate memory, like 'realloc'.
- On failure REALLOC should return NULL, though not necessarily set
+ /* If nonnull, call REALLOCATE to reallocate memory, like 'realloc'.
+ On failure REALLOCATE should return NULL, though not necessarily set
errno. When given a zero size it may return NULL even if
successful. */
- void *(*realloc) (void *, size_t);
+ void *(*reallocate) (void *, size_t);
/* Call FREE to free memory, like 'free'. */
void (*free) (void *);
void (*die) (void);
};
+/* An allocator using the stdlib functions and a null DIE function. */
+extern struct allocator const stdlib_allocator;
+
#endif
#include <errno.h>
#include <limits.h>
-#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-/* Use the system functions, not the gnulib overrides, because this
- module does not depend on GNU or POSIX semantics. */
-#undef malloc
-#undef realloc
-
/* Define this independently so that stdint.h is not a prerequisite. */
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
}
#endif
-/* A standard allocator. For now, only careadlinkat needs this, but
- perhaps it should be moved to the allocator module. */
-static struct allocator const standard_allocator =
- { malloc, realloc, free, NULL };
-
/* Assuming the current directory is FD, get the symbolic link value
of FILENAME as a null-terminated string and put it into a buffer.
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
char stack_buf[1024];
if (! alloc)
- alloc = &standard_allocator;
+ alloc = &stdlib_allocator;
if (! buffer_size)
{
if (buf == stack_buf)
{
- char *b = (char *) alloc->malloc (link_size);
+ char *b = (char *) alloc->allocate (link_size);
if (! b)
break;
memcpy (b, buf, link_size);
buf = b;
}
- else if (link_size < buf_size && buf != buffer && alloc->realloc)
+ else if (link_size < buf_size && buf != buffer && alloc->reallocate)
{
/* Shrink BUF before returning it. */
- char *b = (char *) alloc->realloc (buf, link_size);
+ char *b = (char *) alloc->reallocate (buf, link_size);
if (b)
buf = b;
}
buf_size = buf_size_max;
else
break;
- buf = (char *) alloc->malloc (buf_size);
+ buf = (char *) alloc->allocate (buf_size);
}
while (buf);
libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
EXTRA_libgnu_a_SOURCES =
+## begin gnulib module allocator
+
+libgnu_a_SOURCES += allocator.c
+
+EXTRA_DIST += allocator.h
+
+## end gnulib module allocator
+
## begin gnulib module arg-nonnull
# The BUILT_SOURCES created by this Makefile snippet are not used via #include
libgnu_a_SOURCES += careadlinkat.c
-EXTRA_DIST += allocator.h careadlinkat.h
+EXTRA_DIST += careadlinkat.h
## end gnulib module careadlinkat
# endif
#endif
+/* If _GL_USE_STDLIB_ALLOC is nonzero, the including module does not
+ rely on GNU or POSIX semantics for malloc and realloc (for example,
+ by never specifying a zero size), so it does not need malloc or
+ realloc to be redefined. */
#if @GNULIB_MALLOC_POSIX@
# if @REPLACE_MALLOC@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+ || _GL_USE_STDLIB_ALLOC)
# undef malloc
# define malloc rpl_malloc
# endif
_GL_CXXALIAS_SYS (malloc, void *, (size_t size));
# endif
_GL_CXXALIASWARN (malloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
# undef malloc
/* Assume malloc is always declared. */
_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
#if @GNULIB_REALLOC_POSIX@
# if @REPLACE_REALLOC@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# if !((defined __cplusplus && defined GNULIB_NAMESPACE) \
+ || _GL_USE_STDLIB_ALLOC)
# undef realloc
# define realloc rpl_realloc
# endif
_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size));
# endif
_GL_CXXALIASWARN (realloc);
-#elif defined GNULIB_POSIXCHECK
+#elif defined GNULIB_POSIXCHECK && !_GL_USE_STDLIB_ALLOC
# undef realloc
/* Assume realloc is always declared. */
_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - "
+2011-04-09 Paul Eggert <eggert@cs.ucla.edu>
+
+ Remove the doprnt implementation, as Emacs now uses vsnprintf.
+ * emacs-lisp/find-gc.el (find-gc-source-files): Remove doprnt.c.
+
2011-04-08 Sho Nakatani <lay.sakura@gmail.com>
* doc-view.el (doc-view-fit-width-to-window)
"alloc.c" "data.c" "doc.c" "editfns.c"
"callint.c" "eval.c" "fns.c" "print.c" "lread.c"
"abbrev.c" "syntax.c" "unexcoff.c"
- "bytecode.c" "process.c" "callproc.c" "doprnt.c"
+ "bytecode.c" "process.c" "callproc.c"
"x11term.c" "x11fns.c"))
m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
AC_REQUIRE([AC_PROG_RANLIB])
+ # Code from module allocator:
# Code from module arg-nonnull:
# Code from module c++defs:
# Code from module careadlinkat:
m4_pushdef([gl_LIBSOURCES_DIR], [])
gl_COMMON
gl_source_base='lib'
+ # Code from module allocator:
# Code from module arg-nonnull:
# Code from module c++defs:
# Code from module careadlinkat:
build-aux/arg-nonnull.h
build-aux/c++defs.h
build-aux/warn-on-use.h
+ lib/allocator.c
lib/allocator.h
lib/careadlinkat.c
lib/careadlinkat.h
+2011-04-09 Paul Eggert <eggert@cs.ucla.edu>
+
+ * eval.c: Port to Windows vsnprintf (Bug#8435).
+ Include <limits.h>.
+ (SIZE_MAX): Define if the headers do not.
+ (verror): Do not give up if vsnprintf returns a negative count.
+ Instead, grow the buffer. This ports to Windows vsnprintf, which
+ does not conform to C99. Problem reported by Eli Zaretskii.
+ Also, simplify the allocation scheme, by avoiding the need for
+ calling realloc, and removing the ALLOCATED variable.
+
+ * eval.c (verror): Initial buffer size is 4000 (not 200) bytes.
+
+ Remove the doprnt implementation, as Emacs now uses vsnprintf.
+ * doprnt.c: Remove.
+ * lisp.h (doprnt): Remove.
+ * Makefile.in (base_obj): Remove doprnt.o.
+ * deps.mk (doprnt.o): Remove.
+
+ error: Print 32- and 64-bit integers portably (Bug#8435).
+ Without this change, on typical 64-bit hosts error ("...%d...", N)
+ was used to print both 32- and 64-bit integers N, which relied on
+ undefined behavior.
+ * lisp.h, src/m/amdx86-64.h, src/m/ia64.h, src/m/ibms390x.h (pEd):
+ New macro.
+ * lisp.h (error, verror): Mark as printf-like functions.
+ * eval.c (verror): Use vsnprintf, not doprnt, to do the real work.
+ Report overflow in size calculations when allocating printf buffer.
+ Do not truncate output string at its first null byte.
+ * xdisp.c (vmessage): Use vsnprintf, not doprnt, to do the real work.
+ Truncate the output at a character boundary, since vsnprintf does not
+ do that.
+ * charset.c (check_iso_charset_parameter): Convert internal
+ character to string before calling 'error', since %c now has the
+ printf meaning.
+ * coding.c (Fdecode_sjis_char, Fdecode_big5_char): Avoid int
+ overflow when computing char to be passed to 'error'. Do not
+ pass Lisp_Object to 'error'; pass the integer instead.
+ * nsfns.m (Fns_do_applescript): Use int, not long, since it's
+ formatted with plain %d.
+
+ * eval.c (internal_lisp_condition_case): Don't pass spurious arg.
+
+ * keyboard.c (access_keymap_keyremap): Print func name, not garbage.
+
+ * coding.c (Fdecode_sjis_char): Don't assume CODE fits in int.
+
+ * xterm.c (x_catch_errors): Remove duplicate declaration.
+
+ * term.c (maybe_fatal): Mark its 3rd arg as a printf format, too.
+
+ * xdisp.c, lisp.h (message_nolog): Remove; unused.
+
2011-04-09 Chong Yidong <cyd@stupidchicken.com>
* ftfont.c (get_adstyle_property, ftfont_pattern_entity): Use
syntax.o $(UNEXEC_OBJ) bytecode.o \
process.o gnutls.o callproc.o \
region-cache.o sound.o atimer.o \
- doprnt.o intervals.o textprop.o composite.o xml.o \
+ intervals.o textprop.o composite.o xml.o \
$(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ)
obj = $(base_obj) $(NS_OBJC_OBJ)
table = check_category_table (table);
if (!NILP (CATEGORY_DOCSTRING (table, XFASTINT (category))))
- error ("Category `%c' is already defined", XFASTINT (category));
+ error ("Category `%c' is already defined", (int) XFASTINT (category));
if (!NILP (Vpurify_flag))
docstring = Fpurecopy (docstring);
CATEGORY_DOCSTRING (table, XFASTINT (category)) = docstring;
table = check_category_table (table);
if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category))))
- error ("Undefined category: %c", XFASTINT (category));
+ error ("Undefined category: %c", (int) XFASTINT (category));
set_value = NILP (reset) ? Qt : Qnil;
unbind_to (count, Qnil);
if (fd < 0
|| ! (fp = fdopen (fd, "r")))
- error ("Failure in loading charset map: %S", SDATA (mapfile));
+ error ("Failure in loading charset map: %s", SDATA (mapfile));
/* Use SAFE_ALLOCA instead of alloca, as `charset_map_entries' is
large (larger than MAX_ALLOCA). */
{
CHECK_NUMBER (val);
if (XINT (val) < '0' || XINT (val) > 127)
- error ("Invalid iso-final-char: %d", XINT (val));
+ error ("Invalid iso-final-char: %"pEd, XINT (val));
charset.iso_final = XINT (val);
}
{
CHECK_NATNUM (val);
if ((XINT (val) > 0 && XINT (val) <= 128) || XINT (val) >= 256)
- error ("Invalid emacs-mule-id: %d", XINT (val));
+ error ("Invalid emacs-mule-id: %"pEd, XINT (val));
charset.emacs_mule_id = XINT (val);
}
CHECK_NATNUM (final_char);
if (XINT (dimension) > 3)
- error ("Invalid DIMENSION %d, it should be 1, 2, or 3", XINT (dimension));
+ error ("Invalid DIMENSION %"pEd", it should be 1, 2, or 3",
+ XINT (dimension));
if (XINT (chars) != 94 && XINT (chars) != 96)
- error ("Invalid CHARS %d, it should be 94 or 96", XINT (chars));
+ error ("Invalid CHARS %"pEd", it should be 94 or 96", XINT (chars));
if (XINT (final_char) < '0' || XINT (final_char) > '~')
- error ("Invalid FINAL-CHAR %c, it should be `0'..`~'", XINT (chars));
+ {
+ unsigned char str[MAX_MULTIBYTE_LENGTH + 1];
+ int len = CHAR_STRING (XINT (chars), str);
+ str[len] = '\0';
+ error ("Invalid FINAL-CHAR %s, it should be `0'..`~'", str);
+ }
}
{
Lisp_Object spec, attrs, val;
struct charset *charset_roman, *charset_kanji, *charset_kana, *charset;
+ EMACS_INT ch;
int c;
CHECK_NATNUM (code);
- c = XFASTINT (code);
+ ch = XFASTINT (code);
CHECK_CODING_SYSTEM_GET_SPEC (Vsjis_coding_system, spec);
attrs = AREF (spec, 0);
- if (ASCII_BYTE_P (c)
+ if (ASCII_BYTE_P (ch)
&& ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)))
return code;
charset_kana = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val);
charset_kanji = CHARSET_FROM_ID (XINT (XCAR (val)));
- if (c <= 0x7F)
- charset = charset_roman;
- else if (c >= 0xA0 && c < 0xDF)
+ if (ch <= 0x7F)
{
+ c = ch;
+ charset = charset_roman;
+ }
+ else if (ch >= 0xA0 && ch < 0xDF)
+ {
+ c = ch - 0x80;
charset = charset_kana;
- c -= 0x80;
}
else
{
- int c1 = c >> 8, c2 = c & 0xFF;
+ EMACS_INT c1 = ch >> 8;
+ int c2 = ch & 0xFF;
if (c1 < 0x81 || (c1 > 0x9F && c1 < 0xE0) || c1 > 0xEF
|| c2 < 0x40 || c2 == 0x7F || c2 > 0xFC)
- error ("Invalid code: %d", code);
+ error ("Invalid code: %"pEd, ch);
+ c = ch;
SJIS_TO_JIS (c);
charset = charset_kanji;
}
c = DECODE_CHAR (charset, c);
if (c < 0)
- error ("Invalid code: %d", code);
+ error ("Invalid code: %"pEd, ch);
return make_number (c);
}
{
Lisp_Object spec, attrs, val;
struct charset *charset_roman, *charset_big5, *charset;
+ EMACS_INT ch;
int c;
CHECK_NATNUM (code);
- c = XFASTINT (code);
+ ch = XFASTINT (code);
CHECK_CODING_SYSTEM_GET_SPEC (Vbig5_coding_system, spec);
attrs = AREF (spec, 0);
- if (ASCII_BYTE_P (c)
+ if (ASCII_BYTE_P (ch)
&& ! NILP (CODING_ATTR_ASCII_COMPAT (attrs)))
return code;
charset_roman = CHARSET_FROM_ID (XINT (XCAR (val))), val = XCDR (val);
charset_big5 = CHARSET_FROM_ID (XINT (XCAR (val)));
- if (c <= 0x7F)
- charset = charset_roman;
+ if (ch <= 0x7F)
+ {
+ c = ch;
+ charset = charset_roman;
+ }
else
{
- int b1 = c >> 8, b2 = c & 0x7F;
+ EMACS_INT b1 = ch >> 8;
+ int b2 = ch & 0x7F;
if (b1 < 0xA1 || b1 > 0xFE
|| b2 < 0x40 || (b2 > 0x7E && b2 < 0xA1) || b2 > 0xFE)
- error ("Invalid code: %d", code);
+ error ("Invalid code: %"pEd, ch);
+ c = ch;
charset = charset_big5;
}
- c = DECODE_CHAR (charset, (unsigned )c);
+ c = DECODE_CHAR (charset, c);
if (c < 0)
- error ("Invalid code: %d", code);
+ error ("Invalid code: %"pEd, ch);
return make_number (c);
}
|| (EQ (operation, Qinsert_file_contents) && CONSP (target)
&& STRINGP (XCAR (target)) && BUFFERP (XCDR (target)))
|| (EQ (operation, Qopen_network_stream) && INTEGERP (target))))
- error ("Invalid %dth argument", XFASTINT (target_idx) + 1);
+ error ("Invalid %"pEd"th argument", XFASTINT (target_idx) + 1);
if (CONSP (target))
target = XCAR (target);
CHECK_CHARSET_GET_ID (tmp1, id);
CHECK_NATNUM_CDR (val);
if (XINT (XCDR (val)) >= 4)
- error ("Invalid graphic register number: %d", XINT (XCDR (val)));
+ error ("Invalid graphic register number: %"pEd, XINT (XCDR (val)));
XSETCAR (val, make_number (id));
}
# doc.o's dependency on buildobj.h is in src/Makefile.in.
doc.o: doc.c lisp.h $(config_h) buffer.h keyboard.h keymap.h \
character.h systime.h coding.h composite.h ../lib/unistd.h globals.h
-doprnt.o: doprnt.c character.h lisp.h globals.h ../lib/unistd.h $(config_h)
dosfns.o: buffer.h termchar.h termhooks.h frame.h blockinput.h window.h \
msdos.h dosfns.h dispextern.h charset.h coding.h atimer.h systime.h \
lisp.h $(config_h)
if (0 > lseek (fd, position - offset, 0))
{
emacs_close (fd);
- error ("Position %ld out of range in doc string file \"%s\"",
+ error ("Position %"pEd" out of range in doc string file \"%s\"",
position, name);
}
; /* Just a source file name boundary marker. Ignore it. */
else
- error ("DOC file invalid at position %d", pos);
+ error ("DOC file invalid at position %"pEd, pos);
}
}
pos += end - buf;
+++ /dev/null
-/* Output like sprintf to a buffer of specified size.
- Also takes args differently: pass one pointer to an array of strings
- in addition to the format string which is separate.
- Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc.
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
-
-
-#include <config.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <setjmp.h>
-
-#ifdef STDC_HEADERS
-#include <float.h>
-#endif
-
-#include <unistd.h>
-
-#include "lisp.h"
-
-/* Since we use the macro CHAR_HEAD_P, we have to include this, but
- don't have to include others because CHAR_HEAD_P does not contains
- another macro. */
-#include "character.h"
-
-#ifndef DBL_MAX_10_EXP
-#define DBL_MAX_10_EXP 308 /* IEEE double */
-#endif
-
-/* Generate output from a format-spec FORMAT,
- terminated at position FORMAT_END.
- Output goes in BUFFER, which has room for BUFSIZE chars.
- If the output does not fit, truncate it to fit.
- Returns the number of bytes stored into BUFFER.
- ARGS points to the vector of arguments, and NARGS says how many.
- A double counts as two arguments.
- String arguments are passed as C strings.
- Integers are passed as C integers. */
-
-EMACS_INT
-doprnt (char *buffer, register int bufsize, const char *format,
- const char *format_end, va_list ap)
-{
- const char *fmt = format; /* Pointer into format string */
- register char *bufptr = buffer; /* Pointer into output buffer.. */
-
- /* Use this for sprintf unless we need something really big. */
- char tembuf[DBL_MAX_10_EXP + 100];
-
- /* Size of sprintf_buffer. */
- unsigned size_allocated = sizeof (tembuf);
-
- /* Buffer to use for sprintf. Either tembuf or same as BIG_BUFFER. */
- char *sprintf_buffer = tembuf;
-
- /* Buffer we have got with malloc. */
- char *big_buffer = 0;
-
- register int tem;
- char *string;
- char fixed_buffer[20]; /* Default buffer for small formatting. */
- char *fmtcpy;
- int minlen;
- char charbuf[MAX_MULTIBYTE_LENGTH + 1]; /* Used for %c. */
-
- if (format_end == 0)
- format_end = format + strlen (format);
-
- if ((format_end - format + 1) < sizeof (fixed_buffer))
- fmtcpy = fixed_buffer;
- else
- fmtcpy = (char *) alloca (format_end - format + 1);
-
- bufsize--;
-
- /* Loop until end of format string or buffer full. */
- while (fmt != format_end && bufsize > 0)
- {
- if (*fmt == '%') /* Check for a '%' character */
- {
- unsigned size_bound = 0;
- EMACS_INT width; /* Columns occupied by STRING. */
-
- fmt++;
- /* Copy this one %-spec into fmtcpy. */
- string = fmtcpy;
- *string++ = '%';
- while (1)
- {
- *string++ = *fmt;
- if ('0' <= *fmt && *fmt <= '9')
- {
- /* Get an idea of how much space we might need.
- This might be a field width or a precision; e.g.
- %1.1000f and %1000.1f both might need 1000+ bytes.
- Parse the width or precision, checking for overflow. */
- unsigned n = *fmt - '0';
- while ('0' <= fmt[1] && fmt[1] <= '9')
- {
- if (n * 10 + fmt[1] - '0' < n)
- error ("Format width or precision too large");
- n = n * 10 + fmt[1] - '0';
- *string++ = *++fmt;
- }
-
- if (size_bound < n)
- size_bound = n;
- }
- else if (*fmt == '-' || *fmt == ' ' || *fmt == '.' || *fmt == '+')
- ;
- else
- break;
- fmt++;
- }
- *string = 0;
-
- /* Make the size bound large enough to handle floating point formats
- with large numbers. */
- if (size_bound + DBL_MAX_10_EXP + 50 < size_bound)
- error ("Format width or precision too large");
- size_bound += DBL_MAX_10_EXP + 50;
-
- /* Make sure we have that much. */
- if (size_bound > size_allocated)
- {
- if (big_buffer)
- big_buffer = (char *) xrealloc (big_buffer, size_bound);
- else
- big_buffer = (char *) xmalloc (size_bound);
- sprintf_buffer = big_buffer;
- size_allocated = size_bound;
- }
- minlen = 0;
- switch (*fmt++)
- {
- default:
- error ("Invalid format operation %%%c", fmt[-1]);
-
-/* case 'b': */
- case 'd':
- case 'o':
- case 'x':
- if (sizeof (int) == sizeof (EMACS_INT))
- ;
- else if (sizeof (long) == sizeof (EMACS_INT))
- /* Insert an `l' the right place. */
- string[1] = string[0],
- string[0] = string[-1],
- string[-1] = 'l',
- string++;
- else
- abort ();
- sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *));
- /* Now copy into final output, truncating as nec. */
- string = sprintf_buffer;
- goto doit;
-
- case 'f':
- case 'e':
- case 'g':
- {
- double d = va_arg(ap, double);
- sprintf (sprintf_buffer, fmtcpy, d);
- /* Now copy into final output, truncating as nec. */
- string = sprintf_buffer;
- goto doit;
- }
-
- case 'S':
- string[-1] = 's';
- case 's':
- if (fmtcpy[1] != 's')
- minlen = atoi (&fmtcpy[1]);
- string = va_arg (ap, char *);
- tem = strlen (string);
- width = strwidth (string, tem);
- goto doit1;
-
- /* Copy string into final output, truncating if no room. */
- doit:
- /* Coming here means STRING contains ASCII only. */
- width = tem = strlen (string);
- doit1:
- /* We have already calculated:
- TEM -- length of STRING,
- WIDTH -- columns occupied by STRING when displayed, and
- MINLEN -- minimum columns of the output. */
- if (minlen > 0)
- {
- while (minlen > width && bufsize > 0)
- {
- *bufptr++ = ' ';
- bufsize--;
- minlen--;
- }
- minlen = 0;
- }
- if (tem > bufsize)
- {
- /* Truncate the string at character boundary. */
- tem = bufsize;
- while (!CHAR_HEAD_P (string[tem - 1])) tem--;
- memcpy (bufptr, string, tem);
- /* We must calculate WIDTH again. */
- width = strwidth (bufptr, tem);
- }
- else
- memcpy (bufptr, string, tem);
- bufptr += tem;
- bufsize -= tem;
- if (minlen < 0)
- {
- while (minlen < - width && bufsize > 0)
- {
- *bufptr++ = ' ';
- bufsize--;
- minlen++;
- }
- minlen = 0;
- }
- continue;
-
- case 'c':
- {
- /* Sometimes for %c we pass a char, which would widen
- to int. Sometimes we pass XFASTINT() or XINT()
- values, which would be EMACS_INT. Let's hope that
- both are passed the same way, otherwise we'll need
- to rewrite callers. */
- EMACS_INT chr = va_arg(ap, EMACS_INT);
- tem = CHAR_STRING ((int) chr, (unsigned char *) charbuf);
- string = charbuf;
- string[tem] = 0;
- width = strwidth (string, tem);
- if (fmtcpy[1] != 'c')
- minlen = atoi (&fmtcpy[1]);
- goto doit1;
- }
-
- case '%':
- fmt--; /* Drop thru and this % will be treated as normal */
- }
- }
-
- {
- /* Just some character; Copy it if the whole multi-byte form
- fit in the buffer. */
- char *save_bufptr = bufptr;
-
- do { *bufptr++ = *fmt++; }
- while (--bufsize > 0 && !CHAR_HEAD_P (*fmt));
- if (!CHAR_HEAD_P (*fmt))
- {
- bufptr = save_bufptr;
- break;
- }
- }
- };
-
- /* If we had to malloc something, free it. */
- xfree (big_buffer);
-
- *bufptr = 0; /* Make sure our string end with a '\0' */
- return bufptr - buffer;
-}
#include <config.h>
+#include <limits.h>
#include <setjmp.h>
#include "lisp.h"
#include "blockinput.h"
#include "xterm.h"
#endif
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
/* This definition is duplicated in alloc.c and keyboard.c. */
/* Putting it in lisp.h makes cc bomb out! */
|| (CONSP (tem)
&& (SYMBOLP (XCAR (tem))
|| CONSP (XCAR (tem))))))
- error ("Invalid condition handler", tem);
+ error ("Invalid condition handler");
}
c.tag = Qnil;
void
verror (const char *m, va_list ap)
{
- char buf[200];
- EMACS_INT size = 200;
- int mlen;
+ char buf[4000];
+ size_t size = sizeof buf;
+ size_t size_max =
+ min (MOST_POSITIVE_FIXNUM, min (INT_MAX, SIZE_MAX - 1)) + 1;
char *buffer = buf;
- int allocated = 0;
+ int used;
Lisp_Object string;
- mlen = strlen (m);
-
while (1)
{
- EMACS_INT used;
- used = doprnt (buffer, size, m, m + mlen, ap);
- if (used < size)
- break;
- size *= 2;
- if (allocated)
- buffer = (char *) xrealloc (buffer, size);
- else
+ used = vsnprintf (buffer, size, m, ap);
+
+ if (used < 0)
{
- buffer = (char *) xmalloc (size);
- allocated = 1;
+ /* Non-C99 vsnprintf, such as w32, returns -1 when SIZE is too small.
+ Guess a larger USED to work around the incompatibility. */
+ used = (size <= size_max / 2 ? 2 * size
+ : size < size_max ? size_max - 1
+ : size_max);
}
+ else if (used < size)
+ break;
+ if (size_max <= used)
+ memory_full ();
+ size = used + 1;
+
+ if (buffer != buf)
+ xfree (buffer);
+ buffer = (char *) xmalloc (size);
}
- string = build_string (buffer);
- if (allocated)
+ string = make_string (buffer, used);
+ if (buffer != buf)
xfree (buffer);
xsignal1 (Qerror, string);
EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0);
if (converted < chars)
- error ("Can't convert the %dth character to unibyte", converted);
+ error ("Can't convert the %"pEd"th character to unibyte", converted);
string = make_unibyte_string ((char *) str, chars);
xfree (str);
}
i = i->right; /* Move to the right child */
}
else if (NULL_PARENT (i))
- error ("Point %d after end of properties", pos);
+ error ("Point %"pEd" after end of properties", pos);
else
i = INTERVAL_PARENT (i);
continue;
(To ignore it safely, we would need to gcpro a bunch of
other variables.) */
if (! (VECTORP (next) || STRINGP (next)))
- error ("Function %s returns invalid key sequence", tem);
+ error ("Function %s returns invalid key sequence",
+ SSDATA (SYMBOL_NAME (tem)));
}
return next;
}
#ifndef EMACS_INT
#define EMACS_INT long
#define BITS_PER_EMACS_INT BITS_PER_LONG
+#define pEd "ld"
#endif
#ifndef EMACS_UINT
#define EMACS_UINT unsigned long
#ifndef EMACS_INT
#define EMACS_INT int
#define BITS_PER_EMACS_INT BITS_PER_INT
+#define pEd "d"
#endif
#ifndef EMACS_UINT
#define EMACS_UINT unsigned int
extern void set_message (const char *s, Lisp_Object, EMACS_INT, int);
extern void clear_message (int, int);
extern void message (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
-extern void message_nolog (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
extern void message1 (const char *);
extern void message1_nolog (const char *);
extern void message2 (const char *, EMACS_INT, int);
extern void float_to_string (char *, double);
extern void syms_of_print (void);
-/* Defined in doprnt.c */
-extern EMACS_INT doprnt (char *, int, const char *, const char *, va_list);
-
+/* Defined in lread.c. */
extern Lisp_Object Qvariable_documentation, Qstandard_input;
extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
extern Lisp_Object initial_obarray;
extern void specbind (Lisp_Object, Lisp_Object);
extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
extern Lisp_Object unbind_to (int, Lisp_Object);
-extern void error (const char *, ...) NO_RETURN;
-extern void verror (const char *, va_list) NO_RETURN;
+extern void error (const char *, ...) NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 2);
+extern void verror (const char *, va_list)
+ NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0);
extern void do_autoload (Lisp_Object, Lisp_Object);
extern Lisp_Object un_autoload (Lisp_Object);
EXFUN (Ffetch_bytecode, 1);
/* Define the type to use. */
#define EMACS_INT long
+#define pEd "ld"
#define EMACS_UINT unsigned long
/* Define XPNTR to avoid or'ing with DATA_SEG_BITS */
/* Define the type to use. */
#define EMACS_INT long
+#define pEd "ld"
#define EMACS_UINT unsigned long
#ifdef REL_ALLOC
/* Define the type to use. */
#define EMACS_INT long
+#define pEd "ld"
#define EMACS_UINT unsigned long
/* On the 64 bit architecture, we can use 60 bits for addresses */
/* Define XPNTR to avoid or'ing with DATA_SEG_BITS */
#define XPNTR(a) XUINT (a)
-
if (!STRINGP (f->icon_name))
encoded_icon_name = encoded_name;
else
- encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
+ encoded_icon_name = ENCODE_UTF_8 (f->icon_name);
str = [NSString stringWithUTF8String: SDATA (encoded_icon_name)];
if (FRAME_ICONIFIED_P (f))
[[view window] setMiniwindowTitle: str];
- else
+ else
{
NSString *fstr;
0, /* x_set_fullscreen will ignore */
x_set_font_backend, /* generic OK */
x_set_alpha,
- 0, /* x_set_sticky */
- 0, /* x_set_tool_bar_position */
+ 0, /* x_set_sticky */
+ 0, /* x_set_tool_bar_position */
};
(Lisp_Object script)
{
Lisp_Object result;
- long status;
+ int status;
CHECK_STRING (script);
check_ns ();
{
struct ns_display_info *dpyinfo;
check_ns ();
-
+
dpyinfo = check_ns_display_info (display);
/* We force 24+ bit depths to 24-bit to prevent an overflow. */
return make_number (1 << min (dpyinfo->n_planes, 24));
pt.y = x_display_pixel_height (FRAME_NS_DISPLAY_INFO (f)) - XINT (top)
- height;
}
-
+
/* Ensure in bounds. (Note, screen origin = lower left.) */
if (INTEGERP (left))
*root_x = pt.x;
check_window_system_func = check_ns;
}
-
CHECK_NUMBER (tem);
err = cfsetspeed (&attr, XINT (tem));
if (err != 0)
- error ("cfsetspeed(%d) failed: %s", XINT (tem), emacs_strerror (errno));
+ error ("cfsetspeed(%"pEd") failed: %s", XINT (tem),
+ emacs_strerror (errno));
childp2 = Fplist_put (childp2, QCspeed, tem);
/* Configure bytesize. */
static void delete_tty (struct terminal *);
static void maybe_fatal (int must_succeed, struct terminal *terminal,
const char *str1, const char *str2, ...)
- NO_RETURN ATTRIBUTE_FORMAT_PRINTF (4, 5);
+ NO_RETURN ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5);
static void vfatal (const char *str, va_list ap)
NO_RETURN ATTRIBUTE_FORMAT_PRINTF (1, 0);
error ("Window height %d too small (after splitting)", size_int);
if (size_int + window_safe_height > XFASTINT (o->total_lines))
error ("Window height %d too small (after splitting)",
- XFASTINT (o->total_lines) - size_int);
+ (int) (XFASTINT (o->total_lines) - size_int));
if (NILP (o->parent)
|| NILP (XWINDOW (o->parent)->vchild))
{
error ("Window width %d too small (after splitting)", size_int);
if (size_int + window_safe_width > XFASTINT (o->total_cols))
error ("Window width %d too small (after splitting)",
- XFASTINT (o->total_cols) - size_int);
+ (int) (XFASTINT (o->total_cols) - size_int));
if (NILP (o->parent)
|| NILP (XWINDOW (o->parent)->hchild))
{
{
if (m)
{
- EMACS_INT len;
-
- len = doprnt (FRAME_MESSAGE_BUF (f),
- FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap);
+ char *buf = FRAME_MESSAGE_BUF (f);
+ size_t bufsize = FRAME_MESSAGE_BUF_SIZE (f);
+ int len = vsnprintf (buf, bufsize, m, ap);
+ if (len < 0)
+ len = 0;
+
+ /* Do any truncation at a character boundary. */
+ if (0 < bufsize && bufsize <= len)
+ for (len = bufsize - 1;
+ len && ! CHAR_HEAD_P (buf[len - 1]);
+ len--)
+ continue;
message2 (FRAME_MESSAGE_BUF (f), len, 0);
}
}
-/* The non-logging version of message. */
-
-void
-message_nolog (const char *m, ...)
-{
- Lisp_Object old_log_max;
- va_list ap;
- va_start (ap, m);
- old_log_max = Vmessage_log_max;
- Vmessage_log_max = Qnil;
- vmessage (m, ap);
- Vmessage_log_max = old_log_max;
- va_end (ap);
-}
-
-
/* Display the current message in the current mini-buffer. This is
only called from error handlers in process.c, and is not time
critical. */
struct terminal *t = get_terminal (object, 1);
if (t->type != output_x_window)
- error ("Terminal %d is not an X display", XINT (object));
+ error ("Terminal %"pEd" is not an X display", XINT (object));
dpyinfo = t->display_info.x;
}
Calling x_uncatch_errors resumes the normal error handling. */
-void x_check_errors (Display *dpy, const char *format);
-
void
x_catch_errors (Display *dpy)
{