aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-03 20:35:53 +0400
committerDmitry Antipov2012-07-03 20:35:53 +0400
commitca95b3ebc8587780966cee0acfe0f7822e895f83 (patch)
treed12f6c2196df74fb26320185fee572b437203b50 /src
parent7555c33f15ef5ae98508daf9b17b03aea379c78f (diff)
downloademacs-ca95b3ebc8587780966cee0acfe0f7822e895f83.tar.gz
emacs-ca95b3ebc8587780966cee0acfe0f7822e895f83.zip
Fix block vector allocation code to allow VECTOR_BLOCK_SIZE
values which aren't power of 2. * alloc.c (VECTOR_FREE_LIST_SIZE_MASK): New macro. Verify it's value and the value of VECTOR_BLOCK_SIZE. Adjust users accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/alloc.c19
2 files changed, 23 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index aca64a79961..e3993981317 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12012-07-03 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Fix block vector allocation code to allow VECTOR_BLOCK_SIZE
4 values which aren't power of 2.
5 * alloc.c (VECTOR_FREE_LIST_SIZE_MASK): New macro. Verify
6 it's value and the value of VECTOR_BLOCK_SIZE. Adjust users
7 accordingly.
8
12012-07-03 Stefan Monnier <monnier@iro.umontreal.ca> 92012-07-03 Stefan Monnier <monnier@iro.umontreal.ca>
2 10
3 * lisp.h (Lisp_Misc, Lisp_Fwd): Move around to group better. 11 * lisp.h (Lisp_Misc, Lisp_Fwd): Move around to group better.
diff --git a/src/alloc.c b/src/alloc.c
index 19972d54670..b1e2ed0a2ed 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -2869,6 +2869,12 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
2869 2869
2870#define VECTOR_BLOCK_SIZE 4096 2870#define VECTOR_BLOCK_SIZE 4096
2871 2871
2872/* This special value is used to calculate vector size when the vector is
2873 on a free list. It should be VECTOR_BLOCK_SIZE rounded up to nearest
2874 power of two, minus one. */
2875
2876#define VECTOR_FREE_LIST_SIZE_MASK 4095
2877
2872/* Handy constants for vectorlike objects. */ 2878/* Handy constants for vectorlike objects. */
2873enum 2879enum
2874 { 2880 {
@@ -2881,6 +2887,11 @@ enum
2881/* ROUNDUP_SIZE must be a power of 2. */ 2887/* ROUNDUP_SIZE must be a power of 2. */
2882verify ((roundup_size & (roundup_size - 1)) == 0); 2888verify ((roundup_size & (roundup_size - 1)) == 0);
2883 2889
2890/* Verify assumptions described above. */
2891verify ((VECTOR_BLOCK_SIZE % roundup_size) == 0);
2892verify ((VECTOR_FREE_LIST_SIZE_MASK + 1) >= VECTOR_BLOCK_SIZE);
2893verify ((VECTOR_FREE_LIST_SIZE_MASK & (VECTOR_FREE_LIST_SIZE_MASK + 1)) == 0);
2894
2884/* Round up X to nearest mult-of-ROUNDUP_SIZE. */ 2895/* Round up X to nearest mult-of-ROUNDUP_SIZE. */
2885 2896
2886#define vroundup(x) (((x) + (roundup_size - 1)) & ~(roundup_size - 1)) 2897#define vroundup(x) (((x) + (roundup_size - 1)) & ~(roundup_size - 1))
@@ -2908,7 +2919,7 @@ verify ((roundup_size & (roundup_size - 1)) == 0);
2908 this special value ORed with vector's memory footprint size. */ 2919 this special value ORed with vector's memory footprint size. */
2909 2920
2910#define VECTOR_FREE_LIST_FLAG (~(ARRAY_MARK_FLAG | PSEUDOVECTOR_FLAG \ 2921#define VECTOR_FREE_LIST_FLAG (~(ARRAY_MARK_FLAG | PSEUDOVECTOR_FLAG \
2911 | (VECTOR_BLOCK_SIZE - 1))) 2922 | VECTOR_FREE_LIST_SIZE_MASK))
2912 2923
2913/* Common shortcut to advance vector pointer over a block data. */ 2924/* Common shortcut to advance vector pointer over a block data. */
2914 2925
@@ -3087,7 +3098,7 @@ sweep_vectors (void)
3087 if ((vector->header.size & VECTOR_FREE_LIST_FLAG) 3098 if ((vector->header.size & VECTOR_FREE_LIST_FLAG)
3088 == VECTOR_FREE_LIST_FLAG) 3099 == VECTOR_FREE_LIST_FLAG)
3089 vector->header.next.nbytes = 3100 vector->header.next.nbytes =
3090 vector->header.size & (VECTOR_BLOCK_SIZE - 1); 3101 vector->header.size & VECTOR_FREE_LIST_SIZE_MASK;
3091 3102
3092 next = ADVANCE (vector, vector->header.next.nbytes); 3103 next = ADVANCE (vector, vector->header.next.nbytes);
3093 3104
@@ -3100,7 +3111,7 @@ sweep_vectors (void)
3100 break; 3111 break;
3101 if ((next->header.size & VECTOR_FREE_LIST_FLAG) 3112 if ((next->header.size & VECTOR_FREE_LIST_FLAG)
3102 == VECTOR_FREE_LIST_FLAG) 3113 == VECTOR_FREE_LIST_FLAG)
3103 nbytes = next->header.size & (VECTOR_BLOCK_SIZE - 1); 3114 nbytes = next->header.size & VECTOR_FREE_LIST_SIZE_MASK;
3104 else 3115 else
3105 nbytes = next->header.next.nbytes; 3116 nbytes = next->header.next.nbytes;
3106 vector->header.next.nbytes += nbytes; 3117 vector->header.next.nbytes += nbytes;
@@ -4334,7 +4345,7 @@ live_vector_p (struct mem_node *m, void *p)
4334 if ((vector->header.size & VECTOR_FREE_LIST_FLAG) 4345 if ((vector->header.size & VECTOR_FREE_LIST_FLAG)
4335 == VECTOR_FREE_LIST_FLAG) 4346 == VECTOR_FREE_LIST_FLAG)
4336 vector = ADVANCE (vector, (vector->header.size 4347 vector = ADVANCE (vector, (vector->header.size
4337 & (VECTOR_BLOCK_SIZE - 1))); 4348 & VECTOR_FREE_LIST_SIZE_MASK));
4338 else if (vector == p) 4349 else if (vector == p)
4339 return 1; 4350 return 1;
4340 else 4351 else