changeset 109308:3200fb11db9d

Make doprnt and related functions ANSI C compliant, with prototypes. * doprnt.c (doprnt): Take a va_list argument instead of count and pointer. * eval.c (error): Change to a standard-C variadic function. * xdisp.c (vmessage): Renamed from message, made static, and changed to take a va_list argument. (message): New variadic wrapper. (message_nolog): Now a variadic function, calling vmessage. * lisp.h: Include stdarg.h for va_list. (doprnt, error, message, message_nolog): Decls updated.
author Ken Raeburn <raeburn@raeburn.org>
date Sun, 11 Jul 2010 02:59:55 -0400
parents d115eb41fb0f
children 1d46091f1f65
files src/ChangeLog src/doprnt.c src/eval.c src/lisp.h src/xdisp.c
diffstat 5 files changed, 65 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sun Jul 11 09:39:00 2010 +0300
+++ b/src/ChangeLog	Sun Jul 11 02:59:55 2010 -0400
@@ -1,3 +1,15 @@
+2010-07-11  Ken Raeburn  <raeburn@raeburn.org>
+
+	* doprnt.c (doprnt): Take a va_list argument instead of count and
+	pointer.
+	* eval.c (error): Change to a standard-C variadic function.
+	* xdisp.c (vmessage): Renamed from message, made static, and
+	changed to take a va_list argument.
+	(message): New variadic wrapper.
+	(message_nolog): Now a variadic function, calling vmessage.
+	* lisp.h: Include stdarg.h for va_list.
+	(doprnt, error, message, message_nolog): Decls updated.
+
 2010-07-11  Eli Zaretskii  <eliz@gnu.org>
 
 	* process.c (syms_of_process) <delete-exited-processes>: Define
--- a/src/doprnt.c	Sun Jul 11 09:39:00 2010 +0300
+++ b/src/doprnt.c	Sun Jul 11 02:59:55 2010 -0400
@@ -59,9 +59,8 @@
    Integers are passed as C integers.  */
 
 int
-doprnt (char *buffer, register int bufsize, char *format, char *format_end, int nargs, char **args)
+doprnt (char *buffer, register int bufsize, char *format, char *format_end, va_list ap)
 {
-  int cnt = 0;			/* Number of arg to gobble next */
   register char *fmt = format;	/* Pointer into format string */
   register char *bufptr = buffer; /* Pointer into output buffer.. */
 
@@ -161,8 +160,6 @@
 	    case 'd':
 	    case 'o':
 	    case 'x':
-	      if (cnt == nargs)
-		error ("Not enough arguments for format string");
 	      if (sizeof (int) == sizeof (EMACS_INT))
 		;
 	      else if (sizeof (long) == sizeof (EMACS_INT))
@@ -173,7 +170,7 @@
 		string++;
 	      else
 		abort ();
-	      sprintf (sprintf_buffer, fmtcpy, args[cnt++]);
+	      sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *));
 	      /* Now copy into final output, truncating as nec.  */
 	      string = (unsigned char *) sprintf_buffer;
 	      goto doit;
@@ -182,12 +179,8 @@
 	    case 'e':
 	    case 'g':
 	      {
-		union { double d; char *half[2]; } u;
-		if (cnt + 1 == nargs)
-		  error ("Not enough arguments for format string");
-		u.half[0] = args[cnt++];
-		u.half[1] = args[cnt++];
-		sprintf (sprintf_buffer, fmtcpy, u.d);
+		double d = va_arg(ap, double);
+		sprintf (sprintf_buffer, fmtcpy, d);
 		/* Now copy into final output, truncating as nec.  */
 		string = (unsigned char *) sprintf_buffer;
 		goto doit;
@@ -196,11 +189,9 @@
 	    case 'S':
 	      string[-1] = 's';
 	    case 's':
-	      if (cnt == nargs)
-		error ("Not enough arguments for format string");
 	      if (fmtcpy[1] != 's')
 		minlen = atoi (&fmtcpy[1]);
-	      string = (unsigned char *) args[cnt++];
+	      string = va_arg(ap, unsigned char *);
 	      tem = strlen (string);
 	      width = strwidth (string, tem);
 	      goto doit1;
@@ -250,16 +241,21 @@
 	      continue;
 
 	    case 'c':
-	      if (cnt == nargs)
-		error ("Not enough arguments for format string");
-	      tem = CHAR_STRING ((int) (EMACS_INT) args[cnt], charbuf);
-	      string = charbuf;
-	      cnt++;
-	      string[tem] = 0;
-	      width = strwidth (string, tem);
-	      if (fmtcpy[1] != 'c')
-		minlen = atoi (&fmtcpy[1]);
-	      goto doit1;
+	      {
+		/* 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, 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 */
--- a/src/eval.c	Sun Jul 11 09:39:00 2010 +0300
+++ b/src/eval.c	Sun Jul 11 02:59:55 2010 -0400
@@ -2003,9 +2003,7 @@
 
 /* VARARGS 1 */
 void
-error (m, a1, a2, a3)
-     char *m;
-     char *a1, *a2, *a3;
+error (char *m, ...)
 {
   char buf[200];
   int size = 200;
@@ -2015,15 +2013,18 @@
   int allocated = 0;
   Lisp_Object string;
 
-  args[0] = a1;
-  args[1] = a2;
-  args[2] = a3;
-
   mlen = strlen (m);
 
   while (1)
     {
-      int used = doprnt (buffer, size, m, m + mlen, 3, args);
+      va_list ap;
+      int used;
+
+      /* A va_list can't be reused if we have to go around the loop
+	 again; we need to "reinitialize" it each time.  */
+      va_start(ap, m);
+      used = doprnt (buffer, size, m, m + mlen, ap);
+      va_end(ap);
       if (used < size)
 	break;
       size *= 2;
--- a/src/lisp.h	Sun Jul 11 09:39:00 2010 +0300
+++ b/src/lisp.h	Sun Jul 11 02:59:55 2010 -0400
@@ -21,6 +21,8 @@
 #ifndef EMACS_LISP_H
 #define EMACS_LISP_H
 
+#include <stdarg.h>
+
 /* Use the configure flag --enable-checking[=LIST] to enable various
    types of run time checks for Lisp objects.  */
 
@@ -2648,8 +2650,8 @@
 extern Lisp_Object current_message (void);
 extern void set_message (const char *s, Lisp_Object, int, int);
 extern void clear_message (int, int);
-extern void message (/* char *, ... */);
-extern void message_nolog (/* char *, ... */);
+extern void message (char *, ...);
+extern void message_nolog (char *, ...);
 extern void message1 (char *);
 extern void message1_nolog (char *);
 extern void message2 (const char *, int, int);
@@ -2798,7 +2800,7 @@
 extern void syms_of_print (void);
 
 /* Defined in doprnt.c */
-extern int doprnt (char *, int, char *, char *, int, char **);
+extern int doprnt (char *, int, char *, char *, va_list);
 
 /* Defined in lread.c */
 extern Lisp_Object Qvariable_documentation, Qstandard_input;
@@ -2910,7 +2912,7 @@
 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 (/* char *, ... */) NO_RETURN;
+extern void error (char *, ...) NO_RETURN;
 extern void do_autoload (Lisp_Object, Lisp_Object);
 extern Lisp_Object un_autoload (Lisp_Object);
 EXFUN (Ffetch_bytecode, 1);
--- a/src/xdisp.c	Sun Jul 11 09:39:00 2010 +0300
+++ b/src/xdisp.c	Sun Jul 11 02:59:55 2010 -0400
@@ -8494,9 +8494,8 @@
 /* Dump an informative message to the minibuf.  If M is 0, clear out
    any existing message, and let the mini-buffer text show through.  */
 
-/* VARARGS 1 */
-void
-message (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
+static void
+vmessage (char *m, va_list ap)
 {
   if (noninteractive)
     {
@@ -8505,7 +8504,7 @@
 	  if (noninteractive_need_newline)
 	    putc ('\n', stderr);
 	  noninteractive_need_newline = 0;
-	  fprintf (stderr, m, a1, a2, a3);
+	  vfprintf (stderr, m, ap);
 	  if (cursor_in_echo_area == 0)
 	    fprintf (stderr, "\n");
 	  fflush (stderr);
@@ -8533,13 +8532,9 @@
 	  if (m)
 	    {
 	      int len;
-	      char *a[3];
-	      a[0] = (char *) a1;
-	      a[1] = (char *) a2;
-	      a[2] = (char *) a3;
 
 	      len = doprnt (FRAME_MESSAGE_BUF (f),
-			    FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
+			    FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap);
 
 	      message2 (FRAME_MESSAGE_BUF (f), len, 0);
 	    }
@@ -8553,17 +8548,29 @@
     }
 }
 
+void
+message (char *m, ...)
+{
+  va_list ap;
+  va_start (ap, m);
+  vmessage (m, ap);
+  va_end (ap);
+}
+
 
 /* The non-logging version of message.  */
 
 void
-message_nolog (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
+message_nolog (char *m, ...)
 {
   Lisp_Object old_log_max;
+  va_list ap;
+  va_start (ap, m);
   old_log_max = Vmessage_log_max;
   Vmessage_log_max = Qnil;
-  message (m, a1, a2, a3);
+  vmessage (m, ap);
   Vmessage_log_max = old_log_max;
+  va_end (ap);
 }