aboutsummaryrefslogtreecommitdiffstats
path: root/src/lisp.h
diff options
context:
space:
mode:
authorPaul Eggert2011-04-29 00:54:43 -0700
committerPaul Eggert2011-04-29 00:54:43 -0700
commit8ac068ac0c00afa85bc4df54032b7a855c639312 (patch)
tree551b5146f8f0c9e5c2f7129eaac0fb9f97d8a866 /src/lisp.h
parentc7b270ab8559d9c9ca86ed5887b86b537796042d (diff)
downloademacs-8ac068ac0c00afa85bc4df54032b7a855c639312.tar.gz
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/>. */
22 22
23#include <stdarg.h> 23#include <stdarg.h>
24#include <stddef.h> 24#include <stddef.h>
25#include <inttypes.h>
25 26
26/* Use the configure flag --enable-checking[=LIST] to enable various 27/* Use the configure flag --enable-checking[=LIST] to enable various
27 types of run time checks for Lisp objects. */ 28 types of run time checks for Lisp objects. */
@@ -54,6 +55,18 @@ extern void check_cons_list (void);
54#endif 55#endif
55#endif 56#endif
56 57
58/* Integers large enough to hold casted pointers without losing info. */
59#ifdef INTPTR_MAX
60# define EMACS_INTPTR intptr_t
61#else
62# define EMACS_INTPTR EMACS_INT
63#endif
64#ifdef UINTPTR_MAX
65# define EMACS_UINTPTR uintptr_t
66#else
67# define EMACS_UINTPTR EMACS_UINT
68#endif
69
57/* Extra internal type checking? */ 70/* Extra internal type checking? */
58 71
59#ifdef ENABLE_CHECKING 72#ifdef ENABLE_CHECKING
@@ -398,7 +411,7 @@ enum pvec_type
398#ifdef USE_LSB_TAG 411#ifdef USE_LSB_TAG
399 412
400#define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1) 413#define TYPEMASK ((((EMACS_INT) 1) << GCTYPEBITS) - 1)
401#define XTYPE(a) ((enum Lisp_Type) (((EMACS_UINT) (a)) & TYPEMASK)) 414#define XTYPE(a) ((enum Lisp_Type) ((a) & TYPEMASK))
402#ifdef USE_2_TAGS_FOR_INTS 415#ifdef USE_2_TAGS_FOR_INTS
403# define XINT(a) (((EMACS_INT) (a)) >> (GCTYPEBITS - 1)) 416# define XINT(a) (((EMACS_INT) (a)) >> (GCTYPEBITS - 1))
404# define XUINT(a) (((EMACS_UINT) (a)) >> (GCTYPEBITS - 1)) 417# define XUINT(a) (((EMACS_UINT) (a)) >> (GCTYPEBITS - 1))
@@ -408,11 +421,11 @@ enum pvec_type
408# define XUINT(a) (((EMACS_UINT) (a)) >> GCTYPEBITS) 421# define XUINT(a) (((EMACS_UINT) (a)) >> GCTYPEBITS)
409# define make_number(N) (((EMACS_INT) (N)) << GCTYPEBITS) 422# define make_number(N) (((EMACS_INT) (N)) << GCTYPEBITS)
410#endif 423#endif
411#define XSET(var, type, ptr) \ 424#define XSET(var, type, ptr) \
412 (eassert (XTYPE (ptr) == 0), /* Check alignment. */ \ 425 (eassert (XTYPE ((EMACS_INTPTR) (ptr)) == 0), /* Check alignment. */ \
413 (var) = ((EMACS_INT) (type)) | ((EMACS_INT) (ptr))) 426 (var) = (type) | (EMACS_INTPTR) (ptr))
414 427
415#define XPNTR(a) ((EMACS_INT) ((a) & ~TYPEMASK)) 428#define XPNTR(a) ((EMACS_INTPTR) ((a) & ~TYPEMASK))
416 429
417#else /* not USE_LSB_TAG */ 430#else /* not USE_LSB_TAG */
418 431
@@ -446,14 +459,14 @@ enum pvec_type
446 459
447#define XSET(var, type, ptr) \ 460#define XSET(var, type, ptr) \
448 ((var) = ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS) \ 461 ((var) = ((EMACS_INT) ((EMACS_UINT) (type) << VALBITS) \
449 + ((EMACS_INT) (ptr) & VALMASK))) 462 + ((EMACS_INTPTR) (ptr) & VALMASK)))
450 463
451#ifdef DATA_SEG_BITS 464#ifdef DATA_SEG_BITS
452/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers 465/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
453 which were stored in a Lisp_Object */ 466 which were stored in a Lisp_Object */
454#define XPNTR(a) ((EMACS_UINT) (((a) & VALMASK) | DATA_SEG_BITS)) 467#define XPNTR(a) ((EMACS_UINTPTR) (((a) & VALMASK)) | DATA_SEG_BITS))
455#else 468#else
456#define XPNTR(a) ((EMACS_UINT) ((a) & VALMASK)) 469#define XPNTR(a) ((EMACS_UINTPTR) ((a) & VALMASK))
457#endif 470#endif
458 471
459#endif /* not USE_LSB_TAG */ 472#endif /* not USE_LSB_TAG */
@@ -479,7 +492,7 @@ enum pvec_type
479/* Some versions of gcc seem to consider the bitfield width when issuing 492/* Some versions of gcc seem to consider the bitfield width when issuing
480 the "cast to pointer from integer of different size" warning, so the 493 the "cast to pointer from integer of different size" warning, so the
481 cast is here to widen the value back to its natural size. */ 494 cast is here to widen the value back to its natural size. */
482# define XPNTR(v) ((EMACS_INT)((v).s.val) << GCTYPEBITS) 495# define XPNTR(v) ((EMACS_INTPTR) (v).s.val << GCTYPEBITS)
483 496
484#else /* !USE_LSB_TAG */ 497#else /* !USE_LSB_TAG */
485 498
@@ -495,9 +508,9 @@ enum pvec_type
495#ifdef DATA_SEG_BITS 508#ifdef DATA_SEG_BITS
496/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers 509/* DATA_SEG_BITS forces extra bits to be or'd in with any pointers
497 which were stored in a Lisp_Object */ 510 which were stored in a Lisp_Object */
498#define XPNTR(a) (XUINT (a) | DATA_SEG_BITS) 511#define XPNTR(a) ((EMACS_INTPTR) (XUINT (a) | DATA_SEG_BITS))
499#else 512#else
500#define XPNTR(a) ((EMACS_INT) XUINT (a)) 513#define XPNTR(a) ((EMACS_INTPTR) XUINT (a))
501#endif 514#endif
502 515
503#endif /* !USE_LSB_TAG */ 516#endif /* !USE_LSB_TAG */
@@ -1814,8 +1827,8 @@ typedef struct {
1814 XSETCDR ((x), tmp); \ 1827 XSETCDR ((x), tmp); \
1815 } while (0) 1828 } while (0)
1816 1829
1817/* Cast pointers to this type to compare them. Some machines want int. */ 1830/* Cast pointers to this type to compare them. */
1818#define PNTR_COMPARISON_TYPE EMACS_UINT 1831#define PNTR_COMPARISON_TYPE EMACS_UINTPTR
1819 1832
1820/* Define a built-in function for calling from Lisp. 1833/* Define a built-in function for calling from Lisp.
1821 `lname' should be the name to give the function in Lisp, 1834 `lname' should be the name to give the function in Lisp,