emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new file tparam.h to fix Emacs API glitch


From: Paul Eggert
Subject: new file tparam.h to fix Emacs API glitch
Date: Tue, 08 Mar 2011 10:32:21 -0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7

term.c declares and uses a function tparam, but its definition in
tparam.c uses an incompatible API.  This violates the
C standard, and possibly can cause runtime problems.
I plan to fix the problem in the trunk with the following patch,
which adds a new file tparam.h that contains the  API
so that any future incompatibilities are caught.

I thought I'd give a heads-up as this may require
a change to the dependencies in the Windows build process.

* tparam.h: New file.
* term.c, tparam.h: Include it.
* deps.mk (term.o, tparam.o): Depend on tparam.h.
* term.c (tputs, tgetent, tgetflag, tgetnum, tparam, tgetstr):
Move these decls to tparam.h, and make them agree with what
is actually in tparam.c.  The previous trick of using incompatible
decls in different modules does not conform to the C standard.
All callers of tparam changed to use tparam's actual API.
* tparam.c (tparam1, tparam, tgoto):
Use const pointers where appropriate.
=== modified file 'src/deps.mk'
--- src/deps.mk 2011-02-20 10:53:22 +0000
+++ src/deps.mk 2011-03-08 18:04:33 +0000
@@ -190,13 +190,13 @@
 term.o: term.c termchar.h termhooks.h termopts.h lisp.h globals.h $(config_h) \
    cm.h frame.h disptab.h keyboard.h character.h charset.h coding.h ccl.h \
    xterm.h msdos.h window.h keymap.h blockinput.h atimer.h systime.h \
-   systty.h syssignal.h $(INTERVALS_H) buffer.h ../lib/unistd.h
+   systty.h syssignal.h tparam.h $(INTERVALS_H) buffer.h ../lib/unistd.h
 termcap.o: termcap.c lisp.h $(config_h)
 terminal.o: terminal.c frame.h termchar.h termhooks.h charset.h coding.h \
    keyboard.h lisp.h globals.h $(config_h) dispextern.h composite.h systime.h \
    msdos.h
 terminfo.o: terminfo.c lisp.h globals.h $(config_h)
-tparam.o: tparam.c lisp.h $(config_h)
+tparam.o: tparam.c tparam.h lisp.h $(config_h)
 undo.o: undo.c buffer.h commands.h window.h dispextern.h msdos.h \
    lisp.h globals.h $(config_h)
 unexaix.o: unexaix.c lisp.h $(config_h)

=== modified file 'src/term.c'
--- src/term.c  2011-03-08 17:31:51 +0000
+++ src/term.c  2011-03-08 18:18:03 +0000
@@ -32,6 +32,7 @@
 #include "lisp.h"
 #include "termchar.h"
 #include "termopts.h"
+#include "tparam.h"
 #include "buffer.h"
 #include "character.h"
 #include "charset.h"
@@ -53,18 +54,6 @@
 static int been_here = -1;
 #endif

-/* For now, don't try to include termcap.h.  On some systems,
-   configure finds a non-standard termcap.h that the main build
-   won't find.  */
-extern void tputs (const char *, int, int (*)(int));
-extern int tgetent (char *, const char *);
-extern int tgetflag (char *id);
-extern int tgetnum (char *id);
-
-char *tparam (char *, char *, int, int, ...);
-
-extern char *tgetstr (char *, char **);
-
 #include "cm.h"
 #ifdef HAVE_X_WINDOWS
 #include "xterm.h"
@@ -262,7 +251,7 @@
   struct tty_display_info *tty = FRAME_TTY (f);

   if (tty->TS_set_scroll_region)
-    buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1);
+    buf = tparam (tty->TS_set_scroll_region, 0, 0, start, stop - 1, 0, 0);
   else if (tty->TS_set_scroll_region_1)
     buf = tparam (tty->TS_set_scroll_region_1, 0, 0,
                  FRAME_LINES (f), start,
@@ -859,7 +848,7 @@

   if (tty->TS_ins_multi_chars)
     {
-      buf = tparam (tty->TS_ins_multi_chars, 0, 0, len);
+      buf = tparam (tty->TS_ins_multi_chars, 0, 0, len, 0, 0, 0);
       OUTPUT1 (tty, buf);
       xfree (buf);
       if (start)
@@ -955,7 +944,7 @@

   if (tty->TS_del_multi_chars)
     {
-      buf = tparam (tty->TS_del_multi_chars, 0, 0, n);
+      buf = tparam (tty->TS_del_multi_chars, 0, 0, n, 0, 0, 0);
       OUTPUT1 (tty, buf);
       xfree (buf);
     }
@@ -997,7 +986,7 @@
     {
       raw_cursor_to (f, vpos, 0);
       tty_background_highlight (tty);
-      buf = tparam (multi, 0, 0, i);
+      buf = tparam (multi, 0, 0, i, 0, 0, 0);
       OUTPUT (tty, buf);
       xfree (buf);
     }
@@ -2125,7 +2114,7 @@
       ts = tty->standout_mode ? tty->TS_set_background : 
tty->TS_set_foreground;
       if (fg >= 0 && ts)
        {
-          p = tparam (ts, NULL, 0, (int) fg);
+          p = tparam (ts, NULL, 0, (int) fg, 0, 0, 0);
          OUTPUT (tty, p);
          xfree (p);
        }
@@ -2133,7 +2122,7 @@
       ts = tty->standout_mode ? tty->TS_set_foreground : 
tty->TS_set_background;
       if (bg >= 0 && ts)
        {
-          p = tparam (ts, NULL, 0, (int) bg);
+          p = tparam (ts, NULL, 0, (int) bg, 0, 0, 0);
          OUTPUT (tty, p);
          xfree (p);
        }

=== modified file 'src/tparam.c'
--- src/tparam.c        2011-01-15 23:16:57 +0000
+++ src/tparam.c        2011-03-08 18:16:15 +0000
@@ -21,6 +21,7 @@
 #include <config.h>
 #include <setjmp.h>
 #include "lisp.h"            /* for xmalloc */
+#include "tparam.h"

 #ifndef NULL
 #define NULL (char *) 0
@@ -38,11 +39,12 @@

    The fourth and following args to tparam serve as the parameter values.  */

-static char *tparam1 (char *string, char *outstring, int len, char *up, char 
*left, register int *argp);
+static char *tparam1 (char const *string, char *outstring, int len,
+                     char *up, char *left, int *argp);

-/* VARARGS 2 */
 char *
-tparam (char *string, char *outstring, int len, int arg0, int arg1, int arg2, 
int arg3)
+tparam (const char *string, char *outstring, int len,
+       int arg0, int arg1, int arg2, int arg3)
 {
   int arg[4];

@@ -59,7 +61,7 @@
 static char tgoto_buf[50];

 char *
-tgoto (char *cm, int hpos, int vpos)
+tgoto (const char *cm, int hpos, int vpos)
 {
   int args[2];
   if (!cm)
@@ -70,10 +72,11 @@
 }

 static char *
-tparam1 (char *string, char *outstring, int len, char *up, char *left, 
register int *argp)
+tparam1 (const char *string, char *outstring, int len,
+        char *up, char *left, register int *argp)
 {
   register int c;
-  register char *p = string;
+  register const char *p = string;
   register char *op = outstring;
   char *outend;
   int outlen = 0;
@@ -277,4 +280,3 @@
 }

 #endif /* DEBUG */
-

=== added file 'src/tparam.h'
--- src/tparam.h        1970-01-01 00:00:00 +0000
+++ src/tparam.h        2011-03-08 18:16:45 +0000
@@ -0,0 +1,31 @@
+/* Interface definitions for termcap entries.
+
+Copyright (C) 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/>.  */
+
+
+/* Don't try to include termcap.h.  On some systems, configure finds a
+   non-standard termcap.h that the main build won't find.  */
+
+void tputs (const char *, int, int (*) (int));
+int tgetent (char *, const char *);
+int tgetflag (char *id);
+int tgetnum (char *id);
+char *tgetstr (char *, char **);
+char *tgoto (const char *, int, int);
+
+char *tparam (const char *, char *, int, int, int, int, int);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]