[Top][All Lists]

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

DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX?

From: Paul Eggert
Subject: DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX?
Date: Sun, 10 Apr 2011 22:47:07 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Thunderbird/3.1.9

I've been looking into trimming down the sets of symbols exported and
imported by each C source file in Emacs, down to the list of symbols
that are actually needed.  This should make it easier to read the
code, and to do better static analysis, and shrink Emacs a bit by
removing unused cruft.  The resulting analysis will need more thinking
and will comprise several patches (I don't know how many yet, as I've
only started turning the crank).

I have found several glitches in Emacs so far.  For example, font.c's
functions copy-font-spec and merge-font-spec are defined via DEFUN in
a strange way at the C level, so that they are not visible to Lisp.
It's been that way for nearly three years, so I assume the simplest
way to fix this is to rename the functions so that they don't look to
the C programmer as if they're visible to Lisp.  Other problems
include unreachable functions and unused variables.

There is a bit of technology needed to get this working, namely, we
need a way to mark Lisp-visible functions either static or external at
the C level.  Usually they're static, but often they need to be
external because other C modules call them directly.  To do this, I
changed DEFUN so that it generates static functions, and added a new
macro DEFUE that generates external functions (i.e., DEFUE acts like
the old DEFUN).  I chose the name DEFUE because the "E" stands for
"external", "DEFUE" is the same length as "DEFUN" (so that indenting
need not change), and "DEFUE" starts with "DEFU" (so that the
make-docfile need not change).  But if people would prefer another
identifier (DEFUNEX, say?) it'd be easy to change.

Here's the key part of the first patch:

--- src/lisp.h  2011-04-09 18:42:31 +0000
+++ src/lisp.h  2011-04-11 00:46:54 +0000
@@ -1804,8 +1804,12 @@
  `doc' is documentation for the user.  */

 /* This version of DEFUN declares a function prototype with the right
-   arguments, so we can catch errors with maxargs at compile-time.  */
-#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)    \
+   arguments, so we can catch errors with maxargs at compile-time.
+   DEFUN defines an internal function, and DEFUE is similar but defines a
+   external function, which can be used in other C-language modules.  */
+#define DEFUN static DEFINE_FUNC
+#define DEFUE extern DEFINE_FUNC
+#define DEFINE_FUNC(lname, fnname, sname, minargs, maxargs, intspec, doc) \
   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;                          \
   DECL_ALIGN (struct Lisp_Subr, sname) =                               \
     { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)),    \
@@ -2279,6 +2283,8 @@
    appropriate prototype.  */
 #define EXFUN(fnname, maxargs) \
   extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
+#define INFUN(fnname, maxargs) \
+  static Lisp_Object fnname DEFUN_ARGS_ ## maxargs

 /* Forward declarations for prototypes.  */
 struct window;

and here's an example use of the new DEFUE macro:

--- src/lread.c 2011-04-04 07:48:36 +0000
+++ src/lread.c 2011-04-11 00:41:52 +0000
@@ -681,7 +681,7 @@
   return val;

-DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
+DEFUE ("read-char", Fread_char, Sread_char, 0, 3, 0,
        doc: /* Read a character from the command input (keyboard or macro).
 It is returned as a number.
 If the character has modifiers, they are resolved and reflected to the

I'm attaching the entire patch, gzipped, as most of it is pretty
mechanical substitution of DEFUE for DEFUN.  Comments, as usual, are

Attachment: patch-1.txt.gz
Description: GNU Zip compressed data

reply via email to

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