aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2011-03-17 09:51:42 -0700
committerPaul Eggert2011-03-17 09:51:42 -0700
commita3a6c54ec72118e8d22d2ecd608df5193c8926a3 (patch)
treede018428bd736fd37ec25ac07152199664d3f08b /src/alloc.c
parentd6cd56f187a791983579bf5d4ce3702d2ddf2499 (diff)
parentb1d876f1a19ae65c8a8dd61c4ce17055ca53f16c (diff)
downloademacs-a3a6c54ec72118e8d22d2ecd608df5193c8926a3.tar.gz
emacs-a3a6c54ec72118e8d22d2ecd608df5193c8926a3.zip
Merge: Fix more problems found by GCC 4.5.2's static checks.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c85
1 files changed, 42 insertions, 43 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 6c92f36ca7d..66695e7a9bc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -92,7 +92,8 @@ extern __malloc_size_t __malloc_extra_blocks;
92 92
93#endif /* not DOUG_LEA_MALLOC */ 93#endif /* not DOUG_LEA_MALLOC */
94 94
95#if ! defined (SYSTEM_MALLOC) && defined (HAVE_GTK_AND_PTHREAD) 95#if ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT
96#ifdef HAVE_GTK_AND_PTHREAD
96 97
97/* When GTK uses the file chooser dialog, different backends can be loaded 98/* When GTK uses the file chooser dialog, different backends can be loaded
98 dynamically. One such a backend is the Gnome VFS backend that gets loaded 99 dynamically. One such a backend is the Gnome VFS backend that gets loaded
@@ -130,12 +131,13 @@ static pthread_mutex_t alloc_mutex;
130 } \ 131 } \
131 while (0) 132 while (0)
132 133
133#else /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ 134#else /* ! defined HAVE_GTK_AND_PTHREAD */
134 135
135#define BLOCK_INPUT_ALLOC BLOCK_INPUT 136#define BLOCK_INPUT_ALLOC BLOCK_INPUT
136#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT 137#define UNBLOCK_INPUT_ALLOC UNBLOCK_INPUT
137 138
138#endif /* SYSTEM_MALLOC || not HAVE_GTK_AND_PTHREAD */ 139#endif /* ! defined HAVE_GTK_AND_PTHREAD */
140#endif /* ! defined SYSTEM_MALLOC && ! defined SYNC_INPUT */
139 141
140/* Value of _bytes_used, when spare_memory was freed. */ 142/* Value of _bytes_used, when spare_memory was freed. */
141 143
@@ -152,13 +154,11 @@ static __malloc_size_t bytes_used_when_full;
152#define VECTOR_UNMARK(V) ((V)->size &= ~ARRAY_MARK_FLAG) 154#define VECTOR_UNMARK(V) ((V)->size &= ~ARRAY_MARK_FLAG)
153#define VECTOR_MARKED_P(V) (((V)->size & ARRAY_MARK_FLAG) != 0) 155#define VECTOR_MARKED_P(V) (((V)->size & ARRAY_MARK_FLAG) != 0)
154 156
155/* Value is the number of bytes/chars of S, a pointer to a struct 157/* Value is the number of bytes of S, a pointer to a struct Lisp_String.
156 Lisp_String. This must be used instead of STRING_BYTES (S) or 158 Be careful during GC, because S->size contains the mark bit for
157 S->size during GC, because S->size contains the mark bit for
158 strings. */ 159 strings. */
159 160
160#define GC_STRING_BYTES(S) (STRING_BYTES (S)) 161#define GC_STRING_BYTES(S) (STRING_BYTES (S))
161#define GC_STRING_CHARS(S) ((S)->size & ~ARRAY_MARK_FLAG)
162 162
163/* Global variables. */ 163/* Global variables. */
164struct emacs_globals globals; 164struct emacs_globals globals;
@@ -270,8 +270,6 @@ Lisp_Object Qpost_gc_hook;
270 270
271static void mark_buffer (Lisp_Object); 271static void mark_buffer (Lisp_Object);
272static void mark_terminals (void); 272static void mark_terminals (void);
273extern void mark_kboards (void);
274extern void mark_backtrace (void);
275static void gc_sweep (void); 273static void gc_sweep (void);
276static void mark_glyph_matrix (struct glyph_matrix *); 274static void mark_glyph_matrix (struct glyph_matrix *);
277static void mark_face_cache (struct face_cache *); 275static void mark_face_cache (struct face_cache *);
@@ -2654,17 +2652,17 @@ DEFUN ("cons", Fcons, Scons, 2, 2, 0,
2654 return val; 2652 return val;
2655} 2653}
2656 2654
2655#ifdef GC_CHECK_CONS_LIST
2657/* Get an error now if there's any junk in the cons free list. */ 2656/* Get an error now if there's any junk in the cons free list. */
2658void 2657void
2659check_cons_list (void) 2658check_cons_list (void)
2660{ 2659{
2661#ifdef GC_CHECK_CONS_LIST
2662 struct Lisp_Cons *tail = cons_free_list; 2660 struct Lisp_Cons *tail = cons_free_list;
2663 2661
2664 while (tail) 2662 while (tail)
2665 tail = tail->u.chain; 2663 tail = tail->u.chain;
2666#endif
2667} 2664}
2665#endif
2668 2666
2669/* Make a list of 1, 2, 3, 4 or 5 specified objects. */ 2667/* Make a list of 1, 2, 3, 4 or 5 specified objects. */
2670 2668
@@ -2904,15 +2902,15 @@ See also the function `vector'. */)
2904{ 2902{
2905 Lisp_Object vector; 2903 Lisp_Object vector;
2906 register EMACS_INT sizei; 2904 register EMACS_INT sizei;
2907 register EMACS_INT index; 2905 register EMACS_INT i;
2908 register struct Lisp_Vector *p; 2906 register struct Lisp_Vector *p;
2909 2907
2910 CHECK_NATNUM (length); 2908 CHECK_NATNUM (length);
2911 sizei = XFASTINT (length); 2909 sizei = XFASTINT (length);
2912 2910
2913 p = allocate_vector (sizei); 2911 p = allocate_vector (sizei);
2914 for (index = 0; index < sizei; index++) 2912 for (i = 0; i < sizei; i++)
2915 p->contents[index] = init; 2913 p->contents[i] = init;
2916 2914
2917 XSETVECTOR (vector, p); 2915 XSETVECTOR (vector, p);
2918 return vector; 2916 return vector;
@@ -2926,14 +2924,14 @@ usage: (vector &rest OBJECTS) */)
2926 (register int nargs, Lisp_Object *args) 2924 (register int nargs, Lisp_Object *args)
2927{ 2925{
2928 register Lisp_Object len, val; 2926 register Lisp_Object len, val;
2929 register int index; 2927 register int i;
2930 register struct Lisp_Vector *p; 2928 register struct Lisp_Vector *p;
2931 2929
2932 XSETFASTINT (len, nargs); 2930 XSETFASTINT (len, nargs);
2933 val = Fmake_vector (len, Qnil); 2931 val = Fmake_vector (len, Qnil);
2934 p = XVECTOR (val); 2932 p = XVECTOR (val);
2935 for (index = 0; index < nargs; index++) 2933 for (i = 0; i < nargs; i++)
2936 p->contents[index] = args[index]; 2934 p->contents[i] = args[i];
2937 return val; 2935 return val;
2938} 2936}
2939 2937
@@ -2948,7 +2946,7 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
2948 (register int nargs, Lisp_Object *args) 2946 (register int nargs, Lisp_Object *args)
2949{ 2947{
2950 register Lisp_Object len, val; 2948 register Lisp_Object len, val;
2951 register int index; 2949 register int i;
2952 register struct Lisp_Vector *p; 2950 register struct Lisp_Vector *p;
2953 2951
2954 XSETFASTINT (len, nargs); 2952 XSETFASTINT (len, nargs);
@@ -2966,11 +2964,11 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT
2966 args[1] = Fstring_as_unibyte (args[1]); 2964 args[1] = Fstring_as_unibyte (args[1]);
2967 2965
2968 p = XVECTOR (val); 2966 p = XVECTOR (val);
2969 for (index = 0; index < nargs; index++) 2967 for (i = 0; i < nargs; i++)
2970 { 2968 {
2971 if (!NILP (Vpurify_flag)) 2969 if (!NILP (Vpurify_flag))
2972 args[index] = Fpurecopy (args[index]); 2970 args[i] = Fpurecopy (args[i]);
2973 p->contents[index] = args[index]; 2971 p->contents[i] = args[i];
2974 } 2972 }
2975 XSETPVECTYPE (p, PVEC_COMPILED); 2973 XSETPVECTYPE (p, PVEC_COMPILED);
2976 XSETCOMPILED (val, p); 2974 XSETCOMPILED (val, p);
@@ -4313,12 +4311,6 @@ static void
4313mark_stack (void) 4311mark_stack (void)
4314{ 4312{
4315 int i; 4313 int i;
4316 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4317 union aligned_jmpbuf {
4318 Lisp_Object o;
4319 jmp_buf j;
4320 } j;
4321 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base;
4322 void *end; 4314 void *end;
4323 4315
4324#ifdef HAVE___BUILTIN_UNWIND_INIT 4316#ifdef HAVE___BUILTIN_UNWIND_INIT
@@ -4328,6 +4320,14 @@ mark_stack (void)
4328 __builtin_unwind_init (); 4320 __builtin_unwind_init ();
4329 end = &end; 4321 end = &end;
4330#else /* not HAVE___BUILTIN_UNWIND_INIT */ 4322#else /* not HAVE___BUILTIN_UNWIND_INIT */
4323#ifndef GC_SAVE_REGISTERS_ON_STACK
4324 /* jmp_buf may not be aligned enough on darwin-ppc64 */
4325 union aligned_jmpbuf {
4326 Lisp_Object o;
4327 jmp_buf j;
4328 } j;
4329 volatile int stack_grows_down_p = (char *) &j > (char *) stack_base;
4330#endif
4331 /* This trick flushes the register windows so that all the state of 4331 /* This trick flushes the register windows so that all the state of
4332 the process is contained in the stack. */ 4332 the process is contained in the stack. */
4333 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is 4333 /* Fixme: Code in the Boehm GC suggests flushing (with `flushrs') is
@@ -5064,18 +5064,18 @@ returns nil, because real GC can't be done. */)
5064 5064
5065 if (FLOATP (Vgc_cons_percentage)) 5065 if (FLOATP (Vgc_cons_percentage))
5066 { /* Set gc_cons_combined_threshold. */ 5066 { /* Set gc_cons_combined_threshold. */
5067 EMACS_INT total = 0; 5067 EMACS_INT tot = 0;
5068 5068
5069 total += total_conses * sizeof (struct Lisp_Cons); 5069 tot += total_conses * sizeof (struct Lisp_Cons);
5070 total += total_symbols * sizeof (struct Lisp_Symbol); 5070 tot += total_symbols * sizeof (struct Lisp_Symbol);
5071 total += total_markers * sizeof (union Lisp_Misc); 5071 tot += total_markers * sizeof (union Lisp_Misc);
5072 total += total_string_size; 5072 tot += total_string_size;
5073 total += total_vector_size * sizeof (Lisp_Object); 5073 tot += total_vector_size * sizeof (Lisp_Object);
5074 total += total_floats * sizeof (struct Lisp_Float); 5074 tot += total_floats * sizeof (struct Lisp_Float);
5075 total += total_intervals * sizeof (struct interval); 5075 tot += total_intervals * sizeof (struct interval);
5076 total += total_strings * sizeof (struct Lisp_String); 5076 tot += total_strings * sizeof (struct Lisp_String);
5077 5077
5078 gc_relative_threshold = total * XFLOAT_DATA (Vgc_cons_percentage); 5078 gc_relative_threshold = tot * XFLOAT_DATA (Vgc_cons_percentage);
5079 } 5079 }
5080 else 5080 else
5081 gc_relative_threshold = 0; 5081 gc_relative_threshold = 0;
@@ -5124,9 +5124,9 @@ returns nil, because real GC can't be done. */)
5124 5124
5125 if (!NILP (Vpost_gc_hook)) 5125 if (!NILP (Vpost_gc_hook))
5126 { 5126 {
5127 int count = inhibit_garbage_collection (); 5127 int gc_count = inhibit_garbage_collection ();
5128 safe_run_hooks (Qpost_gc_hook); 5128 safe_run_hooks (Qpost_gc_hook);
5129 unbind_to (count, Qnil); 5129 unbind_to (gc_count, Qnil);
5130 } 5130 }
5131 5131
5132 /* Accumulate statistics. */ 5132 /* Accumulate statistics. */
@@ -5305,7 +5305,6 @@ mark_object (Lisp_Object arg)
5305 5305
5306#else /* not GC_CHECK_MARKED_OBJECTS */ 5306#else /* not GC_CHECK_MARKED_OBJECTS */
5307 5307
5308#define CHECK_ALLOCATED() (void) 0
5309#define CHECK_LIVE(LIVEP) (void) 0 5308#define CHECK_LIVE(LIVEP) (void) 0
5310#define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0 5309#define CHECK_ALLOCATED_AND_LIVE(LIVEP) (void) 0
5311 5310
@@ -6057,7 +6056,7 @@ We divide the value by 1024 to make sure it fits in a Lisp integer. */)
6057{ 6056{
6058 Lisp_Object end; 6057 Lisp_Object end;
6059 6058
6060 XSETINT (end, (EMACS_INT) sbrk (0) / 1024); 6059 XSETINT (end, (EMACS_INT) (char *) sbrk (0) / 1024);
6061 6060
6062 return end; 6061 return end;
6063} 6062}