summaryrefslogtreecommitdiff
path: root/src/lisp.h
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-04-29 00:54:43 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-04-29 00:54:43 -0700
commit8ac068ac0c00afa85bc4df54032b7a855c639312 (patch)
tree551b5146f8f0c9e5c2f7129eaac0fb9f97d8a866 /src/lisp.h
parentc7b270ab8559d9c9ca86ed5887b86b537796042d (diff)
downloademacs-8ac068ac0c00afa85bc4df54032b7a855c639312.tar.gz
emacs-8ac068ac0c00afa85bc4df54032b7a855c639312.tar.bz2
emacs-8ac068ac0c00afa85bc4df54032b7a855c639312.zip
Prefer intptr_t/uintptr_t for integers the same widths as pointers.
This removes an assumption that EMACS_INT and long are the same width as pointers. The assumption is true for Emacs porting targets now, but we want to make other targets possible. * lisp.h: Include <inttypes.h>, for INTPTR_MAX, UINTPTR_MAX. (EMACS_INTPTR, EMACS_UINTPTR): New macros. In the rest of the code, change types of integers that hold casted pointers to EMACS_INTPTR and EMACS_UINTPTR, systematically replacing EMACS_INT, long, EMACS_UINT, and unsigned long. (XTYPE): Don't cast arg to EMACS_UINT; normally is not needed. (XSET): Cast type of XTYPE arg to EMACS_INTPTR; it is needed here. No need to cast type when ORing. (XPNTR): Return a value of type EMACS_INTPTR or EMACS_UINTPTR. * alloc.c (lisp_align_malloc): Remove a no-longer-needed cast. * doc.c (store_function_docstring): Use EMACS_INTPTR, so as not to assume EMACS_INT is the same width as char *. * gtkutil.c (xg_gtk_scroll_destroy, xg_tool_bar_button_cb): (xg_tool_bar_callback, xg_tool_bar_help_callback, xg_make_tool_item): Remove no-longer-needed casts. (xg_create_scroll_bar, xg_tool_bar_button_cb, xg_tool_bar_callback): (xg_tool_bar_help_callback, xg_make_tool_item): Use EMACS_INTPTR to hold an integer that will be cast to void *; this can avoid a GCC warning if EMACS_INT is not the same width as void *. * menu.c (find_and_call_menu_selection): Remove no-longer-needed cast. * xdisp.c (display_echo_area_1, resize_mini_window_1): (current_message_1, set_message_1): Use a local to convert to proper width without a cast. * xmenu.c (dialog_selection_callback): Likewise.
Diffstat (limited to 'src/lisp.h')
-rw-r--r--src/lisp.h39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/lisp.h b/src/lisp.h
index dca3b4d9a32..a8cf38f6669 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <stdarg.h>
#include <stddef.h>
+#include <inttypes.h>
/* Use the configure flag --enable-checking[=LIST] to enable various
types of run time checks for Lisp objects. */
@@ -54,6 +55,18 @@ extern void check_cons_list (void);
#endif
#endif
+/* Integers large enough to hold casted pointers without losing info. */
+#ifdef INTPTR_MAX
+# define EMACS_INTPTR intptr_t
+#else
+# define EMACS_INTPTR EMACS_INT
+#endif
+#ifdef UINTPTR_MAX
+# define EMACS_UINTPTR uintptr_t
+#else
+# define EMACS_UINTPTR EMACS_UINT
+#endif
+
/* Extra internal type checking? */
#ifdef ENABLE_CHECKING
@@ -398,7 +411,7 @@ enum pvec_type
#ifdef USE_LSB_TAG
#define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1)
-#define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK))
+#define XTYPE(a) ((enum Lisp_Type) ((a) & TYPEMASK))
#ifdef USE_2_TAGS_FOR_INTS
# define XINT(a) (((EMACS_INT) (a)) >> (GCTYPEBITS - 1))
# define XUINT(a) (((EMACS_UINT) (a)) >> (GCTYPEBITS - 1))
@@ -408,11 +421,11 @@ enum pvec_type
# define XUINT(a) (((EMACS_UINT) (a)) >> GCTYPEBITS)
# define make_number(N) (((EMACS_INT) (N)) << GCTYPEBITS)
#endif
-#define XSET(var, type, ptr) \
- (eassert (XTYPE (ptr) == 0), /* Check alignment. */ \
- (var) = ((EMACS_INT) (type)) | ((EMACS_INT) (ptr)))
+#define XSET(var, type, ptr) \
+ (eassert (XTYPE ((EMACS_INTPTR) (ptr)) == 0), /* Check alignment. */ \
+ (var) = (type) | (EMACS_INTPTR) (ptr))
-#define XPNTR(a) ((EMACS_INT) ((a) & ~TYPEMASK))
+#define XPNTR(a) ((EMACS_INTPTR) ((a) & ~TYPEMASK))
#else /* not USE_LSB_TAG */
@@ -446,14 +459,14 @@ enum pvec_type
#define XSET(var, type, ptr) \
((var) = ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS) \
- + ((EMACS_INT) (ptr) & VALMASK)))
+ + ((EMACS_INTPTR) (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) ((EMACS_UINT) (((a) & VALMASK) | DATA_SEG_BITS))
+#define XPNTR(a) ((EMACS_UINTPTR) (((a) & VALMASK)) | DATA_SEG_BITS))
#else
-#define XPNTR(a) ((EMACS_UINT) ((a) & VALMASK))
+#define XPNTR(a) ((EMACS_UINTPTR) ((a) & VALMASK))
#endif
#endif /* not USE_LSB_TAG */
@@ -479,7 +492,7 @@ enum pvec_type
/* Some versions of gcc seem to consider the bitfield width when issuing
the "cast to pointer from integer of different size" warning, so the
cast is here to widen the value back to its natural size. */
-# define XPNTR(v) ((EMACS_INT)((v).s.val) << GCTYPEBITS)
+# define XPNTR(v) ((EMACS_INTPTR) (v).s.val << GCTYPEBITS)
#else /* !USE_LSB_TAG */
@@ -495,9 +508,9 @@ enum pvec_type
#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) (XUINT (a) | DATA_SEG_BITS)
+#define XPNTR(a) ((EMACS_INTPTR) (XUINT (a) | DATA_SEG_BITS))
#else
-#define XPNTR(a) ((EMACS_INT) XUINT (a))
+#define XPNTR(a) ((EMACS_INTPTR) XUINT (a))
#endif
#endif /* !USE_LSB_TAG */
@@ -1814,8 +1827,8 @@ typedef struct {
XSETCDR ((x), tmp); \
} while (0)
-/* Cast pointers to this type to compare them. Some machines want int. */
-#define PNTR_COMPARISON_TYPE EMACS_UINT
+/* Cast pointers to this type to compare them. */
+#define PNTR_COMPARISON_TYPE EMACS_UINTPTR
/* Define a built-in function for calling from Lisp.
`lname' should be the name to give the function in Lisp,