aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
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/alloc.c
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/alloc.c')
-rw-r--r--src/alloc.c42
1 files changed, 22 insertions, 20 deletions
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}