aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog32
-rw-r--r--src/alloc.c42
-rw-r--r--src/doc.c11
-rw-r--r--src/gtkutil.c31
-rw-r--r--src/lisp.h39
-rw-r--r--src/menu.c8
-rw-r--r--src/xdisp.c21
-rw-r--r--src/xmenu.c8
8 files changed, 123 insertions, 69 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 45d7e7a9044..05f332b8142 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,35 @@
12011-04-29 Paul Eggert <eggert@cs.ucla.edu>
2
3 Prefer intptr_t/uintptr_t for integers the same widths as pointers.
4 This removes an assumption that EMACS_INT and long are the same
5 width as pointers. The assumption is true for Emacs porting targets
6 now, but we want to make other targets possible.
7 * lisp.h: Include <inttypes.h>, for INTPTR_MAX, UINTPTR_MAX.
8 (EMACS_INTPTR, EMACS_UINTPTR): New macros.
9 In the rest of the code, change types of integers that hold casted
10 pointers to EMACS_INTPTR and EMACS_UINTPTR, systematically
11 replacing EMACS_INT, long, EMACS_UINT, and unsigned long.
12 (XTYPE): Don't cast arg to EMACS_UINT; normally is not needed.
13 (XSET): Cast type of XTYPE arg to EMACS_INTPTR; it is needed here.
14 No need to cast type when ORing.
15 (XPNTR): Return a value of type EMACS_INTPTR or EMACS_UINTPTR.
16 * alloc.c (lisp_align_malloc): Remove a no-longer-needed cast.
17 * doc.c (store_function_docstring): Use EMACS_INTPTR, so as not to
18 assume EMACS_INT is the same width as char *.
19 * gtkutil.c (xg_gtk_scroll_destroy, xg_tool_bar_button_cb):
20 (xg_tool_bar_callback, xg_tool_bar_help_callback, xg_make_tool_item):
21 Remove no-longer-needed casts.
22 (xg_create_scroll_bar, xg_tool_bar_button_cb, xg_tool_bar_callback):
23 (xg_tool_bar_help_callback, xg_make_tool_item):
24 Use EMACS_INTPTR to hold an integer
25 that will be cast to void *; this can avoid a GCC warning
26 if EMACS_INT is not the same width as void *.
27 * menu.c (find_and_call_menu_selection): Remove no-longer-needed cast.
28 * xdisp.c (display_echo_area_1, resize_mini_window_1):
29 (current_message_1, set_message_1):
30 Use a local to convert to proper width without a cast.
31 * xmenu.c (dialog_selection_callback): Likewise.
32
12011-04-28 Paul Eggert <eggert@cs.ucla.edu> 332011-04-28 Paul Eggert <eggert@cs.ucla.edu>
2 34
3 * sysdep.c (get_random): Don't assume EMACS_INT is no wider than long. 35 * sysdep.c (get_random): Don't assume EMACS_INT is no wider than long.
diff --git a/src/alloc.c b/src/alloc.c
index 842088f4e92..591d8264295 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -438,7 +438,7 @@ static POINTER_TYPE *pure_alloc (size_t, int);
438 ALIGNMENT must be a power of 2. */ 438 ALIGNMENT must be a power of 2. */
439 439
440#define ALIGN(ptr, ALIGNMENT) \ 440#define ALIGN(ptr, ALIGNMENT) \
441 ((POINTER_TYPE *) ((((EMACS_UINT)(ptr)) + (ALIGNMENT) - 1) \ 441 ((POINTER_TYPE *) ((((EMACS_UINTPTR) (ptr)) + (ALIGNMENT) - 1) \
442 & ~((ALIGNMENT) - 1))) 442 & ~((ALIGNMENT) - 1)))
443 443
444 444
@@ -876,7 +876,7 @@ struct ablocks
876#define ABLOCKS_BYTES (sizeof (struct ablocks) - BLOCK_PADDING) 876#define ABLOCKS_BYTES (sizeof (struct ablocks) - BLOCK_PADDING)
877 877
878#define ABLOCK_ABASE(block) \ 878#define ABLOCK_ABASE(block) \
879 (((unsigned long) (block)->abase) <= (1 + 2 * ABLOCKS_SIZE) \ 879 (((EMACS_UINTPTR) (block)->abase) <= (1 + 2 * ABLOCKS_SIZE) \
880 ? (struct ablocks *)(block) \ 880 ? (struct ablocks *)(block) \
881 : (block)->abase) 881 : (block)->abase)
882 882
@@ -888,7 +888,7 @@ struct ablocks
888#define ABLOCKS_BASE(abase) (abase) 888#define ABLOCKS_BASE(abase) (abase)
889#else 889#else
890#define ABLOCKS_BASE(abase) \ 890#define ABLOCKS_BASE(abase) \
891 (1 & (long) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1]) 891 (1 & (EMACS_INTPTR) ABLOCKS_BUSY (abase) ? abase : ((void**)abase)[-1])
892#endif 892#endif
893 893
894/* The list of free ablock. */ 894/* The list of free ablock. */
@@ -914,7 +914,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
914 if (!free_ablock) 914 if (!free_ablock)
915 { 915 {
916 int i; 916 int i;
917 EMACS_INT aligned; /* int gets warning casting to 64-bit pointer. */ 917 EMACS_INTPTR aligned; /* int gets warning casting to 64-bit pointer. */
918 918
919#ifdef DOUG_LEA_MALLOC 919#ifdef DOUG_LEA_MALLOC
920 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed 920 /* Prevent mmap'ing the chunk. Lisp data may not be mmap'ed
@@ -977,17 +977,18 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
977 abase->blocks[i].x.next_free = free_ablock; 977 abase->blocks[i].x.next_free = free_ablock;
978 free_ablock = &abase->blocks[i]; 978 free_ablock = &abase->blocks[i];
979 } 979 }
980 ABLOCKS_BUSY (abase) = (struct ablocks *) (long) aligned; 980 ABLOCKS_BUSY (abase) = (struct ablocks *) aligned;
981 981
982 eassert (0 == ((EMACS_UINT)abase) % BLOCK_ALIGN); 982 eassert (0 == ((EMACS_UINTPTR) abase) % BLOCK_ALIGN);
983 eassert (ABLOCK_ABASE (&abase->blocks[3]) == abase); /* 3 is arbitrary */ 983 eassert (ABLOCK_ABASE (&abase->blocks[3]) == abase); /* 3 is arbitrary */
984 eassert (ABLOCK_ABASE (&abase->blocks[0]) == abase); 984 eassert (ABLOCK_ABASE (&abase->blocks[0]) == abase);
985 eassert (ABLOCKS_BASE (abase) == base); 985 eassert (ABLOCKS_BASE (abase) == base);
986 eassert (aligned == (long) ABLOCKS_BUSY (abase)); 986 eassert (aligned == (EMACS_INTPTR) ABLOCKS_BUSY (abase));
987 } 987 }
988 988
989 abase = ABLOCK_ABASE (free_ablock); 989 abase = ABLOCK_ABASE (free_ablock);
990 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (long) ABLOCKS_BUSY (abase)); 990 ABLOCKS_BUSY (abase) =
991 (struct ablocks *) (2 + (EMACS_INTPTR) ABLOCKS_BUSY (abase));
991 val = free_ablock; 992 val = free_ablock;
992 free_ablock = free_ablock->x.next_free; 993 free_ablock = free_ablock->x.next_free;
993 994
@@ -1000,7 +1001,7 @@ lisp_align_malloc (size_t nbytes, enum mem_type type)
1000 if (!val && nbytes) 1001 if (!val && nbytes)
1001 memory_full (); 1002 memory_full ();
1002 1003
1003 eassert (0 == ((EMACS_UINT)val) % BLOCK_ALIGN); 1004 eassert (0 == ((EMACS_UINTPTR) val) % BLOCK_ALIGN);
1004 return val; 1005 return val;
1005} 1006}
1006 1007
@@ -1018,11 +1019,12 @@ lisp_align_free (POINTER_TYPE *block)
1018 ablock->x.next_free = free_ablock; 1019 ablock->x.next_free = free_ablock;
1019 free_ablock = ablock; 1020 free_ablock = ablock;
1020 /* Update busy count. */ 1021 /* Update busy count. */
1021 ABLOCKS_BUSY (abase) = (struct ablocks *) (-2 + (long) ABLOCKS_BUSY (abase)); 1022 ABLOCKS_BUSY (abase) =
1023 (struct ablocks *) (-2 + (EMACS_INTPTR) ABLOCKS_BUSY (abase));
1022 1024
1023 if (2 > (long) ABLOCKS_BUSY (abase)) 1025 if (2 > (EMACS_INTPTR) ABLOCKS_BUSY (abase))
1024 { /* All the blocks are free. */ 1026 { /* All the blocks are free. */
1025 int i = 0, aligned = (long) ABLOCKS_BUSY (abase); 1027 int i = 0, aligned = (EMACS_INTPTR) ABLOCKS_BUSY (abase);
1026 struct ablock **tem = &free_ablock; 1028 struct ablock **tem = &free_ablock;
1027 struct ablock *atop = &abase->blocks[aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1]; 1029 struct ablock *atop = &abase->blocks[aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1];
1028 1030
@@ -1039,7 +1041,7 @@ lisp_align_free (POINTER_TYPE *block)
1039 eassert ((aligned & 1) == aligned); 1041 eassert ((aligned & 1) == aligned);
1040 eassert (i == (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1)); 1042 eassert (i == (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1));
1041#ifdef USE_POSIX_MEMALIGN 1043#ifdef USE_POSIX_MEMALIGN
1042 eassert ((unsigned long)ABLOCKS_BASE (abase) % BLOCK_ALIGN == 0); 1044 eassert ((EMACS_UINTPTR) ABLOCKS_BASE (abase) % BLOCK_ALIGN == 0);
1043#endif 1045#endif
1044 free (ABLOCKS_BASE (abase)); 1046 free (ABLOCKS_BASE (abase));
1045 } 1047 }
@@ -1772,7 +1774,7 @@ check_string_free_list (void)
1772 s = string_free_list; 1774 s = string_free_list;
1773 while (s != NULL) 1775 while (s != NULL)
1774 { 1776 {
1775 if ((unsigned long)s < 1024) 1777 if ((EMACS_UINTPTR) s < 1024)
1776 abort(); 1778 abort();
1777 s = NEXT_FREE_LISP_STRING (s); 1779 s = NEXT_FREE_LISP_STRING (s);
1778 } 1780 }
@@ -2432,10 +2434,10 @@ make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes)
2432 &= ~(1 << ((n) % (sizeof(int) * CHAR_BIT))) 2434 &= ~(1 << ((n) % (sizeof(int) * CHAR_BIT)))
2433 2435
2434#define FLOAT_BLOCK(fptr) \ 2436#define FLOAT_BLOCK(fptr) \
2435 ((struct float_block *)(((EMACS_UINT)(fptr)) & ~(BLOCK_ALIGN - 1))) 2437 ((struct float_block *) (((EMACS_UINTPTR) (fptr)) & ~(BLOCK_ALIGN - 1)))
2436 2438
2437#define FLOAT_INDEX(fptr) \ 2439#define FLOAT_INDEX(fptr) \
2438 ((((EMACS_UINT)(fptr)) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Float)) 2440 ((((EMACS_UINTPTR) (fptr)) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Float))
2439 2441
2440struct float_block 2442struct float_block
2441{ 2443{
@@ -2544,10 +2546,10 @@ make_float (double float_value)
2544 / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1)) 2546 / (sizeof (struct Lisp_Cons) * CHAR_BIT + 1))
2545 2547
2546#define CONS_BLOCK(fptr) \ 2548#define CONS_BLOCK(fptr) \
2547 ((struct cons_block *)(((EMACS_UINT)(fptr)) & ~(BLOCK_ALIGN - 1))) 2549 ((struct cons_block *) ((EMACS_UINTPTR) (fptr) & ~(BLOCK_ALIGN - 1)))
2548 2550
2549#define CONS_INDEX(fptr) \ 2551#define CONS_INDEX(fptr) \
2550 ((((EMACS_UINT)(fptr)) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Cons)) 2552 (((EMACS_UINTPTR) (fptr) & (BLOCK_ALIGN - 1)) / sizeof (struct Lisp_Cons))
2551 2553
2552struct cons_block 2554struct cons_block
2553{ 2555{
@@ -4021,7 +4023,7 @@ mark_maybe_pointer (void *p)
4021 struct mem_node *m; 4023 struct mem_node *m;
4022 4024
4023 /* Quickly rule out some values which can't point to Lisp data. */ 4025 /* Quickly rule out some values which can't point to Lisp data. */
4024 if ((EMACS_INT) p % 4026 if ((EMACS_INTPTR) p %
4025#ifdef USE_LSB_TAG 4027#ifdef USE_LSB_TAG
4026 8 /* USE_LSB_TAG needs Lisp data to be aligned on multiples of 8. */ 4028 8 /* USE_LSB_TAG needs Lisp data to be aligned on multiples of 8. */
4027#else 4029#else
@@ -6072,7 +6074,7 @@ We divide the value by 1024 to make sure it fits in a Lisp integer. */)
6072{ 6074{
6073 Lisp_Object end; 6075 Lisp_Object end;
6074 6076
6075 XSETINT (end, (EMACS_INT) (char *) sbrk (0) / 1024); 6077 XSETINT (end, (EMACS_INTPTR) (char *) sbrk (0) / 1024);
6076 6078
6077 return end; 6079 return end;
6078} 6080}
diff --git a/src/doc.c b/src/doc.c
index 3832eb3708d..740bb26ff08 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -349,10 +349,10 @@ string is passed through `substitute-command-keys'. */)
349 return Qnil; 349 return Qnil;
350 /* FIXME: This is not portable, as it assumes that string 350 /* FIXME: This is not portable, as it assumes that string
351 pointers have the top bit clear. */ 351 pointers have the top bit clear. */
352 else if ((EMACS_INT) XSUBR (fun)->doc >= 0) 352 else if ((EMACS_INTPTR) XSUBR (fun)->doc >= 0)
353 doc = build_string (XSUBR (fun)->doc); 353 doc = build_string (XSUBR (fun)->doc);
354 else 354 else
355 doc = make_number ((EMACS_INT) XSUBR (fun)->doc); 355 doc = make_number ((EMACS_INTPTR) XSUBR (fun)->doc);
356 } 356 }
357 else if (COMPILEDP (fun)) 357 else if (COMPILEDP (fun))
358 { 358 {
@@ -506,8 +506,11 @@ store_function_docstring (Lisp_Object fun, EMACS_INT offset)
506 /* The type determines where the docstring is stored. */ 506 /* The type determines where the docstring is stored. */
507 507
508 /* Lisp_Subrs have a slot for it. */ 508 /* Lisp_Subrs have a slot for it. */
509 if (SUBRP (fun)) 509 if (SUBRP (fun))
510 XSUBR (fun)->doc = (char *) - offset; 510 {
511 EMACS_INTPTR negative_offset = - offset;
512 XSUBR (fun)->doc = (char *) negative_offset;
513 }
511 514
512 /* If it's a lisp form, stick it in the form. */ 515 /* If it's a lisp form, stick it in the form. */
513 else if (CONSP (fun)) 516 else if (CONSP (fun))
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 9d3bfe6a89c..ff33a3f3c04 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -3354,7 +3354,7 @@ xg_get_scroll_id_for_window (Display *dpy, Window wid)
3354static void 3354static void
3355xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data) 3355xg_gtk_scroll_destroy (GtkWidget *widget, gpointer data)
3356{ 3356{
3357 int id = (int) (EMACS_INT) data; /* The EMACS_INT cast avoids a warning. */ 3357 int id = (EMACS_INTPTR) data;
3358 xg_remove_widget_from_map (id); 3358 xg_remove_widget_from_map (id);
3359} 3359}
3360 3360
@@ -3375,7 +3375,7 @@ xg_create_scroll_bar (FRAME_PTR f,
3375{ 3375{
3376 GtkWidget *wscroll; 3376 GtkWidget *wscroll;
3377 GtkWidget *webox; 3377 GtkWidget *webox;
3378 int scroll_id; 3378 EMACS_INTPTR scroll_id;
3379#ifdef HAVE_GTK3 3379#ifdef HAVE_GTK3
3380 GtkAdjustment *vadj; 3380 GtkAdjustment *vadj;
3381#else 3381#else
@@ -3397,11 +3397,10 @@ xg_create_scroll_bar (FRAME_PTR f,
3397 3397
3398 scroll_id = xg_store_widget_in_map (wscroll); 3398 scroll_id = xg_store_widget_in_map (wscroll);
3399 3399
3400 /* The EMACS_INT cast avoids a warning. */
3401 g_signal_connect (G_OBJECT (wscroll), 3400 g_signal_connect (G_OBJECT (wscroll),
3402 "destroy", 3401 "destroy",
3403 G_CALLBACK (xg_gtk_scroll_destroy), 3402 G_CALLBACK (xg_gtk_scroll_destroy),
3404 (gpointer) (EMACS_INT) scroll_id); 3403 (gpointer) scroll_id);
3405 g_signal_connect (G_OBJECT (wscroll), 3404 g_signal_connect (G_OBJECT (wscroll),
3406 "change-value", 3405 "change-value",
3407 scroll_callback, 3406 scroll_callback,
@@ -3663,8 +3662,8 @@ xg_tool_bar_button_cb (GtkWidget *widget,
3663 GdkEventButton *event, 3662 GdkEventButton *event,
3664 gpointer user_data) 3663 gpointer user_data)
3665{ 3664{
3666 /* Casts to avoid warnings when gpointer is 64 bits and int is 32 bits */ 3665 EMACS_INTPTR state = event->state;
3667 gpointer ptr = (gpointer) (EMACS_INT) event->state; 3666 gpointer ptr = (gpointer) state;
3668 g_object_set_data (G_OBJECT (widget), XG_TOOL_BAR_LAST_MODIFIER, ptr); 3667 g_object_set_data (G_OBJECT (widget), XG_TOOL_BAR_LAST_MODIFIER, ptr);
3669 return FALSE; 3668 return FALSE;
3670} 3669}
@@ -3678,10 +3677,9 @@ xg_tool_bar_button_cb (GtkWidget *widget,
3678static void 3677static void
3679xg_tool_bar_callback (GtkWidget *w, gpointer client_data) 3678xg_tool_bar_callback (GtkWidget *w, gpointer client_data)
3680{ 3679{
3681 /* The EMACS_INT cast avoids a warning. */ 3680 EMACS_INTPTR idx = (EMACS_INTPTR) client_data;
3682 int idx = (int) (EMACS_INT) client_data;
3683 gpointer gmod = g_object_get_data (G_OBJECT (w), XG_TOOL_BAR_LAST_MODIFIER); 3681 gpointer gmod = g_object_get_data (G_OBJECT (w), XG_TOOL_BAR_LAST_MODIFIER);
3684 int mod = (int) (EMACS_INT) gmod; 3682 EMACS_INTPTR mod = (EMACS_INTPTR) gmod;
3685 3683
3686 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); 3684 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA);
3687 Lisp_Object key, frame; 3685 Lisp_Object key, frame;
@@ -3960,8 +3958,7 @@ xg_tool_bar_help_callback (GtkWidget *w,
3960 GdkEventCrossing *event, 3958 GdkEventCrossing *event,
3961 gpointer client_data) 3959 gpointer client_data)
3962{ 3960{
3963 /* The EMACS_INT cast avoids a warning. */ 3961 EMACS_INTPTR idx = (EMACS_INTPTR) client_data;
3964 int idx = (int) (EMACS_INT) client_data;
3965 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA); 3962 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (w), XG_FRAME_DATA);
3966 Lisp_Object help, frame; 3963 Lisp_Object help, frame;
3967 3964
@@ -4155,14 +4152,16 @@ xg_make_tool_item (FRAME_PTR f,
4155 4152
4156 if (wimage) 4153 if (wimage)
4157 { 4154 {
4158 /* The EMACS_INT cast avoids a warning. */ 4155 EMACS_INTPTR ii = i;
4156 gpointer gi = (gpointer) ii;
4157
4159 g_signal_connect (G_OBJECT (ti), "create-menu-proxy", 4158 g_signal_connect (G_OBJECT (ti), "create-menu-proxy",
4160 G_CALLBACK (xg_tool_bar_menu_proxy), 4159 G_CALLBACK (xg_tool_bar_menu_proxy),
4161 (gpointer) (EMACS_INT) i); 4160 gi);
4162 4161
4163 g_signal_connect (G_OBJECT (wb), "clicked", 4162 g_signal_connect (G_OBJECT (wb), "clicked",
4164 G_CALLBACK (xg_tool_bar_callback), 4163 G_CALLBACK (xg_tool_bar_callback),
4165 (gpointer) (EMACS_INT) i); 4164 gi);
4166 4165
4167 g_object_set_data (G_OBJECT (weventbox), XG_FRAME_DATA, (gpointer)f); 4166 g_object_set_data (G_OBJECT (weventbox), XG_FRAME_DATA, (gpointer)f);
4168 4167
@@ -4193,11 +4192,11 @@ xg_make_tool_item (FRAME_PTR f,
4193 g_signal_connect (G_OBJECT (weventbox), 4192 g_signal_connect (G_OBJECT (weventbox),
4194 "enter-notify-event", 4193 "enter-notify-event",
4195 G_CALLBACK (xg_tool_bar_help_callback), 4194 G_CALLBACK (xg_tool_bar_help_callback),
4196 (gpointer) (EMACS_INT) i); 4195 gi);
4197 g_signal_connect (G_OBJECT (weventbox), 4196 g_signal_connect (G_OBJECT (weventbox),
4198 "leave-notify-event", 4197 "leave-notify-event",
4199 G_CALLBACK (xg_tool_bar_help_callback), 4198 G_CALLBACK (xg_tool_bar_help_callback),
4200 (gpointer) (EMACS_INT) i); 4199 gi);
4201 } 4200 }
4202 4201
4203 if (wbutton) *wbutton = wb; 4202 if (wbutton) *wbutton = wb;
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,
diff --git a/src/menu.c b/src/menu.c
index f637b92679a..5162ee083bf 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -800,9 +800,9 @@ digest_single_submenu (int start, int end, int top_level_items)
800 if (!NILP (descrip)) 800 if (!NILP (descrip))
801 wv->lkey = descrip; 801 wv->lkey = descrip;
802 wv->value = 0; 802 wv->value = 0;
803 /* The EMACS_INT cast avoids a warning. There's no problem 803 /* The EMACS_INTPTR cast avoids a warning. There's no problem
804 as long as pointers have enough bits to hold small integers. */ 804 as long as pointers have enough bits to hold small integers. */
805 wv->call_data = (!NILP (def) ? (void *) (EMACS_INT) i : 0); 805 wv->call_data = (!NILP (def) ? (void *) (EMACS_INTPTR) i : 0);
806 wv->enabled = !NILP (enable); 806 wv->enabled = !NILP (enable);
807 807
808 if (NILP (type)) 808 if (NILP (type))
@@ -911,9 +911,9 @@ find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object
911 else 911 else
912 { 912 {
913 entry = XVECTOR (vector)->contents[i + MENU_ITEMS_ITEM_VALUE]; 913 entry = XVECTOR (vector)->contents[i + MENU_ITEMS_ITEM_VALUE];
914 /* The EMACS_INT cast avoids a warning. There's no problem 914 /* Treat the pointer as an integer. There's no problem
915 as long as pointers have enough bits to hold small integers. */ 915 as long as pointers have enough bits to hold small integers. */
916 if ((int) (EMACS_INT) client_data == i) 916 if ((EMACS_INTPTR) client_data == i)
917 { 917 {
918 int j; 918 int j;
919 struct input_event buf; 919 struct input_event buf;
diff --git a/src/xdisp.c b/src/xdisp.c
index 6d3c142f62a..af03a504e86 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -8737,7 +8737,7 @@ display_echo_area (struct window *w)
8737 window_height_changed_p 8737 window_height_changed_p
8738 = with_echo_area_buffer (w, display_last_displayed_message_p, 8738 = with_echo_area_buffer (w, display_last_displayed_message_p,
8739 display_echo_area_1, 8739 display_echo_area_1,
8740 (EMACS_INT) w, Qnil, 0, 0); 8740 (EMACS_INTPTR) w, Qnil, 0, 0);
8741 8741
8742 if (no_message_p) 8742 if (no_message_p)
8743 echo_area_buffer[i] = Qnil; 8743 echo_area_buffer[i] = Qnil;
@@ -8756,7 +8756,8 @@ display_echo_area (struct window *w)
8756static int 8756static int
8757display_echo_area_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 8757display_echo_area_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4)
8758{ 8758{
8759 struct window *w = (struct window *) a1; 8759 EMACS_INTPTR i1 = a1;
8760 struct window *w = (struct window *) i1;
8760 Lisp_Object window; 8761 Lisp_Object window;
8761 struct text_pos start; 8762 struct text_pos start;
8762 int window_height_changed_p = 0; 8763 int window_height_changed_p = 0;
@@ -8798,7 +8799,8 @@ resize_echo_area_exactly (void)
8798 resize_exactly = Qnil; 8799 resize_exactly = Qnil;
8799 8800
8800 resized_p = with_echo_area_buffer (w, 0, resize_mini_window_1, 8801 resized_p = with_echo_area_buffer (w, 0, resize_mini_window_1,
8801 (EMACS_INT) w, resize_exactly, 0, 0); 8802 (EMACS_INTPTR) w, resize_exactly,
8803 0, 0);
8802 if (resized_p) 8804 if (resized_p)
8803 { 8805 {
8804 ++windows_or_buffers_changed; 8806 ++windows_or_buffers_changed;
@@ -8818,7 +8820,8 @@ resize_echo_area_exactly (void)
8818static int 8820static int
8819resize_mini_window_1 (EMACS_INT a1, Lisp_Object exactly, EMACS_INT a3, EMACS_INT a4) 8821resize_mini_window_1 (EMACS_INT a1, Lisp_Object exactly, EMACS_INT a3, EMACS_INT a4)
8820{ 8822{
8821 return resize_mini_window ((struct window *) a1, !NILP (exactly)); 8823 EMACS_INTPTR i1 = a1;
8824 return resize_mini_window ((struct window *) i1, !NILP (exactly));
8822} 8825}
8823 8826
8824 8827
@@ -8984,7 +8987,7 @@ current_message (void)
8984 else 8987 else
8985 { 8988 {
8986 with_echo_area_buffer (0, 0, current_message_1, 8989 with_echo_area_buffer (0, 0, current_message_1,
8987 (EMACS_INT) &msg, Qnil, 0, 0); 8990 (EMACS_INTPTR) &msg, Qnil, 0, 0);
8988 if (NILP (msg)) 8991 if (NILP (msg))
8989 echo_area_buffer[0] = Qnil; 8992 echo_area_buffer[0] = Qnil;
8990 } 8993 }
@@ -8996,7 +8999,8 @@ current_message (void)
8996static int 8999static int
8997current_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4) 9000current_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT a3, EMACS_INT a4)
8998{ 9001{
8999 Lisp_Object *msg = (Lisp_Object *) a1; 9002 EMACS_INTPTR i1 = a1;
9003 Lisp_Object *msg = (Lisp_Object *) i1;
9000 9004
9001 if (Z > BEG) 9005 if (Z > BEG)
9002 *msg = make_buffer_string (BEG, Z, 1); 9006 *msg = make_buffer_string (BEG, Z, 1);
@@ -9127,7 +9131,7 @@ set_message (const char *s, Lisp_Object string,
9127 || (STRINGP (string) && STRING_MULTIBYTE (string))); 9131 || (STRINGP (string) && STRING_MULTIBYTE (string)));
9128 9132
9129 with_echo_area_buffer (0, -1, set_message_1, 9133 with_echo_area_buffer (0, -1, set_message_1,
9130 (EMACS_INT) s, string, nbytes, multibyte_p); 9134 (EMACS_INTPTR) s, string, nbytes, multibyte_p);
9131 message_buf_print = 0; 9135 message_buf_print = 0;
9132 help_echo_showing_p = 0; 9136 help_echo_showing_p = 0;
9133} 9137}
@@ -9141,7 +9145,8 @@ set_message (const char *s, Lisp_Object string,
9141static int 9145static int
9142set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multibyte_p) 9146set_message_1 (EMACS_INT a1, Lisp_Object a2, EMACS_INT nbytes, EMACS_INT multibyte_p)
9143{ 9147{
9144 const char *s = (const char *) a1; 9148 EMACS_INTPTR i1 = a1;
9149 const char *s = (const char *) i1;
9145 const unsigned char *msg = (const unsigned char *) s; 9150 const unsigned char *msg = (const unsigned char *) s;
9146 Lisp_Object string = a2; 9151 Lisp_Object string = a2;
9147 9152
diff --git a/src/xmenu.c b/src/xmenu.c
index 2d6185c16e5..54f1fc666ec 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -1139,9 +1139,9 @@ set_frame_menubar (FRAME_PTR f, int first_time, int deep_p)
1139 wv->help = Qnil; 1139 wv->help = Qnil;
1140 /* This prevents lwlib from assuming this 1140 /* This prevents lwlib from assuming this
1141 menu item is really supposed to be empty. */ 1141 menu item is really supposed to be empty. */
1142 /* The EMACS_INT cast avoids a warning. 1142 /* The EMACS_INTPTR cast avoids a warning.
1143 This value just has to be different from small integers. */ 1143 This value just has to be different from small integers. */
1144 wv->call_data = (void *) (EMACS_INT) (-1); 1144 wv->call_data = (void *) (EMACS_INTPTR) (-1);
1145 1145
1146 if (prev_wv) 1146 if (prev_wv)
1147 prev_wv->next = wv; 1147 prev_wv->next = wv;
@@ -1876,9 +1876,9 @@ xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
1876static void 1876static void
1877dialog_selection_callback (GtkWidget *widget, gpointer client_data) 1877dialog_selection_callback (GtkWidget *widget, gpointer client_data)
1878{ 1878{
1879 /* The EMACS_INT cast avoids a warning. There's no problem 1879 /* Treat the pointer as an integer. There's no problem
1880 as long as pointers have enough bits to hold small integers. */ 1880 as long as pointers have enough bits to hold small integers. */
1881 if ((int) (EMACS_INT) client_data != -1) 1881 if ((EMACS_INTPTR) client_data != -1)
1882 menu_item_selection = (Lisp_Object *) client_data; 1882 menu_item_selection = (Lisp_Object *) client_data;
1883 1883
1884 popup_activated_flag = 0; 1884 popup_activated_flag = 0;