aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorMichael R. Mauger2017-07-03 15:32:41 -0400
committerMichael R. Mauger2017-07-03 15:32:41 -0400
commit776635c01abd4aa759e7aa9584b513146978568c (patch)
tree554f444bc96cb6b05435e8bf195de4df1b00df8f /src/alloc.c
parent77083e2d34ba5559ae2899d3b03cf08c2e6c5ad4 (diff)
parent4cd0db3d6e6e4d5bd49283483bdafbbfc0f583f1 (diff)
downloademacs-776635c01abd4aa759e7aa9584b513146978568c.tar.gz
emacs-776635c01abd4aa759e7aa9584b513146978568c.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c79
1 files changed, 69 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c
index ae3e1519c04..ac3de83b2b6 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -75,14 +75,20 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
75static bool valgrind_p; 75static bool valgrind_p;
76#endif 76#endif
77 77
78/* GC_CHECK_MARKED_OBJECTS means do sanity checks on allocated objects. */ 78/* GC_CHECK_MARKED_OBJECTS means do sanity checks on allocated objects.
79 We turn that on by default when ENABLE_CHECKING is defined;
80 define GC_CHECK_MARKED_OBJECTS to zero to disable. */
81
82#if defined ENABLE_CHECKING && !defined GC_CHECK_MARKED_OBJECTS
83# define GC_CHECK_MARKED_OBJECTS 1
84#endif
79 85
80/* GC_MALLOC_CHECK defined means perform validity checks of malloc'd 86/* GC_MALLOC_CHECK defined means perform validity checks of malloc'd
81 memory. Can do this only if using gmalloc.c and if not checking 87 memory. Can do this only if using gmalloc.c and if not checking
82 marked objects. */ 88 marked objects. */
83 89
84#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \ 90#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \
85 || defined HYBRID_MALLOC || defined GC_CHECK_MARKED_OBJECTS) 91 || defined HYBRID_MALLOC || GC_CHECK_MARKED_OBJECTS)
86#undef GC_MALLOC_CHECK 92#undef GC_MALLOC_CHECK
87#endif 93#endif
88 94
@@ -3371,7 +3377,7 @@ allocate_pseudovector (int memlen, int lisplen,
3371 eassert (0 <= tag && tag <= PVEC_FONT); 3377 eassert (0 <= tag && tag <= PVEC_FONT);
3372 eassert (0 <= lisplen && lisplen <= zerolen && zerolen <= memlen); 3378 eassert (0 <= lisplen && lisplen <= zerolen && zerolen <= memlen);
3373 eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1); 3379 eassert (memlen - lisplen <= (1 << PSEUDOVECTOR_REST_BITS) - 1);
3374 eassert (lisplen <= (1 << PSEUDOVECTOR_SIZE_BITS) - 1); 3380 eassert (lisplen <= PSEUDOVECTOR_SIZE_MASK);
3375 3381
3376 /* Only the first LISPLEN slots will be traced normally by the GC. */ 3382 /* Only the first LISPLEN slots will be traced normally by the GC. */
3377 memclear (v->contents, zerolen * word_size); 3383 memclear (v->contents, zerolen * word_size);
@@ -3392,6 +3398,54 @@ allocate_buffer (void)
3392 return b; 3398 return b;
3393} 3399}
3394 3400
3401
3402/* Allocate a record with COUNT slots. COUNT must be positive, and
3403 includes the type slot. */
3404
3405static struct Lisp_Vector *
3406allocate_record (EMACS_INT count)
3407{
3408 if (count > PSEUDOVECTOR_SIZE_MASK)
3409 error ("Attempt to allocate a record of %"pI"d slots; max is %d",
3410 count, PSEUDOVECTOR_SIZE_MASK);
3411 struct Lisp_Vector *p = allocate_vectorlike (count);
3412 p->header.size = count;
3413 XSETPVECTYPE (p, PVEC_RECORD);
3414 return p;
3415}
3416
3417
3418DEFUN ("make-record", Fmake_record, Smake_record, 3, 3, 0,
3419 doc: /* Create a new record.
3420TYPE is its type as returned by `type-of'; it should be either a
3421symbol or a type descriptor. SLOTS is the number of non-type slots,
3422each initialized to INIT. */)
3423 (Lisp_Object type, Lisp_Object slots, Lisp_Object init)
3424{
3425 CHECK_NATNUM (slots);
3426 EMACS_INT size = XFASTINT (slots) + 1;
3427 struct Lisp_Vector *p = allocate_record (size);
3428 p->contents[0] = type;
3429 for (ptrdiff_t i = 1; i < size; i++)
3430 p->contents[i] = init;
3431 return make_lisp_ptr (p, Lisp_Vectorlike);
3432}
3433
3434
3435DEFUN ("record", Frecord, Srecord, 1, MANY, 0,
3436 doc: /* Create a new record.
3437TYPE is its type as returned by `type-of'; it should be either a
3438symbol or a type descriptor. SLOTS is used to initialize the record
3439slots with shallow copies of the arguments.
3440usage: (record TYPE &rest SLOTS) */)
3441 (ptrdiff_t nargs, Lisp_Object *args)
3442{
3443 struct Lisp_Vector *p = allocate_record (nargs);
3444 memcpy (p->contents, args, nargs * sizeof *args);
3445 return make_lisp_ptr (p, Lisp_Vectorlike);
3446}
3447
3448
3395DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, 3449DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
3396 doc: /* Return a newly created vector of length LENGTH, with each element being INIT. 3450 doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
3397See also the function `vector'. */) 3451See also the function `vector'. */)
@@ -3888,7 +3942,6 @@ make_user_ptr (void (*finalizer) (void *), void *p)
3888 uptr->p = p; 3942 uptr->p = p;
3889 return obj; 3943 return obj;
3890} 3944}
3891
3892#endif 3945#endif
3893 3946
3894static void 3947static void
@@ -5532,7 +5585,7 @@ purecopy (Lisp_Object obj)
5532 struct Lisp_Hash_Table *h = purecopy_hash_table (table); 5585 struct Lisp_Hash_Table *h = purecopy_hash_table (table);
5533 XSET_HASH_TABLE (obj, h); 5586 XSET_HASH_TABLE (obj, h);
5534 } 5587 }
5535 else if (COMPILEDP (obj) || VECTORP (obj)) 5588 else if (COMPILEDP (obj) || VECTORP (obj) || RECORDP (obj))
5536 { 5589 {
5537 struct Lisp_Vector *objp = XVECTOR (obj); 5590 struct Lisp_Vector *objp = XVECTOR (obj);
5538 ptrdiff_t nbytes = vector_nbytes (objp); 5591 ptrdiff_t nbytes = vector_nbytes (objp);
@@ -5889,6 +5942,10 @@ garbage_collect_1 (void *end)
5889 mark_fringe_data (); 5942 mark_fringe_data ();
5890#endif 5943#endif
5891 5944
5945#ifdef HAVE_MODULES
5946 mark_modules ();
5947#endif
5948
5892 /* Everything is now marked, except for the data in font caches, 5949 /* Everything is now marked, except for the data in font caches,
5893 undo lists, and finalizers. The first two are compacted by 5950 undo lists, and finalizers. The first two are compacted by
5894 removing an items which aren't reachable otherwise. */ 5951 removing an items which aren't reachable otherwise. */
@@ -6295,7 +6352,7 @@ mark_object (Lisp_Object arg)
6295{ 6352{
6296 register Lisp_Object obj; 6353 register Lisp_Object obj;
6297 void *po; 6354 void *po;
6298#ifdef GC_CHECK_MARKED_OBJECTS 6355#if GC_CHECK_MARKED_OBJECTS
6299 struct mem_node *m; 6356 struct mem_node *m;
6300#endif 6357#endif
6301 ptrdiff_t cdr_count = 0; 6358 ptrdiff_t cdr_count = 0;
@@ -6314,7 +6371,7 @@ mark_object (Lisp_Object arg)
6314 /* Perform some sanity checks on the objects marked here. Abort if 6371 /* Perform some sanity checks on the objects marked here. Abort if
6315 we encounter an object we know is bogus. This increases GC time 6372 we encounter an object we know is bogus. This increases GC time
6316 by ~80%. */ 6373 by ~80%. */
6317#ifdef GC_CHECK_MARKED_OBJECTS 6374#if GC_CHECK_MARKED_OBJECTS
6318 6375
6319 /* Check that the object pointed to by PO is known to be a Lisp 6376 /* Check that the object pointed to by PO is known to be a Lisp
6320 structure allocated from the heap. */ 6377 structure allocated from the heap. */
@@ -6383,7 +6440,7 @@ mark_object (Lisp_Object arg)
6383 if (VECTOR_MARKED_P (ptr)) 6440 if (VECTOR_MARKED_P (ptr))
6384 break; 6441 break;
6385 6442
6386#ifdef GC_CHECK_MARKED_OBJECTS 6443#if GC_CHECK_MARKED_OBJECTS
6387 m = mem_find (po); 6444 m = mem_find (po);
6388 if (m == MEM_NIL && !SUBRP (obj) && !main_thread_p (po)) 6445 if (m == MEM_NIL && !SUBRP (obj) && !main_thread_p (po))
6389 emacs_abort (); 6446 emacs_abort ();
@@ -6400,7 +6457,7 @@ mark_object (Lisp_Object arg)
6400 switch (pvectype) 6457 switch (pvectype)
6401 { 6458 {
6402 case PVEC_BUFFER: 6459 case PVEC_BUFFER:
6403#ifdef GC_CHECK_MARKED_OBJECTS 6460#if GC_CHECK_MARKED_OBJECTS
6404 { 6461 {
6405 struct buffer *b; 6462 struct buffer *b;
6406 FOR_EACH_BUFFER (b) 6463 FOR_EACH_BUFFER (b)
@@ -7107,7 +7164,7 @@ We divide the value by 1024 to make sure it fits in a Lisp integer. */)
7107{ 7164{
7108 Lisp_Object end; 7165 Lisp_Object end;
7109 7166
7110#if defined HAVE_NS || !HAVE_SBRK 7167#if defined HAVE_NS || defined __APPLE__ || !HAVE_SBRK
7111 /* Avoid warning. sbrk has no relation to memory allocated anyway. */ 7168 /* Avoid warning. sbrk has no relation to memory allocated anyway. */
7112 XSETINT (end, 0); 7169 XSETINT (end, 0);
7113#else 7170#else
@@ -7461,10 +7518,12 @@ The time is in seconds as a floating point value. */);
7461 defsubr (&Scons); 7518 defsubr (&Scons);
7462 defsubr (&Slist); 7519 defsubr (&Slist);
7463 defsubr (&Svector); 7520 defsubr (&Svector);
7521 defsubr (&Srecord);
7464 defsubr (&Sbool_vector); 7522 defsubr (&Sbool_vector);
7465 defsubr (&Smake_byte_code); 7523 defsubr (&Smake_byte_code);
7466 defsubr (&Smake_list); 7524 defsubr (&Smake_list);
7467 defsubr (&Smake_vector); 7525 defsubr (&Smake_vector);
7526 defsubr (&Smake_record);
7468 defsubr (&Smake_string); 7527 defsubr (&Smake_string);
7469 defsubr (&Smake_bool_vector); 7528 defsubr (&Smake_bool_vector);
7470 defsubr (&Smake_symbol); 7529 defsubr (&Smake_symbol);