From: Paul Eggert <eggert@cs.ucla.edu>
To: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX?
Date: Sun, 10 Apr 2011 22:47:07 -0700 [thread overview]
Message-ID: <4DA295DB.20709@cs.ucla.edu> (raw)
[-- 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 --]
next reply other threads:[~2011-04-11 5:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-11 5:47 Paul Eggert [this message]
2011-04-11 6:27 ` DEFU* macro name for a extern DEFUN: DEFUE? DEFUNEX? 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DA295DB.20709@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.