+2012-07-03 Dmitry Antipov <dmantipov@yandex.ru>
+
+ 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.
+
2012-07-03 Stefan Monnier <monnier@iro.umontreal.ca>
* lisp.h (Lisp_Misc, Lisp_Fwd): Move around to group better.
#define VECTOR_BLOCK_SIZE 4096
+/* This special value is used to calculate vector size when the vector is
+ on a free list. It should be VECTOR_BLOCK_SIZE rounded up to nearest
+ power of two, minus one. */
+
+#define VECTOR_FREE_LIST_SIZE_MASK 4095
+
/* Handy constants for vectorlike objects. */
enum
{
/* ROUNDUP_SIZE must be a power of 2. */
verify ((roundup_size & (roundup_size - 1)) == 0);
+/* Verify assumptions described above. */
+verify ((VECTOR_BLOCK_SIZE % roundup_size) == 0);
+verify ((VECTOR_FREE_LIST_SIZE_MASK + 1) >= VECTOR_BLOCK_SIZE);
+verify ((VECTOR_FREE_LIST_SIZE_MASK & (VECTOR_FREE_LIST_SIZE_MASK + 1)) == 0);
+
/* Round up X to nearest mult-of-ROUNDUP_SIZE. */
#define vroundup(x) (((x) + (roundup_size - 1)) & ~(roundup_size - 1))
this special value ORed with vector's memory footprint size. */
#define VECTOR_FREE_LIST_FLAG (~(ARRAY_MARK_FLAG | PSEUDOVECTOR_FLAG \
- | (VECTOR_BLOCK_SIZE - 1)))
+ | VECTOR_FREE_LIST_SIZE_MASK))
/* Common shortcut to advance vector pointer over a block data. */
if ((vector->header.size & VECTOR_FREE_LIST_FLAG)
== VECTOR_FREE_LIST_FLAG)
vector->header.next.nbytes =
- vector->header.size & (VECTOR_BLOCK_SIZE - 1);
+ vector->header.size & VECTOR_FREE_LIST_SIZE_MASK;
next = ADVANCE (vector, vector->header.next.nbytes);
break;
if ((next->header.size & VECTOR_FREE_LIST_FLAG)
== VECTOR_FREE_LIST_FLAG)
- nbytes = next->header.size & (VECTOR_BLOCK_SIZE - 1);
+ nbytes = next->header.size & VECTOR_FREE_LIST_SIZE_MASK;
else
nbytes = next->header.next.nbytes;
vector->header.next.nbytes += nbytes;
if ((vector->header.size & VECTOR_FREE_LIST_FLAG)
== VECTOR_FREE_LIST_FLAG)
vector = ADVANCE (vector, (vector->header.size
- & (VECTOR_BLOCK_SIZE - 1)));
+ & VECTOR_FREE_LIST_SIZE_MASK));
else if (vector == p)
return 1;
else