Mercurial > emacs
comparison src/alloc.c @ 21948:d366b3e31fae
(Fmake_bool_vector): Clear out extraneous bits at end.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 05 May 1998 19:30:33 +0000 |
parents | c744d468bfb6 |
children | a0cd311af6e3 |
comparison
equal
deleted
inserted
replaced
21947:18722fb8716f | 21948:d366b3e31fae |
---|---|
1235 CHECK_NATNUM (length, 0); | 1235 CHECK_NATNUM (length, 0); |
1236 | 1236 |
1237 bits_per_value = sizeof (EMACS_INT) * BITS_PER_CHAR; | 1237 bits_per_value = sizeof (EMACS_INT) * BITS_PER_CHAR; |
1238 | 1238 |
1239 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; | 1239 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; |
1240 length_in_chars = length_in_elts * sizeof (EMACS_INT); | 1240 length_in_chars = ((XFASTINT (length) + BITS_PER_CHAR - 1) / BITS_PER_CHAR); |
1241 | 1241 |
1242 /* We must allocate one more elements than LENGTH_IN_ELTS for the | 1242 /* We must allocate one more elements than LENGTH_IN_ELTS for the |
1243 slot `size' of the struct Lisp_Bool_Vector. */ | 1243 slot `size' of the struct Lisp_Bool_Vector. */ |
1244 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); | 1244 val = Fmake_vector (make_number (length_in_elts + 1), Qnil); |
1245 p = XBOOL_VECTOR (val); | 1245 p = XBOOL_VECTOR (val); |
1249 p->size = XFASTINT (length); | 1249 p->size = XFASTINT (length); |
1250 | 1250 |
1251 real_init = (NILP (init) ? 0 : -1); | 1251 real_init = (NILP (init) ? 0 : -1); |
1252 for (i = 0; i < length_in_chars ; i++) | 1252 for (i = 0; i < length_in_chars ; i++) |
1253 p->data[i] = real_init; | 1253 p->data[i] = real_init; |
1254 /* Clear the extraneous bits in the last byte. */ | |
1255 if (XINT (length) != length_in_chars * BITS_PER_CHAR) | |
1256 XBOOL_VECTOR (val)->data[length_in_chars - 1] | |
1257 &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1; | |
1254 | 1258 |
1255 return val; | 1259 return val; |
1256 } | 1260 } |
1257 | 1261 |
1258 /* Make a string from NBYTES bytes at CONTENTS, | 1262 /* Make a string from NBYTES bytes at CONTENTS, |