GNU bug report logs - #11935
XINT etc. should be functions

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Fri, 13 Jul 2012 15:15:02 UTC

Severity: wishlist

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11935 in the body.
You can then email your comments to 11935 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Fri, 13 Jul 2012 15:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Eggert <eggert <at> cs.ucla.edu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 13 Jul 2012 15:15:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: XINT etc. should be functions
Date: Fri, 13 Jul 2012 08:07:35 -0700
Tags: patch

Here's a patch I plan to install after some more testing.
It changes lisp.h to prefer functions to function-like
macros, and constants to object-like macros, when either
will do.  This makes the code easier to debug, as the
symbols are visible to GDB.  It also simplifies use, as
there's no more need to worry about arguments' side effects
being evaluated multiple times.

So, for example, instead of this:

   #if USE_LSB_TAG
   #define XINT(a) (XLI (a) >> INTTYPEBITS)
   #else
   #define XINT(a) (XLI (a) << INTTYPEBITS >> INTTYPEBITS)
   #endif

we now have this:

   static inline EMACS_INT
   XINT (Lisp_Object a)
   {
     EMACS_INT i = XLI (a);
     return (USE_LSB_TAG ? i : i << INTTYPEBITS) >> INTTYPEBITS;
   }

In the old days Emacs had to use macros for this sort of
thing, because C compilers generated significantly faster
code with macros.  Modern C compilers, however, don't have
this problem.  On the contrary, I would guess that this
improves performance slightly, as it shrinks the size of
Emacs's text segment by 0.5% on my platform (x86-64, GCC
4.7.1).


=== modified file 'ChangeLog'
--- ChangeLog	2012-07-13 02:38:30 +0000
+++ ChangeLog	2012-07-13 03:38:40 +0000
@@ -1,3 +1,9 @@
+2012-07-13  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	Use functions, not macros, for XINT etc.
+	* configure.ac (WARN_CFLAGS): Remove -Wbad-function-cast,
+	as it generates bogus warnings about reasonable casts of calls.
+
 2012-07-13  Glenn Morris  <rgm <at> gnu.org>
 
 	* configure.ac (opsysfile): Set to empty on gnu, cygwin.

=== modified file 'configure.ac'
--- configure.ac	2012-07-13 02:38:30 +0000
+++ configure.ac	2012-07-13 03:38:40 +0000
@@ -675,6 +675,7 @@
   nw="$nw -Winline"                 # OK to ignore 'inline'
   nw="$nw -Wsync-nand"              # irrelevant here, and provokes ObjC warning
   nw="$nw -Wunsafe-loop-optimizations" # OK to suppress unsafe optimizations
+  nw="$nw -Wbad-function-cast"      # These casts are no worse than others.
 
   # Emacs doesn't care about shadowing; see
   # <http://lists.gnu.org/archive/html/emacs-diffs/2011-11/msg00265.html>.

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2012-07-13 12:20:07 +0000
+++ src/ChangeLog	2012-07-13 14:46:11 +0000
@@ -1,3 +1,121 @@
+2012-07-13  Paul Eggert  <eggert <at> cs.ucla.edu>
+
+	Use functions, not macros, for XINT etc.
+	In lisp.h, prefer functions to function-like macros, and
+	constants to object-like macros, when either will do.  This:
+	 . makes the code easier to debug, as the symbols are visible to GDB.
+	 . simplifies use, as there's no more need to worry about
+	   arguments' side effects being evaluated multiple times.
+	 . shrinks the size of Emacs's text segment by 0.5%
+	   on my platform (x86-64, GCC 4.7.1).
+	* buffer.c (Qoverlap):
+	* data.c (Qsubrp):
+	* fns.c (Qhash_table_p):
+	Now extern, so lisp.h can use these symbols.
+	* dispextern.h: Include character.h, for MAX_CHAR etc.
+	(GLYPH, GLYPH_CHAR, GLYPH_FACE, SET_GLYPH_CHAR, SET_GLYPH_FACE)
+	(SET_GLYPH, GLYPH_CODE_CHAR, GLYPH_CODE_FACE)
+	(SET_GLYPH_FROM_GLYPH_CODE, GLYPH_MODE_LINE_FACE, GLYPH_CHAR_VALID_P)
+	(GLYPH_CODE_P): Move here from lisp.h.
+	(GLYPH_CHAR, GLYPH_FACE, GLYPH_CODE_CHAR, GLYPH_CODE_FACE)
+	(GLYPH_CHAR_VALID_P, GLYPH_CODE_P): Now functions, not macros.
+	(GLYPH_MODE_LINE_FACE): Now enums, not macros.
+	* eval.c (Fautoload): Cast XUNTAG output to intptr_t, since
+	XUNTAG now returns void *.
+	* lisp.h (CHECK_CONS_LIST, LISP_INT_TAG_P, XLI, XIL, XHASH, XTYPE)
+	(XINT, XFASTINT, XUINT, make_number, XPNTR, XUNTAG, EQ, XCONS, XVECTOR)
+	(XSTRING, XSYMBOL, XFLOAT, XPROCESS, XWINDOW, XTERMINAL, XSUBR)
+	(XBUFFER, XCHAR_TABLE, XSUB_CHAR_TABLE, XBOOL_VECTOR, CHECK_TYPE)
+	(CHECK_STRING_OR_BUFFER, XCAR, XCDR, XSETCAR, XSETCDR, CAR, CDR)
+	(CAR_SAFE, CDR_SAFE, STRING_MULTIBYTE, STRING_INTERVALS)
+	(STRING_SET_INTERVALS, SDATA, SSDATA, SREF, SSET, SCHARS)
+	(STRING_BYTES, SBYTES, STRING_SET_CHARS, ASIZE, ASET)
+	(CHAR_TABLE_EXTRA_SLOTS, CHAR_TABLE_REF_ASCII, CHAR_TABLE_REF)
+	(CHAR_TABLE_TRANSLATE, CHAR_TABLE_SET, SYMBOL_VAL, SYMBOL_ALIAS)
+	(SYMBOL_BLV, SYMBOL_FWD, SET_SYMBOL_VAL, SET_SYMBOL_ALIAS)
+	(SET_SYMBOL_BLV, SET_SYMBOL_FWD, SYMBOL_NAME, SYMBOL_INTERNED_P)
+	(SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P, SYMBOL_CONSTANT_P)
+	(XHASH_TABLE, HASH_TABLE_P, CHECK_HASH_TABLE, HASH_TABLE_SIZE)
+	(XMISC, XMISCANY, XMARKER, XOVERLAY, XSAVE_VALUE, XSETMISCTYPE)
+	(BLV_FOUND, SET_BLV_FOUND, BLV_VALUE, SET_BLV_VALUE, XFWDTYPE)
+	(XINTFWD, XBOOLFWD, XOBJFWD, XBUFFER_OBJFWD, XKBOARD_OBJFWD)
+	(XFLOAT_DATA, XFLOAT_INIT, NILP, NUMBERP, NATNUMP)
+	(RANGED_INTEGERP, CONSP, FLOATP, MISCP, STRINGP, SYMBOLP)
+	(INTEGERP, VECTORLIKEP, VECTORP, OVERLAYP)
+	(MARKERP, SAVE_VALUEP, INTFWDP, BOOLFWDP, OBJFWDP)
+	(BUFFER_OBJFWDP, KBOARD_OBJFWDP, PSEUDOVECTOR_SIZE_TYPEP)
+	(PSEUDOVECTORP, WINDOW_CONFIGURATIONP, PROCESSP, WINDOWP)
+	(TERMINALP, SUBRP, COMPILEDP, BUFFERP, CHAR_TABLE_P)
+	(SUB_CHAR_TABLE_P, BOOL_VECTOR_P, FRAMEP, IMAGEP, ARRAYP)
+	(CHECK_LIST, CHECK_LIST_CONS, CHECK_LIST_END, CHECK_STRING)
+	(CHECK_STRING_CAR, CHECK_CONS, CHECK_SYMBOL, CHECK_CHAR_TABLE)
+	(CHECK_VECTOR, CHECK_VECTOR_OR_STRING, CHECK_ARRAY)
+	(CHECK_VECTOR_OR_CHAR_TABLE, CHECK_BUFFER, CHECK_WINDOW)
+	(CHECK_WINDOW_CONFIGURATION, CHECK_PROCESS, CHECK_SUBR)
+	(CHECK_NUMBER, CHECK_NATNUM, CHECK_MARKER, XFLOATINT)
+	(CHECK_FLOAT, CHECK_NUMBER_OR_FLOAT, CHECK_OVERLAY)
+	(CHECK_NUMBER_CAR, CHECK_NUMBER_CDR, CHECK_NATNUM_CAR)
+	(CHECK_NATNUM_CDR, FUNCTIONP, SPECPDL_INDEX, LOADHIST_ATTACH)
+	(IS_DIRECTORY_SEP, IS_DEVICE_SEP, IS_ANY_SEP):
+	Now static inline functions, not macros.
+	(check_cons_list) [!GC_CHECK_CONS_LIST]: New empty function.
+	(EMACS_INT, EMACS_UINT): Now typedefs, not macros.
+	(VALBITS, INTTYPEBITS, FIXNUM_BITS, LISP_INT_TAG)
+	(PSEUDOVECTOR_SIZE_BITS, PSEUDOVECTOR_SIZE_MASK, PVEC_TYPE_MASK)
+	(BOOL_VECTOR_BITS_PER_CHAR, CHAR_TABLE_STANDARD_SLOTS)
+	(CHARTAB_SIZE_BITS_0, CHARTAB_SIZE_BITS_1)
+	(CHARTAB_SIZE_BITS_2, CHARTAB_SIZE_BITS_3, DEFAULT_HASH_SIZE)
+	(COMPILED_ARGLIST, COMPILED_BYTECODE, COMPILED_CONSTANTS)
+	(COMPILED_STACK_DEPTH, COMPILED_DOC_STRING, COMPILED_INTERACTIVE)
+	(CHAR_ALT, CHAR_SUPER, CHAR_HYPER, CHAR_SHIFT, CHAR_CTL, CHAR_META)
+	(CHAR_MODIFIER_MASK, MANY, UNEVALLED, FLOAT_TO_STRING_BUFSIZE):
+	(DIRECTORY_SEP, MAX_ALLOCA):
+	Now constants, not macros.
+	(LISP_INT1_TAG, LISP_STRING_TAG, LISP_MAKE_RVALUE, TYPEMASK):
+	Remove; no longer needed.
+	(DATA_SEG_BITS): Default to 0, as this simplifies the rest of the code.
+	(VALMASK): Define in one place rather than in two, merging the
+	USE_LSB_TAG parts; this is simpler.
+	(MOST_POSITIVE_FIXNUM, MOST_NEGATIVE_FIXNUM, max, min)
+	(struct Lisp_String, UNSIGNED_CMP, ASCII_CHAR_P):
+	Move up, to avoid use before definition.
+	Also include "globals.h" earlier, for the same reason.
+	(make_natnum, xtag): New functions.
+	(XUNTAG): Now returns void *, not intptr_t, as this means fewer casts.
+	(union Lisp_Fwd, BOOLFWDP, BOOL_VECTOR_P, BUFFER_OBJFWDP, BUFFERP)
+	(CHAR_TABLE_P, CHAR_TABLE_REF_ASCII, CONSP, FLOATP, INTEGERP, INTFWDP)
+	(KBOARD_OBJFWDP, MARKERP, MISCP, NILP, OBJFWDP, OVERLAYP, PROCESSP)
+	(PSEUDOVECTORP, SAVE_VALUEP, STRINGP, SUB_CHAR_TABLE_P, SUBRP, SYMBOLP)
+	(VECTORLIKEP, WINDOWP, Qoverlayp, char_table_ref, char_table_set)
+	(char_table_translate, Qarrayp, Qbufferp, Qbuffer_or_string_p)
+	(Qchar_table_p, Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp)
+	(Qnil, Qnumberp, Qsubrp, Qstringp, Qsymbolp, Qvectorp)
+	(Qvector_or_char_table_p, Qwholenump, Ffboundp, wrong_type_argument)
+	(initialized, Qhash_table_p, extract_float, Qprocessp, Qwindowp)
+	(Qwindow_configuration_p, Qimage): New forward declarations.
+	(XSET): Simplify by rewriting in terms of xtag.
+	(XSETFASTINT): Simplify by rewriting in terms of make_natnum.
+	(STRING_COPYIN): Remove; unused.
+	(GLYPH, GLYPH_CHAR, GLYPH_FACE, SET_GLYPH_CHAR, SET_GLYPH_FACE)
+	(SET_GLYPH, GLYPH_CODE_CHAR, GLYPH_CODE_FACE)
+	(SET_GLYPH_FROM_GLYPH_CODE, GLYPH_MODE_LINE_FACE, GLYPH_CHAR_VALID_P)
+	(GLYPH_CODE_P): Move to dispextern.h, to avoid define-before-use.
+	(TYPE_RANGED_INTEGERP): Simplify.
+	(PSEUDOVECTOR_SIZE_TYPEP): Rename from PSEUDOVECTORP_TYPEP and
+	change the first arg to be a size rather than a pointer,
+	to make it usable as a function.  All uses changed.
+	(Qsubrp, Qhash_table_p, Qoverlayp): New extern decls.
+	(setlocale, fixup_locale, synchronize_system_messages_locale)
+	(synchronize_system_time_locale) [!HAVE_SETLOCALE]:
+	Now empty functions, not macros.
+	* mem-limits.h (EXCEEDS_LISP_PTR) [!defined DATA_SEG_BITS]:
+	Remove, as DATA_SEG_BITS is always defined now, if only to zero.
+	* window.c (Qwindow_configuration_p):
+	Now extern, so window.h can use it.
+	* window.h (Qwindowp): Move decl back to lisp.h.
+	(CHECK_LIVE_WINDOW): Move here from lisp.h, so window.h internals
+	need not be moved to lisp.h.  Now a function, not a macro.
+
 2012-07-13  Kalle Kankare <kalle.kankare <at> iki.fi> (tiny change)
 
 	* image.c (Fimagemagick_types): Initialize ex with GetExceptionInfo

=== modified file 'src/alloc.c'
--- src/alloc.c	2012-07-11 06:14:27 +0000
+++ src/alloc.c	2012-07-13 03:37:42 +0000
@@ -3077,12 +3077,12 @@
    + VECTOR_BLOCK_BYTES - VBLOCK_BYTES_MIN)
 
 /* Number of bytes used by vector-block-allocated object.  This is the only
-   place where we actually use the `nbytes' field of the vector-header.
-   I.e. we could get rid of the `nbytes' field by computing it based on the
+   place where we actually use the 'size' field of the vector-header.
+   I.e. we could get rid of the 'size' field by computing it based on the
    vector-type.  */
 
 #define PSEUDOVECTOR_NBYTES(vector) \
-  (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FREE)	\
+  (PSEUDOVECTOR_SIZE_TYPEP (vector->header.size, PVEC_FREE)	\
    ? vector->header.size & PSEUDOVECTOR_SIZE_MASK	\
    : vector->header.next.nbytes)
 
@@ -4382,7 +4382,7 @@
       while (VECTOR_IN_BLOCK (vector, block)
 	     && vector <= (struct Lisp_Vector *) p)
 	{
-	  if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FREE))
+	  if (PSEUDOVECTOR_SIZE_TYPEP (vector->header.size, PVEC_FREE))
 	    vector = ADVANCE (vector, (vector->header.size
 				       & PSEUDOVECTOR_SIZE_MASK));
 	  else if (vector == p)

=== modified file 'src/buffer.c'
--- src/buffer.c	2012-07-10 23:24:36 +0000
+++ src/buffer.c	2012-07-13 03:37:42 +0000
@@ -139,7 +139,7 @@
 
 static Lisp_Object Qget_file_buffer;
 
-static Lisp_Object Qoverlayp;
+Lisp_Object Qoverlayp;
 
 Lisp_Object Qpriority, Qbefore_string, Qafter_string;
 
@@ -612,7 +612,7 @@
       eassert (NILP (BVAR (b->base_buffer, begv_marker)));
       eassert (NILP (BVAR (b->base_buffer, zv_marker)));
 
-      BVAR (b->base_buffer, pt_marker) 
+      BVAR (b->base_buffer, pt_marker)
 	= build_marker (b->base_buffer, b->base_buffer->pt, b->base_buffer->pt_byte);
 
       BVAR (b->base_buffer, begv_marker)
@@ -862,7 +862,7 @@
     {
       /* Note fileio.c:make_temp_name does random differently.  */
       tem2 = concat2 (name, make_formatted_string
-		      (number, "-%"pI"d", 
+		      (number, "-%"pI"d",
 		       XFASTINT (Frandom (make_number (999999)))));
       tem = Fget_buffer (tem2);
       if (NILP (tem))

=== modified file 'src/data.c'
--- src/data.c	2012-07-10 08:43:46 +0000
+++ src/data.c	2012-07-13 14:51:32 +0000
@@ -91,7 +91,8 @@
 static Lisp_Object Qcompiled_function, Qframe, Qvector;
 Lisp_Object Qbuffer;
 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
-static Lisp_Object Qsubrp, Qmany, Qunevalled;
+Lisp_Object Qsubrp;
+static Lisp_Object Qmany, Qunevalled;
 Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
 static Lisp_Object Qdefun;
 

=== modified file 'src/dispextern.h'
--- src/dispextern.h	2012-07-13 03:50:58 +0000
+++ src/dispextern.h	2012-07-13 03:52:53 +0000
@@ -22,6 +22,8 @@
 #ifndef DISPEXTERN_H_INCLUDED
 #define DISPEXTERN_H_INCLUDED
 
+#include "character.h"
+
 #ifdef HAVE_X_WINDOWS
 
 #include <X11/Xlib.h>
@@ -265,6 +267,55 @@
 				Glyphs
  ***********************************************************************/
 
+/* The glyph datatype, used to represent characters on the display.
+   It consists of a char code and a face id.  */
+
+typedef struct {
+  int ch;
+  int face_id;
+} GLYPH;
+
+/* Return a glyph's character code.  */
+static inline int GLYPH_CHAR (GLYPH glyph) { return glyph.ch; }
+
+/* Return a glyph's face ID.  */
+static inline int GLYPH_FACE (GLYPH glyph) { return glyph.face_id; }
+
+#define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
+#define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
+#define SET_GLYPH(glyph, char, face) \
+  ((glyph).ch = (char), (glyph).face_id = (face))
+
+/* The following are valid only if GLYPH_CODE_P (gc).  */
+
+static inline int
+GLYPH_CODE_CHAR (Lisp_Object gc)
+{
+  return (CONSP (gc)
+	  ? XINT (XCAR (gc))
+	  : XINT (gc) & MAX_CHAR);
+}
+
+static inline int
+GLYPH_CODE_FACE (Lisp_Object gc)
+{
+  return CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS;
+}
+
+#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc)				\
+  do									\
+    {									\
+      if (CONSP (gc))							\
+	SET_GLYPH (glyph, XINT (XCAR (gc)), XINT (XCDR (gc)));		\
+      else								\
+	SET_GLYPH (glyph, (XINT (gc) & ((1 << CHARACTERBITS)-1)),	\
+		   (XINT (gc) >> CHARACTERBITS));			\
+    }									\
+  while (0)
+
+/* The ID of the mode line highlighting face.  */
+enum { GLYPH_MODE_LINE_FACE = 1 };
+
 /* Enumeration of glyph types.  Glyph structures contain a type field
    containing one of the enumerators defined here.  */
 
@@ -1763,6 +1814,30 @@
 
 #endif /* not HAVE_WINDOW_SYSTEM */
 
+/* Return 1 if G contains a valid character code.  */
+static inline int
+GLYPH_CHAR_VALID_P (GLYPH g)
+{
+  return CHAR_VALID_P (GLYPH_CHAR (g));
+}
+
+/* The glyph code from a display vector may either be an integer which
+   encodes a char code in the lower CHARACTERBITS bits and a (very small)
+   face-id in the upper bits, or it may be a cons (CHAR . FACE-ID).  */
+
+static inline int
+GLYPH_CODE_P (Lisp_Object gc)
+{
+  return (CONSP (gc)
+	  ? (CHARACTERP (XCAR (gc))
+	     && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID))
+	  : (RANGED_INTEGERP
+	     (0, gc,
+	      (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS
+	       ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR
+	       : TYPE_MAXIMUM (EMACS_INT)))));
+}
+
 /* Non-zero means face attributes have been changed since the last
    redisplay.  Used in redisplay_internal.  */
 

=== modified file 'src/eval.c'
--- src/eval.c	2012-07-10 16:53:26 +0000
+++ src/eval.c	2012-07-13 03:37:42 +0000
@@ -1931,7 +1931,7 @@
        and assumed the docstring will be provided by Snarf-documentation, so it
        passed us 0 instead.  But that leads to accidental sharing in purecopy's
        hash-consing, so we use a (hopefully) unique integer instead.  */
-    docstring = make_number (XUNTAG (function, Lisp_Symbol));
+    docstring = make_number ((intptr_t) XUNTAG (function, Lisp_Symbol));
   return Ffset (function,
 		Fpurecopy (list5 (Qautoload, file, docstring,
 				  interactive, type)));

=== modified file 'src/fns.c'
--- src/fns.c	2012-07-10 23:24:36 +0000
+++ src/fns.c	2012-07-13 03:37:42 +0000
@@ -3354,7 +3354,8 @@
 
 /* Various symbols.  */
 
-static Lisp_Object Qhash_table_p, Qkey, Qvalue;
+Lisp_Object Qhash_table_p;
+static Lisp_Object Qkey, Qvalue;
 Lisp_Object Qeq, Qeql, Qequal;
 Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness;
 static Lisp_Object Qhash_table_test, Qkey_or_value, Qkey_and_value;

=== modified file 'src/lisp.h'
--- src/lisp.h	2012-07-12 23:56:39 +0000
+++ src/lisp.h	2012-07-13 03:38:40 +0000
@@ -32,10 +32,10 @@
 
 #ifdef GC_CHECK_CONS_LIST
 extern void check_cons_list (void);
-#define CHECK_CONS_LIST() check_cons_list ()
 #else
-#define CHECK_CONS_LIST() ((void) 0)
+static inline void check_cons_list (void) { }
 #endif
+static inline void CHECK_CONS_LIST (void) { check_cons_list (); }
 
 /* Temporarily disable wider-than-pointer integers until they're tested more.
    Build with CFLAGS='-DWIDE_EMACS_INT' to try them out.  */
@@ -45,22 +45,24 @@
    EMACS_INT_MAX - maximum value of EMACS_INT; can be used in #if
    pI - printf length modifier for EMACS_INT
    EMACS_UINT - unsigned variant of EMACS_INT */
-#ifndef EMACS_INT
+#ifndef EMACS_INT_MAX
 # if LONG_MAX < LLONG_MAX && defined WIDE_EMACS_INT
-#  define EMACS_INT long long
+typedef long long int EMACS_INT;
+typedef unsigned long long int EMACS_UINT;
 #  define EMACS_INT_MAX LLONG_MAX
 #  define pI "ll"
 # elif INT_MAX < LONG_MAX
-#  define EMACS_INT long
+typedef long int EMACS_INT;
+typedef unsigned long int EMACS_UINT;
 #  define EMACS_INT_MAX LONG_MAX
 #  define pI "l"
 # else
-#  define EMACS_INT int
+typedef int EMACS_INT;
+typedef unsigned int EMACS_UINT;
 #  define EMACS_INT_MAX INT_MAX
 #  define pI ""
 # endif
 #endif
-#define EMACS_UINT unsigned EMACS_INT
 
 /* Number of bits in some machine integer types.  */
 enum
@@ -153,8 +155,10 @@
    variable VAR of type TYPE with the added requirement that it be
    TYPEBITS-aligned.  */
 
+/* Number of bits in a Lisp_Obect tag.  This can be used in #if.  */
 #define GCTYPEBITS 3
-#define VALBITS (BITS_PER_EMACS_INT - GCTYPEBITS)
+
+enum { VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS };
 
 /* The maximum value that can be stored in a EMACS_INT, assuming all
    bits other than the type bits contribute to a nonnegative signed value.
@@ -216,14 +220,10 @@
 
 /* Lisp integers use 2 tags, to give them one extra bit, thus
    extending their range from, e.g., -2^28..2^28-1 to -2^29..2^29-1.  */
-#define INTTYPEBITS (GCTYPEBITS - 1)
-#define FIXNUM_BITS (VALBITS + 1)
+enum { INTTYPEBITS = GCTYPEBITS - 1 };
+enum { FIXNUM_BITS = VALBITS + 1 };
 #define INTMASK (EMACS_INT_MAX >> (INTTYPEBITS - 1))
-#define LISP_INT_TAG Lisp_Int0
 #define case_Lisp_Int case Lisp_Int0: case Lisp_Int1
-#define LISP_INT1_TAG (USE_LSB_TAG ? 1 << INTTYPEBITS : 1)
-#define LISP_STRING_TAG (5 - LISP_INT1_TAG)
-#define LISP_INT_TAG_P(x) (((x) & ~LISP_INT1_TAG) == 0)
 
 /* Stolen from GDB.  The only known compiler that doesn't support
    enums in bitfields is MSVC.  */
@@ -238,7 +238,7 @@
   {
     /* Integer.  XINT (obj) is the integer value.  */
     Lisp_Int0 = 0,
-    Lisp_Int1 = LISP_INT1_TAG,
+    Lisp_Int1 = USE_LSB_TAG ? 4 : 1,
 
     /* Symbol.  XSYMBOL (object) points to a struct Lisp_Symbol.  */
     Lisp_Symbol = 2,
@@ -249,7 +249,7 @@
 
     /* String.  XSTRING (object) points to a struct Lisp_String.
        The length of the string, and its contents, are stored therein.  */
-    Lisp_String = LISP_STRING_TAG,
+    Lisp_String = USE_LSB_TAG ? 1 : 4,
 
     /* Vector of Lisp objects, or something resembling it.
        XVECTOR (object) points to a struct Lisp_Vector, which contains
@@ -263,6 +263,11 @@
     Lisp_Float = 7,
   };
 
+/* An older name for Lisp_Int0.  */
+enum { LISP_INT_TAG = Lisp_Int0 };
+
+static inline int LISP_INT_TAG_P (int x) { return (x & ~Lisp_Int1) == 0; }
+
 /* This is the set of data types that share a common structure.
    The first member of the structure is a type code from this set.
    The enum values are arbitrary, but we'll use large numbers to make it
@@ -297,7 +302,8 @@
 
 typedef struct { EMACS_INT i; } Lisp_Object;
 
-#define XLI(o) (o).i
+static inline EMACS_INT XLI (Lisp_Object o) { return o.i; }
+
 static inline Lisp_Object
 XIL (EMACS_INT i)
 {
@@ -305,12 +311,6 @@
   return o;
 }
 
-static inline Lisp_Object
-LISP_MAKE_RVALUE (Lisp_Object o)
-{
-    return o;
-}
-
 #define LISP_INITIALLY_ZERO {0}
 
 #else /* CHECK_LISP_OBJECT_TYPE */
@@ -318,9 +318,8 @@
 /* If a struct type is not wanted, define Lisp_Object as just a number.  */
 
 typedef EMACS_INT Lisp_Object;
-#define XLI(o) (o)
-#define XIL(i) (i)
-#define LISP_MAKE_RVALUE(o) (0+(o))
+static inline EMACS_INT XLI (Lisp_Object o) { return o; }
+static inline Lisp_Object XIL (EMACS_INT i) { return i; }
 #define LISP_INITIALLY_ZERO 0
 #endif /* CHECK_LISP_OBJECT_TYPE */
 
@@ -368,89 +367,119 @@
    only the number of Lisp_Object fields (that need to be traced by the GC).
    The distinction is used e.g. by Lisp_Process which places extra
    non-Lisp_Object fields at the end of the structure.  */
-#define PSEUDOVECTOR_SIZE_BITS 16
-#define PSEUDOVECTOR_SIZE_MASK ((1 << PSEUDOVECTOR_SIZE_BITS) - 1)
-#define PVEC_TYPE_MASK (0x0fff << PSEUDOVECTOR_SIZE_BITS)
+enum
+  {
+    PSEUDOVECTOR_SIZE_BITS = 16,
+    PSEUDOVECTOR_SIZE_MASK = (1 << PSEUDOVECTOR_SIZE_BITS) - 1,
+    PVEC_TYPE_MASK = 0xfff << PSEUDOVECTOR_SIZE_BITS
+  };
 
 /* Number of bits to put in each character in the internal representation
    of bool vectors.  This should not vary across implementations.  */
-#define BOOL_VECTOR_BITS_PER_CHAR 8
-
-/* These macros extract various sorts of values from a Lisp_Object.
+enum { BOOL_VECTOR_BITS_PER_CHAR = 8 };
+
+/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
+   which were stored in a Lisp_Object */
+#ifndef DATA_SEG_BITS
+# define DATA_SEG_BITS 0
+#endif
+
+/* These functions extract various sorts of values from a Lisp_Object.
  For example, if tem is a Lisp_Object whose type is Lisp_Cons,
  XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons.  */
 
 /* Return a perfect hash of the Lisp_Object representation.  */
-#define XHASH(a) XLI (a)
-
-#if USE_LSB_TAG
-
-#define TYPEMASK ((1 << GCTYPEBITS) - 1)
-#define XTYPE(a) ((enum Lisp_Type) (XLI (a) & TYPEMASK))
-#define XINT(a) (XLI (a) >> INTTYPEBITS)
-#define XUINT(a) ((EMACS_UINT) XLI (a) >> INTTYPEBITS)
-#define make_number(N) XIL ((EMACS_INT) (N) << INTTYPEBITS)
-#define XSET(var, type, ptr)						   \
-  (eassert (XTYPE (XIL ((intptr_t) (ptr))) == 0), /* Check alignment.  */  \
-   (var) = XIL ((type) | (intptr_t) (ptr)))
-
-#define XPNTR(a) ((intptr_t) (XLI (a) & ~TYPEMASK))
-#define XUNTAG(a, type) ((intptr_t) (XLI (a) - (type)))
-
-#else  /* not USE_LSB_TAG */
-
-#define VALMASK VAL_MAX
-
-#define XTYPE(a) ((enum Lisp_Type) ((EMACS_UINT) XLI (a) >> VALBITS))
-
-/* For integers known to be positive, XFASTINT provides fast retrieval
-   and XSETFASTINT provides fast storage.  This takes advantage of the
-   fact that Lisp integers have zero-bits in their tags.  */
-#define XFASTINT(a) (XLI (a) + 0)
-#define XSETFASTINT(a, b) ((a) = XIL (b))
-
-/* Extract the value of a Lisp_Object as a (un)signed integer.  */
-
-#define XINT(a) (XLI (a) << INTTYPEBITS >> INTTYPEBITS)
-#define XUINT(a) ((EMACS_UINT) (XLI (a) & INTMASK))
-#define make_number(N) XIL ((EMACS_INT) (N) & INTMASK)
-
-#define XSET(var, type, ptr)				      \
-  ((var) = XIL ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS)  \
-		+ ((intptr_t) (ptr) & VALMASK)))
-
-#ifdef DATA_SEG_BITS
-/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
-   which were stored in a Lisp_Object */
-#define XPNTR(a) ((uintptr_t) ((XLI (a) & VALMASK)) | DATA_SEG_BITS))
-#else
-#define XPNTR(a) ((uintptr_t) (XLI (a) & VALMASK))
-#endif
-
-#endif /* not USE_LSB_TAG */
-
-/* For integers known to be positive, XFASTINT sometimes provides
-   faster retrieval and XSETFASTINT provides faster storage.
-   If not, fallback on the non-accelerated path.  */
-#ifndef XFASTINT
-# define XFASTINT(a) (XINT (a))
-# define XSETFASTINT(a, b) (XSETINT (a, b))
-#endif
-
-/* Extract the pointer value of the Lisp object A, under the
-   assumption that A's type is TYPE.  This is a fallback
-   implementation if nothing faster is available.  */
-#ifndef XUNTAG
-# define XUNTAG(a, type) XPNTR (a)
-#endif
-
-#define EQ(x, y) (XHASH (x) == XHASH (y))
+static inline EMACS_INT XHASH (Lisp_Object o) { return XLI (o); }
+
+#define VALMASK (USE_LSB_TAG ? - (1 << GCTYPEBITS) : VAL_MAX)
 
 /* Largest and smallest representable fixnum values.  These are the C
    values.  */
 #define MOST_POSITIVE_FIXNUM (EMACS_INT_MAX >> INTTYPEBITS)
 #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM)
 
+static inline enum Lisp_Type
+XTYPE (Lisp_Object a)
+{
+  EMACS_UINT i = XLI (a);
+  return USE_LSB_TAG ? i & ~VALMASK : i >> VALBITS;
+}
+
+/* Extract the value of a Lisp_Object as a signed integer.  */
+static inline EMACS_INT
+XINT (Lisp_Object a)
+{
+  EMACS_INT i = XLI (a);
+  return (USE_LSB_TAG ? i : i << INTTYPEBITS) >> INTTYPEBITS;
+}
+
+/* Like XINT (A), but may be faster.  A must be nonnegative.  This takes
+   advantage of the fact that Lisp integers have zero-bits in their tags.  */
+static inline EMACS_INT
+XFASTINT (Lisp_Object a)
+{
+  EMACS_INT n = USE_LSB_TAG ? XINT (a) : XLI (a) >> INTTYPEBITS;
+  eassert (0 <= n);
+  return n;
+}
+
+/* Extract the value of a Lisp_Object as an unsigned integer.  */
+static inline EMACS_UINT
+XUINT (Lisp_Object a)
+{
+  EMACS_UINT i = XLI (a);
+  return USE_LSB_TAG ? i >> INTTYPEBITS : i & INTMASK;
+}
+
+static inline Lisp_Object
+make_number (EMACS_INT n)
+{
+  return XIL (USE_LSB_TAG ? n << INTTYPEBITS : n & INTMASK);
+}
+
+/* Like make_number (N), but may be faster.  N must be in nonnegative range.  */
+static inline Lisp_Object
+make_natnum (EMACS_INT n)
+{
+  eassert (0 <= n && n <= MOST_POSITIVE_FIXNUM);
+  return USE_LSB_TAG ? make_number (n) : XIL (n);
+}
+
+static inline void *
+XPNTR (Lisp_Object a)
+{
+  intptr_t i = (XLI (a) & VALMASK) | DATA_SEG_BITS;
+  return (void *) i;
+}
+
+/* Extract the pointer value of the Lisp object A, under the
+   assumption that A's type is TYPE.  */
+static inline void *
+XUNTAG (Lisp_Object a, int type)
+{
+  if (USE_LSB_TAG)
+    {
+      intptr_t i = XLI (a) - type;
+      return (void *) i;
+    }
+  return XPNTR (a);
+}
+
+static inline int
+EQ (Lisp_Object a, Lisp_Object b)
+{
+  return XHASH (a) == XHASH (b);
+}
+
+/* The ubiquitous min and max macros.  */
+
+#ifdef max
+#undef max
+#undef min
+#endif
+#define min(a, b)	((a) < (b) ? (a) : (b))
+#define max(a, b)	((a) > (b) ? (a) : (b))
+
 /* Value is non-zero if I doesn't fit into a Lisp fixnum.  It is
    written this way so that it also works if I is of unsigned
    type or if I is a NaN.  */
@@ -463,64 +492,181 @@
 {
   return num < lower ? lower : num <= upper ? num : upper;
 }
+
+/* Forward declarations.  */
+
+/* Defined in this file.  */
+union Lisp_Fwd;
+static int BOOLFWDP (union Lisp_Fwd *);
+static int BOOL_VECTOR_P (Lisp_Object);
+static int BUFFER_OBJFWDP (union Lisp_Fwd *);
+static int BUFFERP (Lisp_Object);
+static int CHAR_TABLE_P (Lisp_Object);
+static Lisp_Object CHAR_TABLE_REF_ASCII (Lisp_Object, ptrdiff_t);
+static int CONSP (Lisp_Object);
+static int FLOATP (Lisp_Object);
+static int INTEGERP (Lisp_Object);
+static int INTFWDP (union Lisp_Fwd *);
+static int KBOARD_OBJFWDP (union Lisp_Fwd *);
+static int MARKERP (Lisp_Object);
+static int MISCP (Lisp_Object);
+static int NILP (Lisp_Object);
+static int OBJFWDP (union Lisp_Fwd *);
+static int OVERLAYP (Lisp_Object);
+static int PROCESSP (Lisp_Object);
+static int PSEUDOVECTORP (Lisp_Object, int);
+static int SAVE_VALUEP (Lisp_Object);
+static int STRINGP (Lisp_Object);
+static int SUB_CHAR_TABLE_P (Lisp_Object);
+static int SUBRP (Lisp_Object);
+static int SYMBOLP (Lisp_Object);
+static int VECTORLIKEP (Lisp_Object);
+static int WINDOWP (Lisp_Object);
+
+/* Defined in buffer.c.  */
+extern Lisp_Object Qoverlayp;
+
+/* Defined in chartab.c.  */
+extern Lisp_Object char_table_ref (Lisp_Object, int);
+extern Lisp_Object char_table_set (Lisp_Object, int, Lisp_Object);
+extern int char_table_translate (Lisp_Object, int);
+
+/* Defined in data.c.  */
+extern Lisp_Object Qarrayp, Qbufferp, Qbuffer_or_string_p, Qchar_table_p;
+extern Lisp_Object Qconsp, Qfloatp, Qintegerp, Qlambda, Qlistp, Qmarkerp, Qnil;
+extern Lisp_Object Qnumberp, Qsubrp, Qstringp, Qsymbolp, Qvectorp;
+extern Lisp_Object Qvector_or_char_table_p, Qwholenump;
+extern Lisp_Object Ffboundp (Lisp_Object);
+extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object);
+
+/* Defined in emacs.c.  */
+extern int initialized;
+
+/* Defined in fns.c  */
+extern Lisp_Object Qhash_table_p;
+
+/* Defined in floatfns.c.  */
+extern double extract_float (Lisp_Object);
+
+/* Defined in process.c.  */
+extern Lisp_Object Qprocessp;
+
+/* Defined in window.c.  */
+extern Lisp_Object Qwindowp, Qwindow_configuration_p;
+
+/* Defined in xdisp.c.  */
+extern Lisp_Object Qimage;
+
 
 /* Extract a value or address from a Lisp_Object.  */
 
-#define XCONS(a)   (eassert (CONSP (a)), \
-		    (struct Lisp_Cons *) XUNTAG (a, Lisp_Cons))
-#define XVECTOR(a) (eassert (VECTORLIKEP (a)), \
-		    (struct Lisp_Vector *) XUNTAG (a, Lisp_Vectorlike))
-#define XSTRING(a) (eassert (STRINGP (a)), \
-		    (struct Lisp_String *) XUNTAG (a, Lisp_String))
-#define XSYMBOL(a) (eassert (SYMBOLP (a)), \
-		    (struct Lisp_Symbol *) XUNTAG (a, Lisp_Symbol))
-#define XFLOAT(a)  (eassert (FLOATP (a)), \
-		    (struct Lisp_Float *) XUNTAG (a, Lisp_Float))
-
-/* Misc types.  */
-
-#define XMISC(a)	((union Lisp_Misc *) XUNTAG (a, Lisp_Misc))
-#define XMISCANY(a)	(eassert (MISCP (a)), &(XMISC (a)->u_any))
-#define XMISCTYPE(a)   (XMISCANY (a)->type)
-#define XMARKER(a)	(eassert (MARKERP (a)), &(XMISC (a)->u_marker))
-#define XOVERLAY(a)	(eassert (OVERLAYP (a)), &(XMISC (a)->u_overlay))
-#define XSAVE_VALUE(a)	(eassert (SAVE_VALUEP (a)), &(XMISC (a)->u_save_value))
-
-/* Forwarding object types.  */
-
-#define XFWDTYPE(a)     (a->u_intfwd.type)
-#define XINTFWD(a)	(eassert (INTFWDP (a)), &((a)->u_intfwd))
-#define XBOOLFWD(a)	(eassert (BOOLFWDP (a)), &((a)->u_boolfwd))
-#define XOBJFWD(a)	(eassert (OBJFWDP (a)), &((a)->u_objfwd))
-#define XBUFFER_OBJFWD(a) \
-  (eassert (BUFFER_OBJFWDP (a)), &((a)->u_buffer_objfwd))
-#define XKBOARD_OBJFWD(a) \
-  (eassert (KBOARD_OBJFWDP (a)), &((a)->u_kboard_objfwd))
+static inline struct Lisp_Cons *
+XCONS (Lisp_Object a)
+{
+  eassert (CONSP (a));
+  return XUNTAG (a, Lisp_Cons);
+}
+
+static inline struct Lisp_Vector *
+XVECTOR (Lisp_Object a)
+{
+  eassert (VECTORLIKEP (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct Lisp_String *
+XSTRING (Lisp_Object a)
+{
+  eassert (STRINGP (a));
+  return XUNTAG (a, Lisp_String);
+}
+
+static inline struct Lisp_Symbol *
+XSYMBOL (Lisp_Object a)
+{
+  eassert (SYMBOLP (a));
+  return XUNTAG (a, Lisp_Symbol);
+}
+
+static inline struct Lisp_Float *
+XFLOAT (Lisp_Object a)
+{
+  eassert (FLOATP (a));
+  return XUNTAG (a, Lisp_Float);
+}
 
 /* Pseudovector types.  */
 
-#define XPROCESS(a) (eassert (PROCESSP (a)), \
-		     (struct Lisp_Process *) XUNTAG (a, Lisp_Vectorlike))
-#define XWINDOW(a) (eassert (WINDOWP (a)), \
-		    (struct window *) XUNTAG (a, Lisp_Vectorlike))
-#define XTERMINAL(a) (eassert (TERMINALP (a)), \
-		      (struct terminal *) XUNTAG (a, Lisp_Vectorlike))
-#define XSUBR(a) (eassert (SUBRP (a)), \
-		  (struct Lisp_Subr *) XUNTAG (a, Lisp_Vectorlike))
-#define XBUFFER(a) (eassert (BUFFERP (a)), \
-		    (struct buffer *) XUNTAG (a, Lisp_Vectorlike))
-#define XCHAR_TABLE(a) (eassert (CHAR_TABLE_P (a)), \
-			(struct Lisp_Char_Table *) XUNTAG (a, Lisp_Vectorlike))
-#define XSUB_CHAR_TABLE(a) (eassert (SUB_CHAR_TABLE_P (a)), \
-			    ((struct Lisp_Sub_Char_Table *) \
-			     XUNTAG (a, Lisp_Vectorlike)))
-#define XBOOL_VECTOR(a) (eassert (BOOL_VECTOR_P (a)), \
-			 ((struct Lisp_Bool_Vector *) \
-			  XUNTAG (a, Lisp_Vectorlike)))
+static inline struct Lisp_Process *
+XPROCESS (Lisp_Object a)
+{
+  eassert (PROCESSP (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct window *
+XWINDOW (Lisp_Object a)
+{
+  eassert (WINDOWP (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct terminal *
+XTERMINAL (Lisp_Object a)
+{
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct Lisp_Subr *
+XSUBR (Lisp_Object a)
+{
+  eassert (SUBRP (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct buffer *
+XBUFFER (Lisp_Object a)
+{
+  eassert (BUFFERP (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct Lisp_Char_Table *
+XCHAR_TABLE (Lisp_Object a)
+{
+  eassert (CHAR_TABLE_P (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct Lisp_Sub_Char_Table *
+XSUB_CHAR_TABLE (Lisp_Object a)
+{
+  eassert (SUB_CHAR_TABLE_P (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
+
+static inline struct Lisp_Bool_Vector *
+XBOOL_VECTOR (Lisp_Object a)
+{
+  eassert (BOOL_VECTOR_P (a));
+  return XUNTAG (a, Lisp_Vectorlike);
+}
 
 /* Construct a Lisp_Object from a value or address.  */
 
+static inline Lisp_Object
+xtag (enum Lisp_Type type, void *ptr)
+{
+  EMACS_UINT utype = type;
+  EMACS_INT typebits = USE_LSB_TAG ? type : utype << VALBITS;
+  Lisp_Object a = XIL (typebits | (intptr_t) ptr);
+  eassert (XUNTAG (a, type) == ptr);  /* Check alignment.  */
+  return a;
+}
+
+#define XSET(var, type, ptr) ((var) = xtag (type, ptr))
 #define XSETINT(a, b) (a) = make_number (b)
+#define XSETFASTINT(a, b) ((a) = make_natnum (b))
 #define XSETCONS(a, b) XSET (a, Lisp_Cons, b)
 #define XSETVECTOR(a, b) XSET (a, Lisp_Vectorlike, b)
 #define XSETSTRING(a, b) XSET (a, Lisp_String, b)
@@ -568,48 +714,25 @@
 #define XSETBOOL_VECTOR(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_BOOL_VECTOR))
 #define XSETSUB_CHAR_TABLE(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_SUB_CHAR_TABLE))
 
-/* Convenience macros for dealing with Lisp arrays.  */
-
-#define AREF(ARRAY, IDX)	XVECTOR ((ARRAY))->contents[IDX]
-#define ASIZE(ARRAY)		XVECTOR ((ARRAY))->header.size
-/* The IDX==IDX tries to detect when the macro argument is side-effecting.  */
-#define ASET(ARRAY, IDX, VAL)	\
-  (eassert ((IDX) == (IDX)),				\
-   eassert ((IDX) >= 0 && (IDX) < ASIZE (ARRAY)),	\
-   AREF ((ARRAY), (IDX)) = (VAL))
-
-/* Convenience macros for dealing with Lisp strings.  */
-
-#define SDATA(string)		(XSTRING (string)->data + 0)
-#define SREF(string, index)	(SDATA (string)[index] + 0)
-#define SSET(string, index, new) (SDATA (string)[index] = (new))
-#define SCHARS(string)		(XSTRING (string)->size + 0)
-#define SBYTES(string)		(STRING_BYTES (XSTRING (string)) + 0)
-
-/* Avoid "differ in sign" warnings.  */
-#define SSDATA(x)  ((char *) SDATA (x))
-
-#define STRING_SET_CHARS(string, newsize) \
-    (XSTRING (string)->size = (newsize))
-
-#define STRING_COPYIN(string, index, new, count) \
-    memcpy (SDATA (string) + index, new, count)
-
 /* Type checking.  */
 
-#define CHECK_TYPE(ok, Qxxxp, x) \
-  do { if (!(ok)) wrong_type_argument (Qxxxp, (x)); } while (0)
-
-
+static inline void
+CHECK_TYPE (int ok, Lisp_Object Qxxxp, Lisp_Object x)
+{
+  if (!ok)
+    wrong_type_argument (Qxxxp, x);
+}
 
 /* See the macros in intervals.h.  */
 
 typedef struct interval *INTERVAL;
 
 /* Complain if object is not string or buffer type */
-#define CHECK_STRING_OR_BUFFER(x) \
-  CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x)
-
+static inline void
+CHECK_STRING_OR_BUFFER (Lisp_Object x)
+{
+  CHECK_TYPE (STRINGP (x) || BUFFERP (x), Qbuffer_or_string_p, x);
+}
 
 /* In a cons, the markbit of the car is the gc mark bit */
 
@@ -650,54 +773,68 @@
 #endif
 
 /* Use these from normal code.  */
-#define XCAR(c)	LISP_MAKE_RVALUE (XCAR_AS_LVALUE (c))
-#define XCDR(c) LISP_MAKE_RVALUE (XCDR_AS_LVALUE (c))
+static inline Lisp_Object XCAR (Lisp_Object c) { return XCAR_AS_LVALUE (c); }
+static inline Lisp_Object XCDR (Lisp_Object c) { return XCDR_AS_LVALUE (c); }
 
 /* Use these to set the fields of a cons cell.
 
    Note that both arguments may refer to the same object, so 'n'
-   should not be read after 'c' is first modified.  Also, neither
-   argument should be evaluated more than once; side effects are
-   especially common in the second argument.  */
-#define XSETCAR(c,n) (XCAR_AS_LVALUE (c) = (n))
-#define XSETCDR(c,n) (XCDR_AS_LVALUE (c) = (n))
-
-/* Take the car or cdr of something whose type is not known.  */
-#define CAR(c)					\
- (CONSP ((c)) ? XCAR ((c))			\
-  : NILP ((c)) ? Qnil				\
-  : wrong_type_argument (Qlistp, (c)))
-
-#define CDR(c)					\
- (CONSP ((c)) ? XCDR ((c))			\
-  : NILP ((c)) ? Qnil				\
-  : wrong_type_argument (Qlistp, (c)))
-
-/* Take the car or cdr of something whose type is not known.  */
-#define CAR_SAFE(c)				\
-  (CONSP ((c)) ? XCAR ((c)) : Qnil)
-
-#define CDR_SAFE(c)				\
-  (CONSP ((c)) ? XCDR ((c)) : Qnil)
+   should not be read after 'c' is first modified.  */
+static inline void
+XSETCAR (Lisp_Object c, Lisp_Object n)
+{
+  XCAR_AS_LVALUE (c) = n;
+}
+static inline void
+XSETCDR (Lisp_Object c, Lisp_Object n)
+{
+  XCDR_AS_LVALUE (c) = n;
+}
+
+/* Take the car or cdr of something whose type is not known.  */
+static inline Lisp_Object
+CAR (Lisp_Object c)
+{
+  return (CONSP (c) ? XCAR (c)
+	  : NILP (c) ? Qnil
+	  : wrong_type_argument (Qlistp, c));
+}
+static inline Lisp_Object
+CDR (Lisp_Object c)
+{
+  return (CONSP (c) ? XCDR (c)
+	  : NILP (c) ? Qnil
+	  : wrong_type_argument (Qlistp, c));
+}
+
+/* Take the car or cdr of something whose type is not known.  */
+static inline Lisp_Object
+CAR_SAFE (Lisp_Object c)
+{
+  return CONSP (c) ? XCAR (c) : Qnil;
+}
+static inline Lisp_Object
+CDR_SAFE (Lisp_Object c)
+{
+  return CONSP (c) ? XCDR (c) : Qnil;
+}
+
+/* In a string or vector, the sign bit of the `size' is the gc mark bit.  */
+
+struct Lisp_String
+  {
+    ptrdiff_t size;
+    ptrdiff_t size_byte;
+    INTERVAL intervals;		/* Text properties in this string.  */
+    unsigned char *data;
+  };
 
 /* Nonzero if STR is a multibyte string.  */
-#define STRING_MULTIBYTE(STR)  \
-  (XSTRING (STR)->size_byte >= 0)
-
-/* Return the length in bytes of STR.  */
-
-#ifdef GC_CHECK_STRING_BYTES
-
-struct Lisp_String;
-extern ptrdiff_t string_bytes (struct Lisp_String *);
-#define STRING_BYTES(S) string_bytes ((S))
-
-#else /* not GC_CHECK_STRING_BYTES */
-
-#define STRING_BYTES(STR)  \
-  ((STR)->size_byte < 0 ? (STR)->size : (STR)->size_byte)
-
-#endif /* not GC_CHECK_STRING_BYTES */
+static inline int
+STRING_MULTIBYTE (Lisp_Object str)
+{
+  return 0 <= XSTRING (str)->size_byte;
+}
 
 /* An upper bound on the number of bytes in a Lisp string, not
    counting the terminating null.  This a tight enough bound to
@@ -727,25 +864,72 @@
     else XSTRING (STR)->size_byte = XSTRING (STR)->size; } while (0)
 
 /* Get text properties.  */
-#define STRING_INTERVALS(STR)  (XSTRING (STR)->intervals + 0)
+static inline INTERVAL
+STRING_INTERVALS (Lisp_Object str)
+{
+  return XSTRING (str)->intervals;
+}
 
 /* Set text properties.  */
-#define STRING_SET_INTERVALS(STR, INT) (XSTRING (STR)->intervals = (INT))
-
-/* In a string or vector, the sign bit of the `size' is the gc mark bit.  */
-
-struct Lisp_String
-  {
-    ptrdiff_t size;
-    ptrdiff_t size_byte;
-    INTERVAL intervals;		/* Text properties in this string.  */
-    unsigned char *data;
-  };
+static inline void
+STRING_SET_INTERVALS (Lisp_Object str, INTERVAL intervals)
+{
+  XSTRING (str)->intervals = intervals;
+}
+
+/* Convenience functions for dealing with Lisp strings.  */
+
+static inline unsigned char *
+SDATA (Lisp_Object string)
+{
+  return XSTRING (string)->data;
+}
+static inline char *
+SSDATA (Lisp_Object string)
+{
+  /* Avoid "differ in sign" warnings.  */
+  return (char *) SDATA (string);
+}
+static inline unsigned char
+SREF (Lisp_Object string, ptrdiff_t index)
+{
+  return SDATA (string)[index];
+}
+static inline void
+SSET (Lisp_Object string, ptrdiff_t index, unsigned char new)
+{
+  SDATA (string)[index] = new;
+}
+static inline ptrdiff_t
+SCHARS (Lisp_Object string)
+{
+  return XSTRING (string)->size;
+}
+static inline ptrdiff_t
+STRING_BYTES (struct Lisp_String *s)
+{
+#ifdef GC_CHECK_STRING_BYTES
+  extern ptrdiff_t string_bytes (struct Lisp_String *);
+  return string_bytes (s);
+#else
+  return s->size_byte < 0 ? s->size : s->size_byte;
+#endif
+}
+static inline ptrdiff_t
+SBYTES (Lisp_Object string)
+{
+  return STRING_BYTES (XSTRING (string));
+}
+static inline void
+STRING_SET_CHARS (Lisp_Object string, ptrdiff_t newsize)
+{
+  XSTRING (string)->size = newsize;
+}
 
 /* Header of vector-like objects.  This documents the layout constraints on
    vectors and pseudovectors other than struct Lisp_Subr.  It also prevents
-   compilers from being fooled by Emacs's type punning: the XSETPSEUDOVECTOR
-   and PSEUDOVECTORP macros cast their pointers to struct vectorlike_header *,
+   compilers from being fooled by Emacs's type punning: XSETPSEUDOVECTOR
+   and PSEUDOVECTORP cast their pointers to struct vectorlike_header *,
    because when two such pointers potentially alias, a compiler won't
    incorrectly reorder loads and stores to their size fields.  See
    <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8546>.  */
@@ -796,6 +980,23 @@
     Lisp_Object contents[1];
   };
 
+/* Conveniences for dealing with Lisp arrays.  */
+
+/* A macro because it is also used as an lvalue.  FIXME: Use ASET instead.  */
+#define AREF(ARRAY, IDX)	XVECTOR ((ARRAY))->contents[IDX]
+
+static inline ptrdiff_t
+ASIZE (Lisp_Object array)
+{
+  return XVECTOR (array)->header.size;
+}
+
+static inline void
+ASET (Lisp_Object array, ptrdiff_t idx, Lisp_Object val)
+{
+  XVECTOR (array)->contents[idx] = val;
+}
+
 /* If a struct is made to look like a vector, this macro returns the length
    of the shortest vector that would hold that struct.  */
 #define VECSIZE(type) ((sizeof (type)					  \
@@ -810,53 +1011,6 @@
   ((offsetof (type, nonlispfield) - offsetof (struct Lisp_Vector, contents[0])) \
    / sizeof (Lisp_Object))
 
-/* A char-table is a kind of vectorlike, with contents are like a
-   vector but with a few other slots.  For some purposes, it makes
-   sense to handle a char-table with type struct Lisp_Vector.  An
-   element of a char table can be any Lisp objects, but if it is a sub
-   char-table, we treat it a table that contains information of a
-   specific range of characters.  A sub char-table has the same
-   structure as a vector.  A sub char table appears only in an element
-   of a char-table, and there's no way to access it directly from
-   Emacs Lisp program.  */
-
-/* This is the number of slots that every char table must have.  This
-   counts the ordinary slots and the top, defalt, parent, and purpose
-   slots.  */
-#define CHAR_TABLE_STANDARD_SLOTS (VECSIZE (struct Lisp_Char_Table) - 1)
-
-/* Return the number of "extra" slots in the char table CT.  */
-
-#define CHAR_TABLE_EXTRA_SLOTS(CT)	\
-  (((CT)->header.size & PSEUDOVECTOR_SIZE_MASK) - CHAR_TABLE_STANDARD_SLOTS)
-
-#ifdef __GNUC__
-
-#define CHAR_TABLE_REF_ASCII(CT, IDX)					\
-  ({struct Lisp_Char_Table *_tbl = NULL;				\
-    Lisp_Object _val;							\
-    do {								\
-      _tbl = _tbl ? XCHAR_TABLE (_tbl->parent) : XCHAR_TABLE (CT);	\
-      _val = (! SUB_CHAR_TABLE_P (_tbl->ascii) ? _tbl->ascii		\
-	      : XSUB_CHAR_TABLE (_tbl->ascii)->contents[IDX]);		\
-      if (NILP (_val))							\
-	_val = _tbl->defalt;						\
-    } while (NILP (_val) && ! NILP (_tbl->parent));			\
-    _val; })
-
-#else  /* not __GNUC__ */
-
-#define CHAR_TABLE_REF_ASCII(CT, IDX)					  \
-  (! NILP (XCHAR_TABLE (CT)->ascii)					  \
-   ? (! SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii)			  \
-      ? XCHAR_TABLE (CT)->ascii						  \
-      : ! NILP (XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX]) \
-      ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX]	  \
-      : char_table_ref ((CT), (IDX)))					  \
-   :  char_table_ref ((CT), (IDX)))
-
-#endif	/* not __GNUC__ */
-
 /* Compute A OP B, using the unsigned comparison operator OP.  A and B
    should be integer expressions.  This is not the same as
    mathematical comparison; for example, UNSIGNED_CMP (0, <, -1)
@@ -870,31 +1024,23 @@
 /* Nonzero iff C is an ASCII character.  */
 #define ASCII_CHAR_P(c) UNSIGNED_CMP (c, <, 0x80)
 
-/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
-   characters.  Do not check validity of CT.  */
-#define CHAR_TABLE_REF(CT, IDX)					\
-  (ASCII_CHAR_P (IDX) ? CHAR_TABLE_REF_ASCII ((CT), (IDX))	\
-   : char_table_ref ((CT), (IDX)))
-
-/* Almost equivalent to Faref (CT, IDX).  However, if the result is
-   not a character, return IDX.
-
-   For these characters, do not check validity of CT
-   and do not follow parent.  */
-#define CHAR_TABLE_TRANSLATE(CT, IDX)	\
-  char_table_translate (CT, IDX)
-
-/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
-   8-bit European characters.  Do not check validity of CT.  */
-#define CHAR_TABLE_SET(CT, IDX, VAL)					\
-  (ASCII_CHAR_P (IDX) && SUB_CHAR_TABLE_P (XCHAR_TABLE (CT)->ascii)	\
-   ? XSUB_CHAR_TABLE (XCHAR_TABLE (CT)->ascii)->contents[IDX] = VAL	\
-   : char_table_set (CT, IDX, VAL))
-
-#define CHARTAB_SIZE_BITS_0 6
-#define CHARTAB_SIZE_BITS_1 4
-#define CHARTAB_SIZE_BITS_2 5
-#define CHARTAB_SIZE_BITS_3 7
+/* A char-table is a kind of vectorlike, with contents are like a
+   vector but with a few other slots.  For some purposes, it makes
+   sense to handle a char-table with type struct Lisp_Vector.  An
+   element of a char table can be any Lisp objects, but if it is a sub
+   char-table, we treat it a table that contains information of a
+   specific range of characters.  A sub char-table has the same
+   structure as a vector.  A sub char table appears only in an element
+   of a char-table, and there's no way to access it directly from
+   Emacs Lisp program.  */
+
+enum
+  {
+    CHARTAB_SIZE_BITS_0 = 6,
+    CHARTAB_SIZE_BITS_1 = 4,
+    CHARTAB_SIZE_BITS_2 = 5,
+    CHARTAB_SIZE_BITS_3 = 7
+  };
 
 extern const int chartab_size[4];
 
@@ -951,6 +1097,70 @@
     Lisp_Object contents[1];
   };
 
+/* This is the number of slots that every char table must have.  This
+   counts the ordinary slots and the top, defalt, parent, and purpose
+   slots.  */
+enum { CHAR_TABLE_STANDARD_SLOTS = VECSIZE (struct Lisp_Char_Table) - 1 };
+
+/* Return the number of "extra" slots in the char table CT.  */
+
+static inline int
+CHAR_TABLE_EXTRA_SLOTS (struct Lisp_Char_Table *ct)
+{
+  return ((ct->header.size & PSEUDOVECTOR_SIZE_MASK)
+	  - CHAR_TABLE_STANDARD_SLOTS);
+}
+
+static inline Lisp_Object
+CHAR_TABLE_REF_ASCII (Lisp_Object ct, ptrdiff_t idx)
+{
+  struct Lisp_Char_Table *tbl = NULL;
+  Lisp_Object val;
+  do
+    {
+      tbl = tbl ? XCHAR_TABLE (tbl->parent) : XCHAR_TABLE (ct);
+      val = (! SUB_CHAR_TABLE_P (tbl->ascii) ? tbl->ascii
+	     : XSUB_CHAR_TABLE (tbl->ascii)->contents[idx]);
+      if (NILP (val))
+	val = tbl->defalt;
+    }
+  while (NILP (val) && ! NILP (tbl->parent));
+
+  return val;
+}
+
+/* Almost equivalent to Faref (CT, IDX) with optimization for ASCII
+   characters.  Do not check validity of CT.  */
+static inline Lisp_Object
+CHAR_TABLE_REF (Lisp_Object ct, int idx)
+{
+  return (ASCII_CHAR_P (idx)
+	  ? CHAR_TABLE_REF_ASCII (ct, idx)
+	  : char_table_ref (ct, idx));
+}
+
+/* Almost equivalent to Faref (CT, IDX).  However, if the result is
+   not a character, return IDX.
+
+   For these characters, do not check validity of CT
+   and do not follow parent.  */
+static inline int
+CHAR_TABLE_TRANSLATE (Lisp_Object ct, int idx)
+{
+  return char_table_translate (ct, idx);
+}
+
+/* Equivalent to Faset (CT, IDX, VAL) with optimization for ASCII and
+   8-bit European characters.  Do not check validity of CT.  */
+static inline void
+CHAR_TABLE_SET (Lisp_Object ct, int idx, Lisp_Object val)
+{
+  if (ASCII_CHAR_P (idx) && SUB_CHAR_TABLE_P (XCHAR_TABLE (ct)->ascii))
+    XSUB_CHAR_TABLE (XCHAR_TABLE (ct)->ascii)->contents[idx] = val;
+  else
+    char_table_set (ct, idx, val);
+}
+
 /* A boolvector is a kind of vectorlike, with contents are like a string.  */
 struct Lisp_Bool_Vector
   {
@@ -1065,41 +1275,86 @@
 
 /* Value is name of symbol.  */
 
-#define SYMBOL_VAL(sym)   \
-  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  (sym)->val.value)
-#define SYMBOL_ALIAS(sym) \
-  (eassert ((sym)->redirect == SYMBOL_VARALIAS),  (sym)->val.alias)
-#define SYMBOL_BLV(sym)   \
-  (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv)
-#define SYMBOL_FWD(sym)   \
-  (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd)
-#define SET_SYMBOL_VAL(sym, v)     \
-  (eassert ((sym)->redirect == SYMBOL_PLAINVAL),  (sym)->val.value = (v))
-#define SET_SYMBOL_ALIAS(sym, v)   \
-  (eassert ((sym)->redirect == SYMBOL_VARALIAS),  (sym)->val.alias = (v))
-#define SET_SYMBOL_BLV(sym, v)     \
-  (eassert ((sym)->redirect == SYMBOL_LOCALIZED), (sym)->val.blv = (v))
-#define SET_SYMBOL_FWD(sym, v) \
-  (eassert ((sym)->redirect == SYMBOL_FORWARDED), (sym)->val.fwd = (v))
+static inline Lisp_Object
+SYMBOL_VAL (struct Lisp_Symbol *sym)
+{
+  eassert (sym->redirect == SYMBOL_PLAINVAL);
+  return sym->val.value;
+}
+static inline struct Lisp_Symbol *
+SYMBOL_ALIAS (struct Lisp_Symbol *sym)
+{
+  eassert (sym->redirect == SYMBOL_VARALIAS);
+  return sym->val.alias;
+}
+static inline struct Lisp_Buffer_Local_Value *
+SYMBOL_BLV (struct Lisp_Symbol *sym)
+{
+  eassert (sym->redirect == SYMBOL_LOCALIZED);
+  return sym->val.blv;
+}
+static inline union Lisp_Fwd *
+SYMBOL_FWD (struct Lisp_Symbol *sym)
+{
+  eassert (sym->redirect == SYMBOL_FORWARDED);
+  return sym->val.fwd;
+}
+static inline void
+SET_SYMBOL_VAL (struct Lisp_Symbol *sym, Lisp_Object v)
+{
+  eassert (sym->redirect == SYMBOL_PLAINVAL);
+  sym->val.value = v;
+}
+static inline void
+SET_SYMBOL_ALIAS (struct Lisp_Symbol *sym, struct Lisp_Symbol *v)
+{
+  eassert (sym->redirect == SYMBOL_VARALIAS);
+  sym->val.alias = v;
+}
+static inline void
+SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v)
+{
+  eassert (sym->redirect == SYMBOL_LOCALIZED);
+  sym->val.blv = v;
+}
+static inline void
+SET_SYMBOL_FWD (struct Lisp_Symbol *sym, union Lisp_Fwd *v)
+{
+  eassert (sym->redirect == SYMBOL_FORWARDED);
+  sym->val.fwd = v;
+}
 
-#define SYMBOL_NAME(sym)  \
-     LISP_MAKE_RVALUE (XSYMBOL (sym)->xname)
+static inline Lisp_Object
+SYMBOL_NAME (Lisp_Object sym)
+{
+  return XSYMBOL (sym)->xname;
+}
 
 /* Value is non-zero if SYM is an interned symbol.  */
 
-#define SYMBOL_INTERNED_P(sym)  \
-     (XSYMBOL (sym)->interned != SYMBOL_UNINTERNED)
+static inline int
+SYMBOL_INTERNED_P (Lisp_Object sym)
+{
+  return XSYMBOL (sym)->interned != SYMBOL_UNINTERNED;
+}
 
 /* Value is non-zero if SYM is interned in initial_obarray.  */
 
-#define SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P(sym) \
-     (XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY)
+static inline int
+SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (Lisp_Object sym)
+{
+  return XSYMBOL (sym)->interned == SYMBOL_INTERNED_IN_INITIAL_OBARRAY;
+}
 
 /* Value is non-zero if symbol is considered a constant, i.e. its
    value cannot be changed (there is an exception for keyword symbols,
    whose value can be set to the keyword symbol itself).  */
 
-#define SYMBOL_CONSTANT_P(sym)   XSYMBOL (sym)->constant
+static inline int
+SYMBOL_CONSTANT_P (Lisp_Object sym)
+{
+  return XSYMBOL (sym)->constant;
+}
 
 #define DEFSYM(sym, name)	\
   do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
@@ -1181,16 +1436,25 @@
 };
 
 
-#define XHASH_TABLE(OBJ) \
-     ((struct Lisp_Hash_Table *) XUNTAG (OBJ, Lisp_Vectorlike))
+static inline struct Lisp_Hash_Table *
+XHASH_TABLE (Lisp_Object a)
+{
+  return XUNTAG (a, Lisp_Vectorlike);
+}
 
 #define XSET_HASH_TABLE(VAR, PTR) \
      (XSETPSEUDOVECTOR (VAR, PTR, PVEC_HASH_TABLE))
 
-#define HASH_TABLE_P(OBJ)  PSEUDOVECTORP (OBJ, PVEC_HASH_TABLE)
-
-#define CHECK_HASH_TABLE(x) \
-  CHECK_TYPE (HASH_TABLE_P (x), Qhash_table_p, x)
+static inline int
+HASH_TABLE_P (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_HASH_TABLE);
+}
+static inline void
+CHECK_HASH_TABLE (Lisp_Object x)
+{
+  return CHECK_TYPE (HASH_TABLE_P (x), Qhash_table_p, x);
+}
 
 /* Value is the key part of entry IDX in hash table H.  */
 
@@ -1215,12 +1479,14 @@
 #define HASH_INDEX(H, IDX)  AREF ((H)->index, (IDX))
 
 /* Value is the size of hash table H.  */
-
-#define HASH_TABLE_SIZE(H) ASIZE ((H)->next)
+static inline ptrdiff_t
+HASH_TABLE_SIZE (struct Lisp_Hash_Table *h)
+{
+  return ASIZE (h->next);
+}
 
 /* Default size for hash tables if not specified.  */
-
-#define DEFAULT_HASH_SIZE 65
+enum { DEFAULT_HASH_SIZE = 65 };
 
 /* Default threshold specifying when to resize a hash table.  The
    value gives the ratio of current entries in the hash table and the
@@ -1340,6 +1606,43 @@
     struct Lisp_Save_Value u_save_value;
   };
 
+static inline union Lisp_Misc *
+XMISC (Lisp_Object a)
+{
+  return XUNTAG (a, Lisp_Misc);
+}
+
+static inline struct Lisp_Misc_Any *
+XMISCANY (Lisp_Object a)
+{
+  eassert (MISCP (a));
+  return & XMISC (a)->u_any;
+}
+
+/* A macro because it is also used as an lvalue.  FIXME: clean this up.  */
+#define XMISCTYPE(a)   (XMISCANY (a)->type)
+
+static inline struct Lisp_Marker *
+XMARKER (Lisp_Object a)
+{
+  eassert (MARKERP (a));
+  return & XMISC (a)->u_marker;
+}
+
+static inline struct Lisp_Overlay *
+XOVERLAY (Lisp_Object a)
+{
+  eassert (OVERLAYP (a));
+  return & XMISC (a)->u_overlay;
+}
+
+static inline struct Lisp_Save_Value *
+XSAVE_VALUE (Lisp_Object a)
+{
+  eassert (SAVE_VALUEP (a));
+  return & XMISC (a)->u_save_value;
+}
+
 /* Forwarding pointer to an int variable.
    This is allowed only in the value cell of a symbol,
    and it means that the symbol's value really lives in the
@@ -1429,13 +1732,29 @@
     Lisp_Object valcell;
   };
 
-#define BLV_FOUND(blv) \
-  (eassert ((blv)->found == !EQ ((blv)->defcell, (blv)->valcell)), (blv)->found)
-#define SET_BLV_FOUND(blv, v) \
-  (eassert ((v) == !EQ ((blv)->defcell, (blv)->valcell)), (blv)->found = (v))
+static inline int
+BLV_FOUND (struct Lisp_Buffer_Local_Value *blv)
+{
+  eassert (blv->found == !EQ (blv->defcell, blv->valcell));
+  return blv->found;
+}
+static inline void
+SET_BLV_FOUND (struct Lisp_Buffer_Local_Value *blv, int v)
+{
+  eassert (v == !EQ (blv->defcell, blv->valcell));
+  blv->found = v;
+}
 
-#define BLV_VALUE(blv) (XCDR ((blv)->valcell))
-#define SET_BLV_VALUE(blv, v) (XSETCDR ((blv)->valcell, v))
+static inline Lisp_Object
+BLV_VALUE (struct Lisp_Buffer_Local_Value *blv)
+{
+  return XCDR (blv->valcell);
+}
+static inline void
+SET_BLV_VALUE (struct Lisp_Buffer_Local_Value *blv, Lisp_Object v)
+{
+  XSETCDR (blv->valcell, v);
+}
 
 /* Like Lisp_Objfwd except that value lives in a slot in the
    current kboard.  */
@@ -1453,6 +1772,47 @@
     struct Lisp_Buffer_Objfwd u_buffer_objfwd;
     struct Lisp_Kboard_Objfwd u_kboard_objfwd;
   };
+
+static inline enum Lisp_Fwd_Type
+XFWDTYPE (union Lisp_Fwd *a)
+{
+  return a->u_intfwd.type;
+}
+
+static inline struct Lisp_Intfwd *
+XINTFWD (union Lisp_Fwd *a)
+{
+  eassert (INTFWDP (a));
+  return &a->u_intfwd;
+}
+
+static inline struct Lisp_Boolfwd *
+XBOOLFWD (union Lisp_Fwd *a)
+{
+  eassert (BOOLFWDP (a));
+  return &a->u_boolfwd;
+}
+
+static inline struct Lisp_Objfwd *
+XOBJFWD (union Lisp_Fwd *a)
+{
+  eassert (OBJFWDP (a));
+  return &a->u_objfwd;
+}
+
+static inline struct Lisp_Buffer_Objfwd *
+XBUFFER_OBJFWD (union Lisp_Fwd *a)
+{
+  eassert (BUFFER_OBJFWDP (a));
+  return &a->u_buffer_objfwd;
+}
+
+static inline struct Lisp_Kboard_Objfwd *
+XKBOARD_OBJFWD (union Lisp_Fwd *a)
+{
+  eassert (KBOARD_OBJFWDP (a));
+  return &a->u_kboard_objfwd;
+}
 
 /* Lisp floating point type.  */
 struct Lisp_Float
@@ -1468,13 +1828,24 @@
     } u;
   };
 
+static inline double
+XFLOAT_DATA (Lisp_Object f)
+{
 #ifdef HIDE_LISP_IMPLEMENTATION
-#define XFLOAT_DATA(f)	(0 ? XFLOAT (f)->u.data_ : XFLOAT (f)->u.data_)
+  return XFLOAT (f)->u.data_;
 #else
-#define XFLOAT_DATA(f)	(0 ? XFLOAT (f)->u.data :  XFLOAT (f)->u.data)
+  return XFLOAT (f)->u.data;
+#endif
+}
+
+#ifndef HIDE_LISP_IMPLEMENTATION
 /* This should be used only in alloc.c, which always disables
    HIDE_LISP_IMPLEMENTATION.  */
-#define XFLOAT_INIT(f,n) (XFLOAT (f)->u.data = (n))
+static inline void
+XFLOAT_INIT (Lisp_Object f, double n)
+{
+  XFLOAT (f)->u.data = n;
+}
 #endif
 
 /* A character, declared with the following typedef, is a member
@@ -1485,91 +1856,36 @@
 #endif
 
 /* Meanings of slots in a Lisp_Compiled:  */
-
-#define COMPILED_ARGLIST 0
-#define COMPILED_BYTECODE 1
-#define COMPILED_CONSTANTS 2
-#define COMPILED_STACK_DEPTH 3
-#define COMPILED_DOC_STRING 4
-#define COMPILED_INTERACTIVE 5
+enum
+  {
+    COMPILED_ARGLIST,
+    COMPILED_BYTECODE,
+    COMPILED_CONSTANTS,
+    COMPILED_STACK_DEPTH,
+    COMPILED_DOC_STRING,
+    COMPILED_INTERACTIVE
+  };
 
 /* Flag bits in a character.  These also get used in termhooks.h.
    Richard Stallman <rms <at> gnu.ai.mit.edu> thinks that MULE
    (MUlti-Lingual Emacs) might need 22 bits for the character value
    itself, so we probably shouldn't use any bits lower than 0x0400000.  */
-#define CHAR_ALT   (0x0400000)
-#define CHAR_SUPER (0x0800000)
-#define CHAR_HYPER (0x1000000)
-#define CHAR_SHIFT (0x2000000)
-#define CHAR_CTL   (0x4000000)
-#define CHAR_META  (0x8000000)
-
-#define CHAR_MODIFIER_MASK \
-  (CHAR_ALT | CHAR_SUPER | CHAR_HYPER  | CHAR_SHIFT | CHAR_CTL | CHAR_META)
-
+enum
+  {
+    CHAR_ALT   = 0x0400000,
+    CHAR_SUPER = 0x0800000,
+    CHAR_HYPER = 0x1000000,
+    CHAR_SHIFT = 0x2000000,
+    CHAR_CTL   = 0x4000000,
+    CHAR_META  = 0x8000000,
+    CHAR_MODIFIER_MASK =
+      CHAR_ALT | CHAR_SUPER | CHAR_HYPER  | CHAR_SHIFT | CHAR_CTL | CHAR_META
+  };
 
 /* Actually, the current Emacs uses 22 bits for the character value
    itself.  */
-#define CHARACTERBITS 22
-
-
-/* The glyph datatype, used to represent characters on the display.
-   It consists of a char code and a face id.  */
-
-typedef struct {
-  int ch;
-  int face_id;
-} GLYPH;
-
-/* Return a glyph's character code.  */
-#define GLYPH_CHAR(glyph) ((glyph).ch)
-
-/* Return a glyph's face ID.  */
-#define GLYPH_FACE(glyph) ((glyph).face_id)
-
-#define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
-#define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
-#define SET_GLYPH(glyph, char, face) ((glyph).ch = (char), (glyph).face_id = (face))
-
-/* Return 1 if GLYPH contains valid character code.  */
-#define GLYPH_CHAR_VALID_P(glyph) CHAR_VALID_P (GLYPH_CHAR (glyph))
-
-
-/* Glyph Code from a display vector may either be an integer which
-   encodes a char code in the lower CHARACTERBITS bits and a (very small)
-   face-id in the upper bits, or it may be a cons (CHAR . FACE-ID).  */
-
-#define GLYPH_CODE_P(gc)						\
-  (CONSP (gc)								\
-   ? (CHARACTERP (XCAR (gc))						\
-      && RANGED_INTEGERP (0, XCDR (gc), MAX_FACE_ID))			\
-   : (RANGED_INTEGERP							\
-      (0, gc,								\
-       (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS		\
-	? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR		\
-	: TYPE_MAXIMUM (EMACS_INT)))))
-
-/* The following are valid only if GLYPH_CODE_P (gc).  */
-
-#define GLYPH_CODE_CHAR(gc) \
-  (CONSP (gc) ? XINT (XCAR (gc)) : XINT (gc) & ((1 << CHARACTERBITS) - 1))
-
-#define GLYPH_CODE_FACE(gc) \
-  (CONSP (gc) ? XINT (XCDR (gc)) : XINT (gc) >> CHARACTERBITS)
-
-#define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc)				\
-  do									\
-    {									\
-      if (CONSP (gc))							\
-	SET_GLYPH (glyph, XINT (XCAR (gc)), XINT (XCDR (gc)));		\
-      else								\
-	SET_GLYPH (glyph, (XINT (gc) & ((1 << CHARACTERBITS)-1)),	\
-		   (XINT (gc) >> CHARACTERBITS));			\
-    }									\
-  while (0)
-
-/* The ID of the mode line highlighting face.  */
-#define GLYPH_MODE_LINE_FACE 1
+enum { CHARACTERBITS = 22 };
+
 
 /* Structure to hold mouse highlight data.  This is here because other
    header files need it for defining struct x_output etc.  */
@@ -1608,140 +1924,304 @@
 
 /* Data type checking */
 
-#define NILP(x)  EQ (x, Qnil)
-
-#define NUMBERP(x) (INTEGERP (x) || FLOATP (x))
-#define NATNUMP(x) (INTEGERP (x) && XINT (x) >= 0)
-
-#define RANGED_INTEGERP(lo, x, hi) \
-  (INTEGERP (x) && (lo) <= XINT (x) && XINT (x) <= (hi))
+static inline int
+NILP (Lisp_Object x)
+{
+  return EQ (x, Qnil);
+}
+
+static inline int
+NUMBERP (Lisp_Object x)
+{
+  return INTEGERP (x) || FLOATP (x);
+}
+static inline int
+NATNUMP (Lisp_Object x)
+{
+  return INTEGERP (x) && 0 <= XINT (x);
+}
+
+static inline int
+RANGED_INTEGERP (intmax_t lo, Lisp_Object x, intmax_t hi)
+{
+  return INTEGERP (x) && lo <= XINT (x) && XINT (x) <= hi;
+}
+
 #define TYPE_RANGED_INTEGERP(type, x) \
-  (TYPE_SIGNED (type)							\
-   ? RANGED_INTEGERP (TYPE_MINIMUM (type), x, TYPE_MAXIMUM (type))	\
-   : RANGED_INTEGERP (0, x, TYPE_MAXIMUM (type)))
-
-#define INTEGERP(x) (LISP_INT_TAG_P (XTYPE ((x))))
-#define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
-#define MISCP(x) (XTYPE ((x)) == Lisp_Misc)
-#define VECTORLIKEP(x) (XTYPE ((x)) == Lisp_Vectorlike)
-#define STRINGP(x) (XTYPE ((x)) == Lisp_String)
-#define CONSP(x) (XTYPE ((x)) == Lisp_Cons)
-
-#define FLOATP(x) (XTYPE ((x)) == Lisp_Float)
-#define VECTORP(x) (VECTORLIKEP (x) && !(ASIZE (x) & PSEUDOVECTOR_FLAG))
-#define OVERLAYP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay)
-#define MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker)
-#define SAVE_VALUEP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value)
-
-#define INTFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Int)
-#define BOOLFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Bool)
-#define OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Obj)
-#define BUFFER_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Buffer_Obj)
-#define KBOARD_OBJFWDP(x) (XFWDTYPE (x) == Lisp_Fwd_Kboard_Obj)
-
-/* True if object X is a pseudovector whose code is CODE.  The cast to struct
-   vectorlike_header * avoids aliasing issues.  */
-#define PSEUDOVECTORP(x, code)					\
-  TYPED_PSEUDOVECTORP (x, vectorlike_header, code)
-
-#define PSEUDOVECTOR_TYPEP(v, code)					\
-  (((v)->size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))			\
-   == (PSEUDOVECTOR_FLAG | ((code) << PSEUDOVECTOR_SIZE_BITS)))
-
-/* True if object X, with internal type struct T *, is a pseudovector whose
-   code is CODE.  */
-#define TYPED_PSEUDOVECTORP(x, t, code)				\
-  (VECTORLIKEP (x)						\
-   && PSEUDOVECTOR_TYPEP ((struct t *) XUNTAG (x, Lisp_Vectorlike), code))
+  (INTEGERP (x)			      \
+   && (TYPE_SIGNED (type) ? TYPE_MINIMUM (type) <= XINT (x) : 0 <= XINT (x)) \
+   && XINT (x) <= TYPE_MAXIMUM (type))
+
+static inline int CONSP (Lisp_Object x) { return XTYPE (x) == Lisp_Cons; }
+static inline int FLOATP (Lisp_Object x) { return XTYPE (x) == Lisp_Float; }
+static inline int MISCP (Lisp_Object x) { return XTYPE (x) == Lisp_Misc; }
+static inline int STRINGP (Lisp_Object x) { return XTYPE (x) == Lisp_String; }
+static inline int SYMBOLP (Lisp_Object x) { return XTYPE (x) == Lisp_Symbol; }
+static inline int
+INTEGERP (Lisp_Object x)
+{
+  return LISP_INT_TAG_P (XTYPE (x));
+}
+static inline int
+VECTORLIKEP (Lisp_Object x)
+{
+  return XTYPE (x) == Lisp_Vectorlike;
+}
+static inline int
+VECTORP (Lisp_Object x)
+{
+  return VECTORLIKEP (x) && ! (ASIZE (x) & PSEUDOVECTOR_FLAG);
+}
+static inline int
+OVERLAYP (Lisp_Object x)
+{
+  return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Overlay;
+}
+static inline int
+MARKERP (Lisp_Object x)
+{
+  return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker;
+}
+static inline int
+SAVE_VALUEP (Lisp_Object x)
+{
+  return MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Save_Value;
+}
+
+static inline int
+INTFWDP (union Lisp_Fwd *a)
+{
+  return XFWDTYPE (a) == Lisp_Fwd_Int;
+}
+static inline int
+BOOLFWDP (union Lisp_Fwd *a)
+{
+  return XFWDTYPE (a) == Lisp_Fwd_Bool;
+}
+static inline int
+OBJFWDP (union Lisp_Fwd *a)
+{
+  return XFWDTYPE (a) == Lisp_Fwd_Obj;
+}
+static inline int
+BUFFER_OBJFWDP (union Lisp_Fwd *a)
+{
+  return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj;
+}
+static inline int
+KBOARD_OBJFWDP (union Lisp_Fwd *a)
+{
+  return XFWDTYPE (a) == Lisp_Fwd_Kboard_Obj;
+}
+
+/* True if the size field SIZE of a pseudovector is that of a
+   pseudovector whose code is CODE.  */
+static inline int
+PSEUDOVECTOR_SIZE_TYPEP (ptrdiff_t size, int code)
+{
+  return ((size & (PSEUDOVECTOR_FLAG | PVEC_TYPE_MASK))
+	  == (PSEUDOVECTOR_FLAG | (code << PSEUDOVECTOR_SIZE_BITS)));
+}
+
+/* True if A is a pseudovector whose code is CODE.  */
+static inline int
+PSEUDOVECTORP (Lisp_Object a, int code)
+{
+  if (! VECTORLIKEP (a))
+    return 0;
+  else
+    {
+      /* Converting to struct vectorlike_header * avoids aliasing issues.  */
+      struct vectorlike_header *h = XUNTAG (a, Lisp_Vectorlike);
+      return PSEUDOVECTOR_SIZE_TYPEP (h->size, code);
+    }
+}
+
 
 /* Test for specific pseudovector types.  */
-#define WINDOW_CONFIGURATIONP(x) PSEUDOVECTORP (x, PVEC_WINDOW_CONFIGURATION)
-#define PROCESSP(x) PSEUDOVECTORP (x, PVEC_PROCESS)
-#define WINDOWP(x) PSEUDOVECTORP (x, PVEC_WINDOW)
-#define TERMINALP(x) PSEUDOVECTORP (x, PVEC_TERMINAL)
+
+static inline int
+WINDOW_CONFIGURATIONP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_WINDOW_CONFIGURATION);
+}
+
+static inline int
+PROCESSP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_PROCESS);
+}
+
+static inline int
+WINDOWP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_WINDOW);
+}
+
+static inline int
+TERMINALP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_TERMINAL);
+}
+
 /* SUBRP is special since Lisp_Subr lacks struct vectorlike_header.  */
-#define SUBRP(x) TYPED_PSEUDOVECTORP (x, Lisp_Subr, PVEC_SUBR)
-#define COMPILEDP(x) PSEUDOVECTORP (x, PVEC_COMPILED)
-#define BUFFERP(x) PSEUDOVECTORP (x, PVEC_BUFFER)
-#define CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_CHAR_TABLE)
-#define SUB_CHAR_TABLE_P(x) PSEUDOVECTORP (x, PVEC_SUB_CHAR_TABLE)
-#define BOOL_VECTOR_P(x) PSEUDOVECTORP (x, PVEC_BOOL_VECTOR)
-#define FRAMEP(x) PSEUDOVECTORP (x, PVEC_FRAME)
+static inline int
+SUBRP (Lisp_Object a)
+{
+  if (! VECTORLIKEP (a))
+    return 0;
+  else
+    {
+      struct Lisp_Subr *h = XUNTAG (a, Lisp_Vectorlike);
+      return PSEUDOVECTOR_SIZE_TYPEP (h->size, PVEC_SUBR);
+    }
+}
+
+static inline int
+COMPILEDP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_COMPILED);
+}
+
+static inline int
+BUFFERP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_BUFFER);
+}
+
+static inline int
+CHAR_TABLE_P (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_CHAR_TABLE);
+}
+
+static inline int
+SUB_CHAR_TABLE_P (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_SUB_CHAR_TABLE);
+}
+
+static inline int
+BOOL_VECTOR_P (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_BOOL_VECTOR);
+}
+
+static inline int
+FRAMEP (Lisp_Object a)
+{
+  return PSEUDOVECTORP (a, PVEC_FRAME);
+}
 
 /* Test for image (image . spec)  */
-#define IMAGEP(x) (CONSP (x) && EQ (XCAR (x), Qimage))
+static inline int
+IMAGEP (Lisp_Object x)
+{
+  return CONSP (x) && EQ (XCAR (x), Qimage);
+}
 
 /* Array types.  */
-
-#define ARRAYP(x) \
-  (VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x))
+static inline int
+ARRAYP (Lisp_Object x)
+{
+  return VECTORP (x) || STRINGP (x) || CHAR_TABLE_P (x) || BOOL_VECTOR_P (x);
+}
 
-#define CHECK_LIST(x) \
-  CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x)
-
-#define CHECK_LIST_CONS(x, y) \
-  CHECK_TYPE (CONSP (x), Qlistp, y)
-
-#define CHECK_LIST_END(x, y) \
-  CHECK_TYPE (NILP (x), Qlistp, y)
-
-#define CHECK_STRING(x) \
-  CHECK_TYPE (STRINGP (x), Qstringp, x)
-
-#define CHECK_STRING_CAR(x) \
-  CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x))
-
-#define CHECK_CONS(x) \
-  CHECK_TYPE (CONSP (x), Qconsp, x)
-
-#define CHECK_SYMBOL(x) \
-  CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
-
-#define CHECK_CHAR_TABLE(x) \
-  CHECK_TYPE (CHAR_TABLE_P (x), Qchar_table_p, x)
-
-#define CHECK_VECTOR(x) \
-  CHECK_TYPE (VECTORP (x), Qvectorp, x)
-
-#define CHECK_VECTOR_OR_STRING(x) \
-  CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x)
-
-#define CHECK_ARRAY(x, Qxxxp) \
-  CHECK_TYPE (ARRAYP (x), Qxxxp, x)
-
-#define CHECK_VECTOR_OR_CHAR_TABLE(x) \
-  CHECK_TYPE (VECTORP (x) || CHAR_TABLE_P (x), Qvector_or_char_table_p, x)
-
-#define CHECK_BUFFER(x) \
-  CHECK_TYPE (BUFFERP (x), Qbufferp, x)
-
-#define CHECK_WINDOW(x) \
-  CHECK_TYPE (WINDOWP (x), Qwindowp, x)
-
-#define CHECK_WINDOW_CONFIGURATION(x) \
-  CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x)
-
-/* This macro rejects windows on the interior of the window tree as
-   "dead", which is what we want; this is an argument-checking macro, and
-   the user should never get access to interior windows.
-
-   A window of any sort, leaf or interior, is dead if the buffer,
-   vchild, and hchild members are all nil.  */
-
-#define CHECK_LIVE_WINDOW(x) \
-  CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), Qwindow_live_p, x)
-
-#define CHECK_PROCESS(x) \
-  CHECK_TYPE (PROCESSP (x), Qprocessp, x)
-
-#define CHECK_SUBR(x) \
-  CHECK_TYPE (SUBRP (x), Qsubrp, x)
-
-#define CHECK_NUMBER(x) \
-  CHECK_TYPE (INTEGERP (x), Qintegerp, x)
-
-#define CHECK_NATNUM(x) \
-  CHECK_TYPE (NATNUMP (x), Qwholenump, x)
+static inline void
+CHECK_LIST (Lisp_Object x)
+{
+  CHECK_TYPE (CONSP (x) || NILP (x), Qlistp, x);
+}
+static inline void
+CHECK_LIST_CONS (Lisp_Object x, Lisp_Object y)
+{
+  CHECK_TYPE (CONSP (x), Qlistp, y);
+}
+static inline void
+CHECK_LIST_END (Lisp_Object x, Lisp_Object y)
+{
+  CHECK_TYPE (NILP (x), Qlistp, y);
+}
+static inline void
+CHECK_STRING (Lisp_Object x)
+{
+  CHECK_TYPE (STRINGP (x), Qstringp, x);
+}
+static inline void
+CHECK_STRING_CAR (Lisp_Object x)
+{
+  CHECK_TYPE (STRINGP (XCAR (x)), Qstringp, XCAR (x));
+}
+static inline void
+CHECK_CONS (Lisp_Object x)
+{
+  CHECK_TYPE (CONSP (x), Qconsp, x);
+}
+static inline void
+CHECK_SYMBOL (Lisp_Object x)
+{
+  CHECK_TYPE (SYMBOLP (x), Qsymbolp, x);
+}
+static inline void
+CHECK_CHAR_TABLE (Lisp_Object x)
+{
+  CHECK_TYPE (CHAR_TABLE_P (x), Qchar_table_p, x);
+}
+static inline void
+CHECK_VECTOR (Lisp_Object x)
+{
+  CHECK_TYPE (VECTORP (x), Qvectorp, x);
+}
+static inline void
+CHECK_VECTOR_OR_STRING (Lisp_Object x)
+{
+  CHECK_TYPE (VECTORP (x) || STRINGP (x), Qarrayp, x);
+}
+static inline void
+CHECK_ARRAY (Lisp_Object x, Lisp_Object Qxxxp)
+{
+  CHECK_TYPE (ARRAYP (x), Qxxxp, x);
+}
+static inline void
+CHECK_VECTOR_OR_CHAR_TABLE (Lisp_Object x)
+{
+  CHECK_TYPE (VECTORP (x) || CHAR_TABLE_P (x), Qvector_or_char_table_p, x);
+}
+static inline void
+CHECK_BUFFER (Lisp_Object x)
+{
+  CHECK_TYPE (BUFFERP (x), Qbufferp, x);
+}
+static inline void
+CHECK_WINDOW (Lisp_Object x)
+{
+  CHECK_TYPE (WINDOWP (x), Qwindowp, x);
+}
+static inline void
+CHECK_WINDOW_CONFIGURATION (Lisp_Object x)
+{
+  CHECK_TYPE (WINDOW_CONFIGURATIONP (x), Qwindow_configuration_p, x);
+}
+static inline void
+CHECK_PROCESS (Lisp_Object x)
+{
+  CHECK_TYPE (PROCESSP (x), Qprocessp, x);
+}
+static inline void
+CHECK_SUBR (Lisp_Object x)
+{
+  CHECK_TYPE (SUBRP (x), Qsubrp, x);
+}
+static inline void
+CHECK_NUMBER (Lisp_Object x)
+{
+  CHECK_TYPE (INTEGERP (x), Qintegerp, x);
+}
+static inline void
+CHECK_NATNUM (Lisp_Object x)
+{
+  CHECK_TYPE (NATNUMP (x), Qwholenump, x);
+}
 
 #define CHECK_RANGED_INTEGER(x, lo, hi)					\
   do {									\
@@ -1762,57 +2242,76 @@
       CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type));			\
   } while (0)
 
-#define CHECK_MARKER(x) \
-  CHECK_TYPE (MARKERP (x), Qmarkerp, x)
+static inline void
+CHECK_MARKER (Lisp_Object x)
+{
+  CHECK_TYPE (MARKERP (x), Qmarkerp, x);
+}
 
 #define CHECK_NUMBER_COERCE_MARKER(x) \
   do { if (MARKERP ((x))) XSETFASTINT (x, marker_position (x)); \
     else CHECK_TYPE (INTEGERP (x), Qinteger_or_marker_p, x); } while (0)
 
-#define XFLOATINT(n) extract_float((n))
-
-#define CHECK_FLOAT(x) \
-  CHECK_TYPE (FLOATP (x), Qfloatp, x)
-
-#define CHECK_NUMBER_OR_FLOAT(x) \
-  CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x)
+static inline double
+XFLOATINT (Lisp_Object n)
+{
+  return extract_float (n);
+}
+
+static inline void
+CHECK_FLOAT (Lisp_Object x)
+{
+  CHECK_TYPE (FLOATP (x), Qfloatp, x);
+}
+static inline void
+CHECK_NUMBER_OR_FLOAT (Lisp_Object x)
+{
+  CHECK_TYPE (FLOATP (x) || INTEGERP (x), Qnumberp, x);
+}
 
 #define CHECK_NUMBER_OR_FLOAT_COERCE_MARKER(x) \
   do { if (MARKERP (x)) XSETFASTINT (x, marker_position (x)); \
     else CHECK_TYPE (INTEGERP (x) || FLOATP (x), Qnumber_or_marker_p, x); } while (0)
 
-#define CHECK_OVERLAY(x) \
-  CHECK_TYPE (OVERLAYP (x), Qoverlayp, x)
+static inline void
+CHECK_OVERLAY (Lisp_Object x)
+{
+  CHECK_TYPE (OVERLAYP (x), Qoverlayp, x);
+}
 
 /* Since we can't assign directly to the CAR or CDR fields of a cons
    cell, use these when checking that those fields contain numbers.  */
-#define CHECK_NUMBER_CAR(x) \
-  do {					\
-    Lisp_Object tmp = XCAR (x);		\
-    CHECK_NUMBER (tmp);			\
-    XSETCAR ((x), tmp);			\
-  } while (0)
-
-#define CHECK_NUMBER_CDR(x) \
-  do {					\
-    Lisp_Object tmp = XCDR (x);		\
-    CHECK_NUMBER (tmp);			\
-    XSETCDR ((x), tmp);			\
-  } while (0)
-
-#define CHECK_NATNUM_CAR(x) \
-  do {					\
-    Lisp_Object tmp = XCAR (x);		\
-    CHECK_NATNUM (tmp);			\
-    XSETCAR ((x), tmp);			\
-  } while (0)
-
-#define CHECK_NATNUM_CDR(x) \
-  do {					\
-    Lisp_Object tmp = XCDR (x);		\
-    CHECK_NATNUM (tmp);			\
-    XSETCDR ((x), tmp);			\
-  } while (0)
+static inline void
+CHECK_NUMBER_CAR (Lisp_Object x)
+{
+  Lisp_Object tmp = XCAR (x);
+  CHECK_NUMBER (tmp);
+  XSETCAR (x, tmp);
+}
+
+static inline void
+CHECK_NUMBER_CDR (Lisp_Object x)
+{
+  Lisp_Object tmp = XCDR (x);
+  CHECK_NUMBER (tmp);
+  XSETCDR (x, tmp);
+}
+
+static inline void
+CHECK_NATNUM_CAR (Lisp_Object x)
+{
+  Lisp_Object tmp = XCAR (x);
+  CHECK_NATNUM (tmp);
+  XSETCAR (x, tmp);
+}
+
+static inline void
+CHECK_NATNUM_CDR (Lisp_Object x)
+{
+  Lisp_Object tmp = XCDR (x);
+  CHECK_NATNUM (tmp);
+  XSETCDR (x, tmp);
+}
 
 /* Define a built-in function for calling from Lisp.
  `lname' should be the name to give the function in Lisp,
@@ -1879,18 +2378,20 @@
 			 Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object)
 
 /* Non-zero if OBJ is a Lisp function.  */
-#define FUNCTIONP(OBJ)					\
-     ((CONSP (OBJ) && EQ (XCAR (OBJ), Qlambda))		\
-      || (SYMBOLP (OBJ) && !NILP (Ffboundp (OBJ)))	\
-      || COMPILEDP (OBJ)				\
-      || SUBRP (OBJ))
+static inline int
+FUNCTIONP (Lisp_Object obj)
+{
+  return ((CONSP (obj) && EQ (XCAR (obj), Qlambda))
+	  || (SYMBOLP (obj) && !NILP (Ffboundp (obj)))
+	  || COMPILEDP (obj)
+	  || SUBRP (obj));
+}
 
 /* defsubr (Sname);
    is how we define the symbol for function `name' at start-up time.  */
 extern void defsubr (struct Lisp_Subr *);
 
-#define MANY -2
-#define UNEVALLED -1
+enum { MANY = -2, UNEVALLED = -1 };
 
 extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *);
 extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *);
@@ -1983,7 +2484,11 @@
 extern struct specbinding *specpdl_ptr;
 extern ptrdiff_t specpdl_size;
 
-#define SPECPDL_INDEX()	(specpdl_ptr - specpdl)
+static inline ptrdiff_t
+SPECPDL_INDEX (void)
+{
+  return specpdl_ptr - specpdl;
+}
 
 /* Everything needed to describe an active condition case.  */
 struct handler
@@ -2301,6 +2806,8 @@
 #define EXFUN(fnname, maxargs) \
   extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs
 
+#include "globals.h"
+
 /* Forward declarations for prototypes.  */
 struct window;
 struct frame;
@@ -2334,6 +2841,7 @@
 
 extern Lisp_Object Qinteger;
 
+extern Lisp_Object Qsubrp;
 extern Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
 
 EXFUN (Fbyteorder, 0) ATTRIBUTE_CONST;
@@ -2429,6 +2937,7 @@
 extern Lisp_Object Qcursor_in_echo_area;
 extern Lisp_Object Qstring_lessp;
 extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql;
+extern Lisp_Object Qhash_table_p;
 EMACS_UINT hash_string (char const *, ptrdiff_t);
 EMACS_UINT sxhash (Lisp_Object, int);
 Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object,
@@ -2714,7 +3223,7 @@
 				 Lisp_Object);
 extern Lisp_Object internal_with_output_to_temp_buffer
         (const char *, Lisp_Object (*) (Lisp_Object), Lisp_Object);
-#define FLOAT_TO_STRING_BUFSIZE 350
+enum { FLOAT_TO_STRING_BUFSIZE = 350 };
 extern int float_to_string (char *, double);
 extern void syms_of_print (void);
 
@@ -2737,10 +3246,12 @@
 extern Lisp_Object intern_1 (const char *, ptrdiff_t);
 extern Lisp_Object intern_c_string_1 (const char *, ptrdiff_t);
 extern Lisp_Object oblookup (Lisp_Object, const char *, ptrdiff_t, ptrdiff_t);
-#define LOADHIST_ATTACH(x) \
-  do {									\
-    if (initialized) Vcurrent_load_list = Fcons (x, Vcurrent_load_list); \
-  } while (0)
+static inline void
+LOADHIST_ATTACH (Lisp_Object x)
+{
+  if (initialized)
+    Vcurrent_load_list = Fcons (x, Vcurrent_load_list);
+}
 extern int openp (Lisp_Object, Lisp_Object, Lisp_Object,
                   Lisp_Object *, Lisp_Object);
 Lisp_Object string_to_number (char const *, int, int);
@@ -2858,6 +3369,7 @@
 extern Lisp_Object Vbuffer_alist;
 extern Lisp_Object set_buffer_if_live (Lisp_Object);
 extern Lisp_Object other_buffer_safely (Lisp_Object);
+extern Lisp_Object Qoverlayp;
 extern Lisp_Object Qpriority, Qwindow, Qbefore_string, Qafter_string;
 extern Lisp_Object get_truename_buffer (Lisp_Object);
 extern struct buffer *all_buffers;
@@ -3015,10 +3527,10 @@
 void synchronize_system_messages_locale (void);
 void synchronize_system_time_locale (void);
 #else
-#define setlocale(category, locale)
-#define fixup_locale()
-#define synchronize_system_messages_locale()
-#define synchronize_system_time_locale()
+static inline char *setlocale (int cat, char const *locale) { return 0; }
+static inline void fixup_locale (void) {}
+static inline void synchronize_system_messages_locale (void) {}
+static inline void synchronize_system_time_locale (void) {}
 #endif
 void shut_down_emacs (int, int, Lisp_Object);
 /* Nonzero means don't do interactive redisplay and don't change tty modes.  */
@@ -3281,19 +3793,19 @@
    in addition to a device separator.  Set the path separator
    to '/', and don't test for a device separator in IS_ANY_SEP.  */
 
-#define DIRECTORY_SEP '/'
+enum { DIRECTORY_SEP = '/' };
 #ifndef IS_DIRECTORY_SEP
-#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
+static inline int IS_DIRECTORY_SEP (int c) { return c == DIRECTORY_SEP; }
 #endif
 #ifndef IS_DEVICE_SEP
 #ifndef DEVICE_SEP
-#define IS_DEVICE_SEP(_c_) 0
+static inline int IS_DEVICE_SEP (int c) { return 0; }
 #else
-#define IS_DEVICE_SEP(_c_) ((_c_) == DEVICE_SEP)
+static inline int IS_DEVICE_SEP (int c) { return c == DEVICE_SEP; }
 #endif
 #endif
 #ifndef IS_ANY_SEP
-#define IS_ANY_SEP(_c_) (IS_DIRECTORY_SEP (_c_))
+static inline int IS_ANY_SEP (int c) { return IS_DIRECTORY_SEP (c); }
 #endif
 
 #define SWITCH_ENUM_CAST(x) (x)
@@ -3313,15 +3825,6 @@
 # define lint_assume(cond) ((void) (0 && (cond)))
 #endif
 
-/* The ubiquitous min and max macros.  */
-
-#ifdef max
-#undef max
-#undef min
-#endif
-#define min(a, b)	((a) < (b) ? (a) : (b))
-#define max(a, b)	((a) > (b) ? (a) : (b))
-
 /* We used to use `abs', but that clashes with system headers on some
    platforms, and using a name reserved by Standard C is a bad idea
    anyway.  */
@@ -3364,7 +3867,7 @@
 /* SAFE_ALLOCA normally allocates memory on the stack, but if size is
    larger than MAX_ALLOCA, use xmalloc to avoid overflowing the stack.  */
 
-#define MAX_ALLOCA 16*1024
+enum { MAX_ALLOCA = 16*1024 };
 
 extern Lisp_Object safe_alloca_unwind (Lisp_Object);
 
@@ -3433,7 +3936,4 @@
       memory_full (SIZE_MAX);				  \
   } while (0)
 
-
-#include "globals.h"
-
 #endif /* EMACS_LISP_H */

=== modified file 'src/mem-limits.h'
--- src/mem-limits.h	2012-07-09 16:38:45 +0000
+++ src/mem-limits.h	2012-07-13 03:37:42 +0000
@@ -36,9 +36,7 @@
 extern char *start_of_data (void) ATTRIBUTE_CONST;
 #if USE_LSB_TAG || UINTPTR_MAX <= VAL_MAX
 #define EXCEEDS_LISP_PTR(ptr) 0
-#elif defined DATA_SEG_BITS
+#else
 #define EXCEEDS_LISP_PTR(ptr) \
   (((uintptr_t) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
-#else
-#define EXCEEDS_LISP_PTR(ptr) ((uintptr_t) (ptr) >> VALBITS)
 #endif

=== modified file 'src/window.c'
--- src/window.c	2012-07-10 16:53:26 +0000
+++ src/window.c	2012-07-13 03:37:42 +0000
@@ -51,8 +51,8 @@
 #include "nsterm.h"
 #endif
 
-Lisp_Object Qwindowp, Qwindow_live_p;
-static Lisp_Object Qwindow_configuration_p, Qrecord_window_buffer;
+Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p;
+static Lisp_Object Qrecord_window_buffer;
 static Lisp_Object Qwindow_deletable_p, Qdelete_window, Qdisplay_buffer;
 static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
 static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;

=== modified file 'src/window.h'
--- src/window.h	2012-07-05 15:20:12 +0000
+++ src/window.h	2012-07-13 03:37:42 +0000
@@ -885,7 +885,7 @@
 
 /* These used to be in lisp.h.  */
 
-extern Lisp_Object Qwindowp, Qwindow_live_p;
+extern Lisp_Object Qwindow_live_p;
 extern Lisp_Object Vwindow_list;
 
 extern int compare_window_configurations (Lisp_Object, Lisp_Object, int);
@@ -900,4 +900,17 @@
 extern void syms_of_window (void);
 extern void keys_of_window (void);
 
+/* CHECK_LIVE_WINDOW rejects windows on the interior of the window tree as
+   "dead", which is what we want; this is an argument-checking function, and
+   the user should never get access to interior windows.
+
+   A window of any sort, leaf or interior, is dead if the buffer,
+   vchild, and hchild members are all nil.  */
+static inline void
+CHECK_LIVE_WINDOW (Lisp_Object x)
+{
+  CHECK_TYPE (WINDOWP (x) && !NILP (XWINDOW (x)->buffer), Qwindow_live_p, x);
+}
+
+
 #endif /* not WINDOW_H_INCLUDED */




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sat, 14 Jul 2012 02:26:01 GMT) Full text and rfc822 format available.

Message #8 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: [TRUNCATED MESSAGE 2746 87596] bug#11935: XINT etc. should be
	functions
Date: Fri, 13 Jul 2012 22:20:14 -0400
    In the old days Emacs had to use macros for this sort of
    thing, because C compilers generated significantly faster
    code with macros.  Modern C compilers, however, don't have
    this problem.

That could be true if the functions are inlined.
How does this change affect performance with -O0?

--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 15 Jul 2012 13:48:01 GMT) Full text and rfc822 format available.

Message #11 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: rms <at> gnu.org
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 15 Jul 2012 06:41:41 -0700
On 07/13/2012 07:20 PM, Richard Stallman wrote:
> How does this change affect performance with -O0?

It hurts it.  In normal operation I don't notice --
everything is plenty fast enough -- but in an artificial
benchmark designed to stress the new code (see below) the
performance is significantly worse.  If this is an issue,
we can mark these new functions with __attribute__
((__always_inline__)), but I'm inclined to try things
without this attribute, and resort to the attribute only if
needed.

I did two measures of performance.  "text" simply counts the
number of bytes in the text segment.  "bench" counts the
number of CPU seconds consumed by running the benchmark
described below.  "current" refers to trunk bzr 109093, and
"patched" to that bzr after the proposed patch is applied.
In both cases I've normalized the numbers to the current
default (so it scores as 1), and smaller numbers are better.

text   bench
1.000   1.00   current (default optimization)
0.995   0.99   patched (default optimization)
1.332   1.82   current (-O0)
1.410  11.86   patched (-O0)

My benchmark was (benchmark 100000), with the following
code, byte-compiled.  My platform is Fedora 15 x86-64,
compiled with GCC 4.7.1.  Benchmark timings are sloppy, as
usual, so I wouldn't attach much significance past the first
couple of digits.

(defvar longlist '(a b c d e f g h i j k l m n o p q r s t u v w x y z))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(setq longlist (append longlist longlist))
(defvar x)

(defun benchmark-with (n)
  (let ((start (float-time (get-internal-run-time)))
	(v (make-vector 1 0))
	(i 0))
    (while (< i n)
      (setq x (nth 8000 longlist))
      (setq i (1+ i)))
    (- (float-time (get-internal-run-time)) start)))

(defun benchmark-without (n)
  (let ((start (float-time (get-internal-run-time)))
	(v (make-vector 1 0))
	(i 0))
    (while (< i n)
      (setq i (1+ i)))
    (- (float-time (get-internal-run-time)) start)))

(defun benchmark (n)
  (- (benchmark-with n)
     (benchmark-without n)))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 15 Jul 2012 14:48:02 GMT) Full text and rfc822 format available.

Message #14 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 15 Jul 2012 22:41:41 +0800
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> Here's a patch I plan to install after some more testing.  It changes
> lisp.h to prefer functions to function-like macros, and constants to
> object-like macros, when either will do.

I think this is too fundamental a change for 24.2.  Please don't
install.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 15 Jul 2012 16:47:02 GMT) Full text and rfc822 format available.

Message #17 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Chong Yidong <cyd <at> gnu.org>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 15 Jul 2012 09:40:35 -0700
On 07/15/2012 07:41 AM, Chong Yidong wrote:
> I think this is too fundamental a change for 24.2.

I wasn't planning to install it into the emacs-24
branch; only the trunk.  Is 24.2 going to
come from the emacs-24 branch?  If so, what would
be the problem with making this change to the trunk?
And if not, then where should post-24 changes go?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 15 Jul 2012 22:13:02 GMT) Full text and rfc822 format available.

Message #20 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 15 Jul 2012 18:06:16 -0400
>> How does this change affect performance with -O0?

> It hurts it.  In normal operation I don't notice --
> everything is plenty fast enough -- but in an artificial
> benchmark designed to stress the new code (see below) the
> performance is significantly worse.  If this is an issue,
> we can mark these new functions with __attribute__
> ((__always_inline__)), but I'm inclined to try things
> without this attribute, and resort to the attribute only if
> needed.

I always run with -O0 (plus ENABLE_CHECKING, and to add insult to
injury, on Atom-level platforms), so I'd appreciate if you could ensure
those functions are inlined even in -O0.

> 1.332   1.82   current (-O0)
> 1.410  11.86   patched (-O0)

That would really hurt: my Emacs sessions already tend to feel sluggish
without this extra pain.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 02:29:02 GMT) Full text and rfc822 format available.

Message #23 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 10:22:48 +0800
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> I wasn't planning to install it into the emacs-24 branch; only the
> trunk.  Is 24.2 going to come from the emacs-24 branch?

No, from the trunk.  I've explained this several times on emacs-devel,
but maybe you missed those messages.  The emacs-24 branch is only in
case of emergency (e.g. security) release.  Otherwise, 24.2 will be from
the trunk; it will include new features, i.e. it won't be a bugfix-only
release.  But this change could be rather disruptive, for apparently
negligible gain, so better leave it out, I think.

> And if not, then where should post-24 changes go?

You can make a new branch, if you like, or just keep this as a bug in
the BTS.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 15:01:02 GMT) Full text and rfc822 format available.

Message #26 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 11935 <at> debbugs.gnu.org, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 07:54:07 -0700
On 07/15/2012 03:06 PM, Stefan Monnier wrote:
> I always run with -O0 (plus ENABLE_CHECKING, and to add insult to
> injury, on Atom-level platforms), so I'd appreciate if you could ensure
> those functions are inlined even in -O0.

That's easy enough to arrange, without being intrusive --
it would add maybe 10 lines to the patch.

Although the benchmark numbers are a bit scary, they greatly
exaggerate the real-life performance effect,
because most of Emacs's CPU time is spent elsewhere.
I just now ran Emacs with the patch compiled with -g -O0,
on my main laptop, which is also quite limited and slow
(Pentium M 1.86 GHz, circa 2005), and interactive performance
was fine.  Your mileage may vary, of course, but it might
make sense to not inline those functions even with -O0.
There are important advantages to not inlining: you can put
breakpoints on them, for example.  So it might make sense to
inline them only as an option.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 15:01:03 GMT) Full text and rfc822 format available.

Message #29 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Chong Yidong <cyd <at> gnu.org>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 07:54:55 -0700
On 07/15/2012 07:22 PM, Chong Yidong wrote:

> You can make a new branch, if you like, or just keep this as a bug in
> the BTS.

Thanks, I think I'll just keep it as a bug then.

And thanks for patiently explaining the plan one more time
-- I had read the earlier messages but clearly they did not
sink in.






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 16:19:02 GMT) Full text and rfc822 format available.

Message #32 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org, monnier <at> IRO.UMontreal.CA, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 19:12:14 +0300
> Date: Mon, 16 Jul 2012 07:54:07 -0700
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Cc: 11935 <at> debbugs.gnu.org, rms <at> gnu.org
> 
> There are important advantages to not inlining: you can put
> breakpoints on them, for example.

Why would we need to put a breakpoint on a function that replaces the
XINT macro?  We've lived with a macro (where you cannot put a
breakpoint) for many years without any problems (AFAIK).  We have
debugger commands to display values of Lisp integers.  So I don't
think debuggability will be a problem in this particular case
(although it might be in others).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 18:26:01 GMT) Full text and rfc822 format available.

Message #35 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Richard Stallman <rms <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 14:19:36 -0400
    It hurts it.  In normal operation I don't notice --
    everything is plenty fast enough

My machine is a lot slower than yours; I think this will be a big
problem.  Please set them up to always inline.  There can be
a macro switch to turn that off with -D.

--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 21:47:01 GMT) Full text and rfc822 format available.

Message #38 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 11935 <at> debbugs.gnu.org, monnier <at> IRO.UMontreal.CA, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 14:40:34 -0700
On 07/16/2012 09:12 AM, Eli Zaretskii wrote:
> Why would we need to put a breakpoint on a function that replaces the
> XINT macro?

I was thinking more of larger macros like CHAR_TABLE_REF_ASCII,
where it can be helpful to step through the interior loop.
This cannot be done easily right now -- I typically drop into
machine code, which is painful.

Even for XINT, it can be helpful (for a beginner, anyway) to step
through a function, for example, to see what happens with integers
that are out of range for Emacs fixnums.  I know that Emacs has
gdb macros that substitute for straightforward commands to print
expressions, and these are useful for the long-time Emacs experts who
know about them, but it'd be nicer if debugging also worked in the
usual way without requiring this additional expertise.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 16 Jul 2012 22:53:02 GMT) Full text and rfc822 format available.

Message #41 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: rms <at> gnu.org
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 15:46:31 -0700
On 07/16/2012 11:19 AM, Richard Stallman wrote:

> Please set them up to always inline.  There can be
> a macro switch to turn that off with -D.

Sure, that's easy.  I plan to incorporate something like the patch
below, which uses -DINLINING=0 to turn it off (default is INLINING=1).

=== modified file 'ChangeLog'
--- ChangeLog	2012-07-16 06:49:45 +0000
+++ ChangeLog	2012-07-16 22:35:32 +0000
@@ -3,6 +3,9 @@
 	Use functions, not macros, for XINT etc.
 	* configure.ac (WARN_CFLAGS): Remove -Wbad-function-cast,
 	as it generates bogus warnings about reasonable casts of calls.
+	(ALWAYS_INLINE): New macro.
+	(inline): Define to 'ALWAYS_INLINE' when compiling with GCC without
+	optimization, and without -DINLINING=0.
 
 2012-07-15  Paul Eggert  <eggert <at> cs.ucla.edu>
 

=== modified file 'configure.ac'
--- configure.ac	2012-07-15 00:33:12 +0000
+++ configure.ac	2012-07-16 22:21:37 +0000
@@ -4238,6 +4238,25 @@
 #include <string.h>
 #include <stdlib.h>
 
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
+# define ALWAYS_INLINE __attribute__ ((__always_inline__))
+#else
+# define ALWAYS_INLINE
+#endif
+
+/* When compiling via GCC without optimization, and without -DINLINING=0,
+   always inline functions marked 'inline'.  This typically improves CPU
+   performance when debugging.  With optimization, trust the compiler
+   to inline as appropriate.  */
+#ifndef INLINING
+# define INLINING 1
+#endif
+#if (defined __NO_INLINE__ \
+     && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
+     && INLINING && !defined inline)
+# define inline ALWAYS_INLINE
+#endif
+
 #if __GNUC__ >= 3  /* On GCC 3.0 we might get a warning.  */
 #define NO_INLINE __attribute__((noinline))
 #else





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 17 Jul 2012 03:11:01 GMT) Full text and rfc822 format available.

Message #44 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Tue, 17 Jul 2012 06:04:14 +0300
> Date: Mon, 16 Jul 2012 15:46:31 -0700
> From: Paul Eggert <eggert <at> cs.ucla.edu>
> Cc: 11935 <at> debbugs.gnu.org
> 
> +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
> +# define ALWAYS_INLINE __attribute__ ((__always_inline__))
> +#else
> +# define ALWAYS_INLINE
> +#endif
> +
> +/* When compiling via GCC without optimization, and without -DINLINING=0,
> +   always inline functions marked 'inline'.  This typically improves CPU
> +   performance when debugging.  With optimization, trust the compiler
> +   to inline as appropriate.  */
> +#ifndef INLINING
> +# define INLINING 1
> +#endif
> +#if (defined __NO_INLINE__ \
> +     && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
> +     && INLINING && !defined inline)
> +# define inline ALWAYS_INLINE
> +#endif
> +

Wouldn't this inline all the functions declared 'inline'?  If so,
that's going too far, IMO.  I think we need a facility for doing this
only with a few functions that affect performance.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 17 Jul 2012 04:01:01 GMT) Full text and rfc822 format available.

Message #47 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 11935 <at> debbugs.gnu.org, rms <at> gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 16 Jul 2012 20:54:12 -0700
On 07/16/2012 08:04 PM, Eli Zaretskii wrote:
> Wouldn't this inline all the functions declared 'inline'?

No, only the functions defined after the macro.
<string.h> functions, for example, are unaffected.

> I think we need a facility for doing this
> only with a few functions that affect performance.

I considered that (with a macro "Inline"), but it'd complicate
maintenance.  I hope that the simpler approach is good enough.
If not, we can revisit this, and quite possibly if we do that
we'll do "Inline" or something like it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 24 Jul 2012 02:28:01 GMT) Full text and rfc822 format available.

Message #50 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Mon, 23 Jul 2012 19:20:07 -0700
[Message part 1 (text/plain, inline)]
On 07/16/2012 08:04 PM, Eli Zaretskii wrote:
> we need a facility for doing this
> only with a few functions that affect performance.

It turns out that when compiling with -O0, always_inline
functions are often slower than macros, as the inlined code
also contains unnecessary instructions to copy arguments and
results.  So instead of using always_inline, it's better to
do this performance-critical inlining by hand.  I did that
(patch relative to trunk bzr 109195 attached), inlining
enough so that CPU performance improved by 8.7% compared to
the current trunk, when compiled with gcc -O0.  (This is the
same benchmark as before, on x86-64 with GCC 4.7.1.)  The
performance win is because I inlined a bit more cleverly
than the current code does.

Like the earlier version, this patch should improve
performance slightly in the default-optimization case too,
since this patch is identical to the earlier one when
default optimization is used.

In short, it should take only a relatively small amount of
hand-inlining to address the -O0 performance issue.

[inline-diff.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 24 Jul 2012 09:15:01 GMT) Full text and rfc822 format available.

Message #53 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Tue, 24 Jul 2012 05:07:39 -0400
> results.  So instead of using always_inline, it's better to
> do this performance-critical inlining by hand.  I did that

Could you separate this part of the patch, since I don't know what you
mean by "inlining by hand".


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 24 Jul 2012 13:53:01 GMT) Full text and rfc822 format available.

Message #56 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Tue, 24 Jul 2012 06:45:27 -0700
[Message part 1 (text/plain, inline)]
On 07/24/2012 02:07 AM, Stefan Monnier wrote:
> Could you separate this part of the patch, since I don't know what you
> mean by "inlining by hand".

Sure, attached; this assumes the earlier patch in
<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11935#5>
has been applied and merged.

[inline-by-hand.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Tue, 24 Jul 2012 22:04:02 GMT) Full text and rfc822 format available.

Message #59 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Tue, 24 Jul 2012 17:57:09 -0400
> Sure, attached; this assumes the earlier patch in
> <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11935#5>
> has been applied and merged.

I'm not sure I understand what it does.  It seems to define XLI first as
a macro then as a function.  Is that right?
If so, why is it any better than using only the macro form?


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Wed, 25 Jul 2012 04:15:02 GMT) Full text and rfc822 format available.

Message #62 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Tue, 24 Jul 2012 21:07:28 -0700
On 07/24/2012 02:57 PM, Stefan Monnier wrote:

> It seems to define XLI first as
> a macro then as a function.  Is that right?

Yes.  The macro is purely for performance with -O0.
The function is for all other purposes, including
having XLI work in expressions given to GDB.

> why is it any better than using only the macro form?

Mostly for debuggability, though there's also a small
performance win when compiling with default (-O2)
optimization.  Having the functions makes GDB more useful
when printing expressions.  Here's a trivial example:

  (gdb) p SYMBOLP (Qnil)
  $3 = 1

With the patch, this works if one compiles with -g -O0,
regardless of whether -DINLINING=0 is also specified.
This is because SYMBOLP is defined as a function,
regardless of whether it is also defined as a macro.

Also, having the functions makes backtraces work better,
even when compiling with default optimization.  For example,
here's the start of a GDB backtrace of a patched Emacs
compiled with default optimization:

   (gdb) where
   #0  XTYPE (a=0) at lisp.h:461
   #1  VECTORLIKEP (x=0) at lisp.h:2018
   #2  PSEUDOVECTORP (code=2, a=0) at lisp.h:2080
   #3  PROCESSP (a=0) at lisp.h:2102
   #4  Fget_process (name=0) at process.c:680
   #5  0x0000000000573e87 in eval_sub (form=form <at> entry=16514534) at eval.c:2146
   ...

When the macro forms are used, levels #0 through #3 are lost,
which makes things harder to follow, particularly when one
is not expert in the code.

This debuggability win is partly lost when compiling with
plain -O0, because then some functions turn into macros.
But that's OK, since one can compile with -O0 -DINLINING=0
to get nicer debugging.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 06 Jun 2013 16:00:02 GMT) Full text and rfc822 format available.

Message #65 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 06 Jun 2013 08:56:39 -0700
[Message part 1 (text/plain, inline)]
Attached is an updated version of this patch,
relative to the current trunk (bzr 112869).
Since the last version of the patch we've added
several inline functions to lisp.h, such as
specpdl_symbol, make_lisp_proc, SAVE_VALUEP,
and I've merged them all in.  I'd like to apply
this soon.
[inline4.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 06 Jun 2013 16:39:01 GMT) Full text and rfc822 format available.

Message #68 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 06 Jun 2013 18:36:00 +0200
Paul Eggert <eggert <at> cs.ucla.edu> writes:

> -#define CHECK_OVERLAY(x) \
> -  CHECK_TYPE (OVERLAYP (x), Qoverlayp, x)
> +LISP_INLINE void
> +CHECK_OVERLAY (Lisp_Object x)
> +{
> +  CHECK_TYPE (OVERLAYP (x), Qoverlayp, x);
> +}

Since it's only used in buffer.c it should be moved there.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 06 Jun 2013 16:45:02 GMT) Full text and rfc822 format available.

Message #71 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 06 Jun 2013 12:42:05 -0400
> Attached is an updated version of this patch,
> relative to the current trunk (bzr 112869).

Having XCONS and friends duplicated into a macro version and a function
version is a non-starter for me.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 00:53:02 GMT) Full text and rfc822 format available.

Message #74 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sat, 08 Jun 2013 17:52:05 -0700
On 06/06/13 09:42, Stefan Monnier wrote:

> Having XCONS and friends duplicated into a macro version and a function
> version is a non-starter for me.

Yes, I didn't like those macros either.  I'll remove them; they're no
longer needed now that GCC has the -Og option.  In case you haven't
run into it yet, -Og means "optimize for debugging", and causes GCC to
generate code that's easy to debug, without having the big runtime
performance penalty of -O0.

Like -O2 but unlike -O0, with -Og the CPU time for my little Lisp
nthcdr benchmark is unaffected by the proposed patch (assuming those
macros are removed).  C compilation time is considerably faster for
-Og than for -O2; it's not as fast as -O0, but for the common case of
changing one C source file and then typing "make emacs", -Og is faster
than -O0 (because bootstrap-emacs runs faster) and is a tad faster
than -O2 (because the C compiler runs faster).

Here are the detailed times, if you're curious.  I got these on a
Fedora 17 x86-64 (AMD Phenom II X4 910e) that was otherwise unloaded.
I used plain 'make' without parallelism.  Everything was built with
GCC 4.8.1 and with Texinfo 5.1.  All times are user+system CPU times;
the low-order digits of the times aren't that reliable.

		(benchmark  make \    rm fns.o;   rm *.o;    make \
		   100000)   xdisp.o  make emacs  make emacs  bootstrap
  -O0 unpatched    2.89        3.1       12.4        57	       1099
  -O0 patched     21.66        3.0       20.0        63        2442
  -Og unpatched    1.15        5.9        9.2        80	        860
  -Og patched      1.15        6.4        9.5        87	        879
  -O2 unpatched    1.57       11.3        9.6       110		843
  -O2 patched      1.57       11.1        9.9       119	        847

In (benchmark 100000) the -Og code runs faster than -O2, which is
surprising, but I think it's an anomaly; I may find the time to fire
off a performance bug-report to the GCC developers.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 03:06:02 GMT) Full text and rfc822 format available.

Message #77 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sat, 08 Jun 2013 23:04:45 -0400
>> Having XCONS and friends duplicated into a macro version and a function
>> version is a non-starter for me.
> Yes, I didn't like those macros either.  I'll remove them; they're no
> longer needed now that GCC has the -Og option.

Sadly, I don't live in the same era as you do: my gcc doesn't take -Og yet.

>   -O0 unpatched    2.89        3.1       12.4        57	       1099
>   -O0 patched     21.66        3.0       20.0        63        2442

An almost 10 times slowdown for the -O0 case is really problematic.
IOW I think it'll be a fine idea but only when -Og is supported in
Debian stable.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 04:44:02 GMT) Full text and rfc822 format available.

Message #80 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: James Cloos <cloos <at> jhcloos.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 11935 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 09 Jun 2013 00:37:52 -0400
>>>>> "SM" == Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

SM> An almost 10 times slowdown for the -O0 case is really problematic.
SM> IOW I think it'll be a fine idea but only when -Og is supported in
SM> Debian stable.

Jessie has gcc-4.8, so that is just one more freeze/thaw cycle.

However long that takes. :^)

-JimC
-- 
James Cloos <cloos <at> jhcloos.com>         OpenPGP: 1024D/ED7DAEA6




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 06:58:01 GMT) Full text and rfc822 format available.

Message #83 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 9 Jun 2013 08:56:55 +0200
Hello.

9 jun 2013 kl. 02:52 skrev Paul Eggert <eggert <at> cs.ucla.edu>:

> On 06/06/13 09:42, Stefan Monnier wrote:
> 
>> Having XCONS and friends duplicated into a macro version and a function
>> version is a non-starter for me.
> 
> Yes, I didn't like those macros either.  I'll remove them; they're no
> longer needed now that GCC has the -Og option.  In case you haven't
> run into it yet, -Og means "optimize for debugging", and causes GCC to
> generate code that's easy to debug, without having the big runtime
> performance penalty of -O0.

Which version of gcc has this?  Note that most people does not have the latest gcc version.

	Jan D.






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 07:00:02 GMT) Full text and rfc822 format available.

Message #86 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: James Cloos <cloos <at> jhcloos.com>
Cc: 11935 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 9 Jun 2013 08:59:34 +0200
9 jun 2013 kl. 06:37 skrev James Cloos <cloos <at> jhcloos.com>:

>>>>>> "SM" == Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
> 
> SM> An almost 10 times slowdown for the -O0 case is really problematic.
> SM> IOW I think it'll be a fine idea but only when -Og is supported in
> SM> Debian stable.
> 
> Jessie has gcc-4.8, so that is just one more freeze/thaw cycle.
> 
> However long that takes. :^)

Some distibutions will never get gcc 4.8.  Not everybody upgrades to the latest version.
I think it would be a big mistake to introduce a x10 slowdown for pre 4.8 gcc users.

	Jan D.






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 07:14:02 GMT) Full text and rfc822 format available.

Message #89 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 09 Jun 2013 00:13:11 -0700
On 06/08/2013 08:04 PM, Stefan Monnier wrote:
> I think it'll be a fine idea but only when -Og is supported in
> Debian stable.

I'd rather not wait three (or five!) more years to install helpful
changes like this.  I might not live that long.

If it's unacceptable to maintain both a macro and a function
implementation for a few primitives, we can simply have the
latter invoke the former -- that way, there's only one actual
implementation.  Or if you prefer, we can omit the functions
entirely.  We can leave in a FIXME reminding us to
change the macros to functions after the three years or so.

Another option is that you could download and install
GCC 4.8.x on your Debian stable host.  That should
work.  That might be better for Emacs development,
though it'd be a bit more of an effort for you.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 07:24:02 GMT) Full text and rfc822 format available.

Message #92 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Jan Djärv <jan.h.d <at> swipnet.se>
Cc: 11935 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 09 Jun 2013 00:23:21 -0700
On 06/08/2013 11:56 PM, Jan Djärv wrote:
> most people does not have the latest gcc version.

Most people can use older GCC versions just fine,
since by default Emacs builds with optimization flags
that will generate pretty much the same machine code
regardless of whether the patch is used.

The only problem is with developers who are using older
GCC versions and who wish to compile without optimization,
to make Emacs easier to debug.  These folks can't use -Og
(available in GCC 4.8 and later), so they have to make do
with -O0.

-Og is better for debugging than -O0 is, and the
proposed patch caters to -Og.  Eventually the -Og
approach will win out; the only question is when
and how to start the ball rolling.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 09:20:01 GMT) Full text and rfc822 format available.

Message #95 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 9 Jun 2013 11:18:45 +0200
Hello.

9 jun 2013 kl. 09:23 skrev Paul Eggert <eggert <at> cs.ucla.edu>:

> On 06/08/2013 11:56 PM, Jan Djärv wrote:
>> most people does not have the latest gcc version.
> 
> Most people can use older GCC versions just fine,
> since by default Emacs builds with optimization flags
> that will generate pretty much the same machine code
> regardless of whether the patch is used.
> 
> The only problem is with developers who are using older
> GCC versions and who wish to compile without optimization,
> to make Emacs easier to debug.  These folks can't use -Og
> (available in GCC 4.8 and later), so they have to make do
> with -O0.
> 

That is not the only problem.  etc/DEBUG recommends to build with no optimization when reporting errors.

> -Og is better for debugging than -O0 is, and the
> proposed patch caters to -Og.  Eventually the -Og
> approach will win out; the only question is when
> and how to start the ball rolling.

If you can make it detect when to use macros and when to use functions so -O0 doesn't suffer, that is starting the ball rolling.  Otherwise it is setting up a brick wall for users/developers with older gcc.

	Jan D.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 14:27:02 GMT) Full text and rfc822 format available.

Message #98 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Juanma Barranquero <lekktu <at> gmail.com>
To: Jan Djärv <jan.h.d <at> swipnet.se>
Cc: 11935 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 9 Jun 2013 16:25:50 +0200
On Sun, Jun 9, 2013 at 11:18 AM, Jan Djärv <jan.h.d <at> swipnet.se> wrote:

> If you can make it detect when to use macros and when to use functions so
> -O0 doesn't suffer, that is starting the ball rolling.  Otherwise it is setting up
> a brick wall for users/developers with older gcc.

Also, in some environments updating to newer GCC isn't that easy.
There's no MinGW GCC 4.8.1, and I wouldn't bet there will be one for
many months.

   J




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 15:58:02 GMT) Full text and rfc822 format available.

Message #101 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 09 Jun 2013 11:57:23 -0400
>> I think it'll be a fine idea but only when -Og is supported in
>> Debian stable.
> I'd rather not wait three (or five!) more years to install helpful
> changes like this.  I might not live that long.

OTOH we've been using the current macros for so many years that the
change is not exactly urgent.

> If it's unacceptable to maintain both a macro and a function
> implementation for a few primitives, we can simply have the
> latter invoke the former -- that way, there's only one actual
> implementation.

I could live with that.

> Or if you prefer, we can omit the functions entirely.

Sounds even better.

> We can leave in a FIXME reminding us to
> change the macros to functions after the three years or so.

Sure.

> Another option is that you could download and install
> GCC 4.8.x on your Debian stable host.

I'm running Debian testing on most of my machines, so it should get to
4.8 pretty soon, but as others have pointed out, Debian is not the only
problem.  I generally take "Debian stable" as a reference, not because
I use Debian but because it seems that if something is in Debian stable
you can mostly assume it's also available in most other contexts.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sun, 09 Jun 2013 16:06:02 GMT) Full text and rfc822 format available.

Message #104 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Jan Djärv <jan.h.d <at> swipnet.se>
To: Juanma Barranquero <lekktu <at> gmail.com>
Cc: 11935 <at> debbugs.gnu.org, Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 9 Jun 2013 18:05:31 +0200
Hello.

9 jun 2013 kl. 16:25 skrev Juanma Barranquero <lekktu <at> gmail.com>:

> On Sun, Jun 9, 2013 at 11:18 AM, Jan Djärv <jan.h.d <at> swipnet.se> wrote:
> 
>> If you can make it detect when to use macros and when to use functions so
>> -O0 doesn't suffer, that is starting the ball rolling.  Otherwise it is setting up
>> a brick wall for users/developers with older gcc.
> 
> Also, in some environments updating to newer GCC isn't that easy.
> There's no MinGW GCC 4.8.1, and I wouldn't bet there will be one for
> many months.

Another thing to consider are other compilers.  Clang is becoming more common, and is available on all supported platforms (maybe not DOS).  How does it handle -g -O0?  AFAIK, it does not have -Og.

	Jan D.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Mon, 10 Jun 2013 13:42:03 GMT) Full text and rfc822 format available.

Message #107 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Barry OReilly <gundaetiapo <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: bug#11935: XINT etc. should be functions
Date: Mon, 10 Jun 2013 09:40:37 -0400
[Message part 1 (text/plain, inline)]
Man gcc indicates -O* flags are selected sets of finer grained
optimizations. Perhaps if this is so for -Og, it is possible to build an
efficient and debug-friendly Emacs with older versions of GCC by specifying
the right set of finer grained optimization flags.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 13 Jun 2013 14:46:01 GMT) Full text and rfc822 format available.

Message #110 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 13 Jun 2013 07:45:16 -0700
[Message part 1 (text/plain, inline)]
On 06/09/13 08:57, Stefan Monnier wrote:
>> > If it's unacceptable to maintain both a macro and a function
>> > implementation for a few primitives, we can simply have the
>> > latter invoke the former -- that way, there's only one actual
>> > implementation.
> I could live with that.

OK, attached is a patch to do that.  I think this is a bit better than
a macro-only implementation as it makes the way forward clearer for
a few years from now, when we can assume GCC 4.8 or later.

This fixes the -O0 performance problem, so developers using pre-4.8
GCC (or clang) won't suffer.  Here are the measurements, where "old
patch" refers to the previous version of the patch with the XINT
etc. macros removed, and "new patch" refers to the attached.  The
benchmark is the same as before.  As before, the low-order digits
probably aren't that significant.

Fedora 17 x86-64, AMD Phenom II X4 910e
Clang 3.0 (Fedora 17)
GCC 4.8.1 (I built it)
single-process make (no -j)

		    (benchmark  make \    rm fns.o;   rm *.o;    make \
		       100000)   xdisp.o  make emacs  make emacs  bootstrap
GCC   -O2 unpatched    1.57       11.3        9.6       110          843
GCC   -O2 old patch    1.57       11.1        9.9       119	     847
GCC   -O2 new patch    1.38	  10.9	      9.9	118	     850
GCC   -Og unpatched    1.15        5.9        9.2        80          860
GCC   -Og old patch    1.15        6.4        9.5        87          879
GCC   -Og new patch    1.15	   6.4	      9.5	 86	     874
GCC   -O0 unpatched    2.89        3.1       12.4        57         1099
GCC   -O0 old patch   21.66        3.0       20.0        63         2442
GCC   -O0 new patch    2.89	   2.9	     13.2	 56	    1265
Clang -O2 unpatched    1.57	   6.3	      8.3	 65	     818
Clang -O2 old patch    1.34	   6.8	      8.5	 70	     826
Clang -O2 new patch    1.34	   6.8	      8.5	 70	     830
Clang -O0 unpatched    3.72        1.5       10.9	 34	    1159
Clang -O0 old patch   17.89	   1.4	     17.0	 39	    2309
Clang -O0 new patch    3.92	   1.4	     11.8	 34	    1332

[inline4n.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 13 Jun 2013 16:31:02 GMT) Full text and rfc822 format available.

Message #113 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 13 Jun 2013 09:30:25 -0700
[Message part 1 (text/plain, inline)]
On 06/06/13 09:36, Andreas Schwab wrote:
> Since it's only used in buffer.c it should be moved there.

Yes, that's a win, as it makes it clearer to the human
reader that the function is used and needed only by one
module, and it simplifies lisp.h.  Attached is a patch to do that
systematically for lisp.h; it assumes the patch I sent out earlier today
<http://bugs.gnu.org/11935#110>.  A side effect is that
this gives GCC -O2 a bit more chance to optimize, shrinking
the executable by 3k on my x86-64 platform.

[inline4o.diff (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Thu, 13 Jun 2013 22:49:02 GMT) Full text and rfc822 format available.

Message #116 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Thu, 13 Jun 2013 16:08:08 -0400
> +   the operation's implementation.  That way, OP can be implementated
                                                           ^^^^^^^^^^^^^
                                                           implemented

> +LISP_INLINE bool
> +(LISP_INT_TAG_P) (int x)
> +{
> +  return lisp_h_LISP_INT_TAG_P (x);
> +}

Can't we use something like

#define FUNCTION_OF_MACRO(fun, type_in, type_out) \
  LISP_INLINE type_out (fun) (type_in x) { return lisp_h_##fun (x); }

[ I guess it depends on whether the args to FUNCTION_OF_MACRO get
  macro-expanded before or after expanding the macro. ]

Other than that, it looks OK for me,


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sat, 15 Jun 2013 06:44:02 GMT) Full text and rfc822 format available.

Message #119 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Fri, 14 Jun 2013 23:43:30 -0700
[Message part 1 (text/plain, inline)]
On 06/13/2013 01:08 PM, Stefan Monnier wrote:
> Can't we use something like
> 
> #define FUNCTION_OF_MACRO(fun, type_in, type_out) \
>   LISP_INLINE type_out (fun) (type_in x) { return lisp_h_##fun (x); }

Sure, though we need to adjust that a bit,
as the function can take multiple args, and it might return
void (where the 'return' keyword must be omitted).

The following variant works for me, and the attached combined
patch implements this suggestion.

/* Define NAME as a lisp.h inline function that returns TYPE and has
   arguments declared as ARGDECLS and passed as ARGS.  ARGDECLS and
   ARGS should be parenthesized.  Implement the function by calling
   lisp_h_NAME ARGS.  */
#define LISP_MACRO_DEFUN(name, type, argdecls, args) \
  LISP_INLINE type (name) argdecls { return lisp_h_##name args; }

/* like LISP_MACRO_DEFUN, except NAME returns void.  */
#define LISP_MACRO_DEFUN_VOID(name, argdecls, args) \
  LISP_INLINE void (name) argdecls { lisp_h_##name args; }

[inline4o.txt (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#11935; Package emacs. (Sat, 15 Jun 2013 14:23:02 GMT) Full text and rfc822 format available.

Message #122 received at 11935 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: 11935 <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sat, 15 Jun 2013 10:22:39 -0400
> The following variant works for me, and the attached combined
> patch implements this suggestion.

Looks OK to me, thank you,


        Stefan




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Mon, 17 Jun 2013 06:06:02 GMT) Full text and rfc822 format available.

Notification sent to Paul Eggert <eggert <at> cs.ucla.edu>:
bug acknowledged by developer. (Mon, 17 Jun 2013 06:06:02 GMT) Full text and rfc822 format available.

Message #127 received at 11935-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 11935-done <at> debbugs.gnu.org
Subject: Re: bug#11935: XINT etc. should be functions
Date: Sun, 16 Jun 2013 23:05:18 -0700
On 06/15/2013 07:22 AM, Stefan Monnier wrote:
> Looks OK to me, thank you,

OK, I installed that as trunk bzr 113012
and am marking this as done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 15 Jul 2013 11:24:05 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Kyle Brodie <kylecbrodie <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 15 Mar 2020 02:46:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 12 Apr 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 15 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.