aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/alloc.c b/src/alloc.c
index c8141d22f95..8417ef4982b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -318,7 +318,6 @@ static void *min_heap_address, *max_heap_address;
318static struct mem_node mem_z; 318static struct mem_node mem_z;
319#define MEM_NIL &mem_z 319#define MEM_NIL &mem_z
320 320
321#if GC_MARK_STACK || defined GC_MALLOC_CHECK
322static struct mem_node *mem_insert (void *, void *, enum mem_type); 321static struct mem_node *mem_insert (void *, void *, enum mem_type);
323static void mem_insert_fixup (struct mem_node *); 322static void mem_insert_fixup (struct mem_node *);
324static void mem_rotate_left (struct mem_node *); 323static void mem_rotate_left (struct mem_node *);
@@ -326,7 +325,6 @@ static void mem_rotate_right (struct mem_node *);
326static void mem_delete (struct mem_node *); 325static void mem_delete (struct mem_node *);
327static void mem_delete_fixup (struct mem_node *); 326static void mem_delete_fixup (struct mem_node *);
328static struct mem_node *mem_find (void *); 327static struct mem_node *mem_find (void *);
329#endif
330 328
331#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */ 329#endif /* GC_MARK_STACK || GC_MALLOC_CHECK */
332 330
@@ -796,10 +794,19 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min,
796char * 794char *
797xstrdup (const char *s) 795xstrdup (const char *s)
798{ 796{
799 size_t len = strlen (s) + 1; 797 ptrdiff_t size;
800 char *p = xmalloc (len); 798 eassert (s);
801 memcpy (p, s, len); 799 size = strlen (s) + 1;
802 return p; 800 return memcpy (xmalloc (size), s, size);
801}
802
803/* Like above, but duplicates Lisp string to C string. */
804
805char *
806xlispstrdup (Lisp_Object string)
807{
808 ptrdiff_t size = SBYTES (string) + 1;
809 return memcpy (xmalloc (size), SSDATA (string), size);
803} 810}
804 811
805/* Like putenv, but (1) use the equivalent of xmalloc and (2) the 812/* Like putenv, but (1) use the equivalent of xmalloc and (2) the
@@ -2798,7 +2805,7 @@ vector_nbytes (struct Lisp_Vector *v)
2798static void 2805static void
2799sweep_vectors (void) 2806sweep_vectors (void)
2800{ 2807{
2801 struct vector_block *block = vector_blocks, **bprev = &vector_blocks; 2808 struct vector_block *block, **bprev = &vector_blocks;
2802 struct large_vector *lv, **lvprev = &large_vectors; 2809 struct large_vector *lv, **lvprev = &large_vectors;
2803 struct Lisp_Vector *vector, *next; 2810 struct Lisp_Vector *vector, *next;
2804 2811
@@ -3472,6 +3479,7 @@ DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0,
3472 p->charpos = 0; 3479 p->charpos = 0;
3473 p->next = NULL; 3480 p->next = NULL;
3474 p->insertion_type = 0; 3481 p->insertion_type = 0;
3482 p->need_adjustment = 0;
3475 return val; 3483 return val;
3476} 3484}
3477 3485
@@ -3496,6 +3504,7 @@ build_marker (struct buffer *buf, ptrdiff_t charpos, ptrdiff_t bytepos)
3496 m->charpos = charpos; 3504 m->charpos = charpos;
3497 m->bytepos = bytepos; 3505 m->bytepos = bytepos;
3498 m->insertion_type = 0; 3506 m->insertion_type = 0;
3507 m->need_adjustment = 0;
3499 m->next = BUF_MARKERS (buf); 3508 m->next = BUF_MARKERS (buf);
3500 BUF_MARKERS (buf) = m; 3509 BUF_MARKERS (buf) = m;
3501 return obj; 3510 return obj;
@@ -4058,7 +4067,7 @@ live_string_p (struct mem_node *m, void *p)
4058{ 4067{
4059 if (m->type == MEM_TYPE_STRING) 4068 if (m->type == MEM_TYPE_STRING)
4060 { 4069 {
4061 struct string_block *b = (struct string_block *) m->start; 4070 struct string_block *b = m->start;
4062 ptrdiff_t offset = (char *) p - (char *) &b->strings[0]; 4071 ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
4063 4072
4064 /* P must point to the start of a Lisp_String structure, and it 4073 /* P must point to the start of a Lisp_String structure, and it
@@ -4081,7 +4090,7 @@ live_cons_p (struct mem_node *m, void *p)
4081{ 4090{
4082 if (m->type == MEM_TYPE_CONS) 4091 if (m->type == MEM_TYPE_CONS)
4083 { 4092 {
4084 struct cons_block *b = (struct cons_block *) m->start; 4093 struct cons_block *b = m->start;
4085 ptrdiff_t offset = (char *) p - (char *) &b->conses[0]; 4094 ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
4086 4095
4087 /* P must point to the start of a Lisp_Cons, not be 4096 /* P must point to the start of a Lisp_Cons, not be
@@ -4107,7 +4116,7 @@ live_symbol_p (struct mem_node *m, void *p)
4107{ 4116{
4108 if (m->type == MEM_TYPE_SYMBOL) 4117 if (m->type == MEM_TYPE_SYMBOL)
4109 { 4118 {
4110 struct symbol_block *b = (struct symbol_block *) m->start; 4119 struct symbol_block *b = m->start;
4111 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0]; 4120 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
4112 4121
4113 /* P must point to the start of a Lisp_Symbol, not be 4122 /* P must point to the start of a Lisp_Symbol, not be
@@ -4133,7 +4142,7 @@ live_float_p (struct mem_node *m, void *p)
4133{ 4142{
4134 if (m->type == MEM_TYPE_FLOAT) 4143 if (m->type == MEM_TYPE_FLOAT)
4135 { 4144 {
4136 struct float_block *b = (struct float_block *) m->start; 4145 struct float_block *b = m->start;
4137 ptrdiff_t offset = (char *) p - (char *) &b->floats[0]; 4146 ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
4138 4147
4139 /* P must point to the start of a Lisp_Float and not be 4148 /* P must point to the start of a Lisp_Float and not be
@@ -4157,7 +4166,7 @@ live_misc_p (struct mem_node *m, void *p)
4157{ 4166{
4158 if (m->type == MEM_TYPE_MISC) 4167 if (m->type == MEM_TYPE_MISC)
4159 { 4168 {
4160 struct marker_block *b = (struct marker_block *) m->start; 4169 struct marker_block *b = m->start;
4161 ptrdiff_t offset = (char *) p - (char *) &b->markers[0]; 4170 ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
4162 4171
4163 /* P must point to the start of a Lisp_Misc, not be 4172 /* P must point to the start of a Lisp_Misc, not be
@@ -4184,7 +4193,7 @@ live_vector_p (struct mem_node *m, void *p)
4184 if (m->type == MEM_TYPE_VECTOR_BLOCK) 4193 if (m->type == MEM_TYPE_VECTOR_BLOCK)
4185 { 4194 {
4186 /* This memory node corresponds to a vector block. */ 4195 /* This memory node corresponds to a vector block. */
4187 struct vector_block *block = (struct vector_block *) m->start; 4196 struct vector_block *block = m->start;
4188 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data; 4197 struct Lisp_Vector *vector = (struct Lisp_Vector *) block->data;
4189 4198
4190 /* P is in the block's allocation range. Scan the block 4199 /* P is in the block's allocation range. Scan the block
@@ -4229,6 +4238,10 @@ live_buffer_p (struct mem_node *m, void *p)
4229 4238
4230#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 4239#if GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
4231 4240
4241/* Currently not used, but may be called from gdb. */
4242
4243void dump_zombies (void) EXTERNALLY_VISIBLE;
4244
4232/* Array of objects that are kept alive because the C stack contains 4245/* Array of objects that are kept alive because the C stack contains
4233 a pattern that looks like a reference to them . */ 4246 a pattern that looks like a reference to them . */
4234 4247
@@ -4611,7 +4624,7 @@ check_gcpros (void)
4611 4624
4612#elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES 4625#elif GC_MARK_STACK == GC_USE_GCPROS_CHECK_ZOMBIES
4613 4626
4614static void 4627void
4615dump_zombies (void) 4628dump_zombies (void)
4616{ 4629{
4617 int i; 4630 int i;
@@ -4748,6 +4761,10 @@ mark_stack (void)
4748#endif 4761#endif
4749} 4762}
4750 4763
4764#else /* GC_MARK_STACK == 0 */
4765
4766#define mark_maybe_object(obj) emacs_abort ()
4767
4751#endif /* GC_MARK_STACK != 0 */ 4768#endif /* GC_MARK_STACK != 0 */
4752 4769
4753 4770
@@ -5218,7 +5235,7 @@ See Info node `(elisp)Garbage Collection'. */)
5218 ptrdiff_t i; 5235 ptrdiff_t i;
5219 bool message_p; 5236 bool message_p;
5220 ptrdiff_t count = SPECPDL_INDEX (); 5237 ptrdiff_t count = SPECPDL_INDEX ();
5221 EMACS_TIME start; 5238 struct timespec start;
5222 Lisp_Object retval = Qnil; 5239 Lisp_Object retval = Qnil;
5223 size_t tot_before = 0; 5240 size_t tot_before = 0;
5224 5241
@@ -5243,7 +5260,7 @@ See Info node `(elisp)Garbage Collection'. */)
5243 if (profiler_memory_running) 5260 if (profiler_memory_running)
5244 tot_before = total_bytes_of_live_objects (); 5261 tot_before = total_bytes_of_live_objects ();
5245 5262
5246 start = current_emacs_time (); 5263 start = current_timespec ();
5247 5264
5248 /* In case user calls debug_print during GC, 5265 /* In case user calls debug_print during GC,
5249 don't let that cause a recursive GC. */ 5266 don't let that cause a recursive GC. */
@@ -5506,9 +5523,9 @@ See Info node `(elisp)Garbage Collection'. */)
5506 /* Accumulate statistics. */ 5523 /* Accumulate statistics. */
5507 if (FLOATP (Vgc_elapsed)) 5524 if (FLOATP (Vgc_elapsed))
5508 { 5525 {
5509 EMACS_TIME since_start = sub_emacs_time (current_emacs_time (), start); 5526 struct timespec since_start = timespec_sub (current_timespec (), start);
5510 Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed) 5527 Vgc_elapsed = make_float (XFLOAT_DATA (Vgc_elapsed)
5511 + EMACS_TIME_TO_DOUBLE (since_start)); 5528 + timespectod (since_start));
5512 } 5529 }
5513 5530
5514 gcs_done++; 5531 gcs_done++;