unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX?
@ 2011-04-11  5:47 Paul Eggert
  2011-04-11  6:27 ` Dan Nicolaescu
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Paul Eggert @ 2011-04-11  5:47 UTC (permalink / raw)
  To: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 3465 bytes --]

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
welcome.

[-- Attachment #2: patch-1.txt.gz --]
[-- Type: application/x-gzip, Size: 36874 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-04-15  8:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-11  5:47 DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX? Paul Eggert
2011-04-11  6:27 ` Dan Nicolaescu
2011-04-11  6:37   ` Paul Eggert
2011-04-11 10:39   ` Juanma Barranquero
2011-04-11 16:49     ` Paul Eggert
2011-04-11 14:34 ` Jason Rumney
2011-04-11 22:37 ` Chong Yidong
2011-04-12  1:35   ` Paul Eggert
2011-04-14 23:52     ` checking static vs extern symbols Paul Eggert
2011-04-15  8:23       ` Eli Zaretskii
2011-04-15  1:15     ` DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX? Stefan Monnier
2011-04-12  3:34   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).