mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 11:40:18 +02:00
bitvector tweaks
* libguile/arrays.c (scm_from_contiguous_typed_array): * libguile/bytevectors.c (scm_uniform_array_to_bytevector): Error if the uniform element size is more than 8 bits, but not divisible by 8 -- because our math could overflow in that case. * module/ice-9/deprecated.scm (#\y): Indeed, #* is the valid bitvector syntax :)
This commit is contained in:
parent
96e15df109
commit
b0fae4ecaa
3 changed files with 9 additions and 3 deletions
|
@ -241,12 +241,15 @@ scm_from_contiguous_typed_array (SCM type, SCM bounds, const void *bytes,
|
||||||
if (byte_len / (sz / 8) != rlen)
|
if (byte_len / (sz / 8) != rlen)
|
||||||
SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
|
SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
|
||||||
}
|
}
|
||||||
else
|
else if (sz < 8)
|
||||||
{
|
{
|
||||||
/* byte_len ?= ceil (rlen * sz / 8) */
|
/* byte_len ?= ceil (rlen * sz / 8) */
|
||||||
if (byte_len != (rlen * sz + 7) / 8)
|
if (byte_len != (rlen * sz + 7) / 8)
|
||||||
SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
|
SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
/* an internal guile error, really */
|
||||||
|
SCM_MISC_ERROR ("uniform elements larger than 8 bits must fill whole bytes", SCM_EOL);
|
||||||
|
|
||||||
memcpy (elts, bytes, byte_len);
|
memcpy (elts, bytes, byte_len);
|
||||||
|
|
||||||
|
|
|
@ -604,9 +604,12 @@ SCM_DEFINE (scm_uniform_array_to_bytevector, "uniform-array->bytevector",
|
||||||
sz = scm_array_handle_uniform_element_bit_size (&h);
|
sz = scm_array_handle_uniform_element_bit_size (&h);
|
||||||
if (sz >= 8 && ((sz % 8) == 0))
|
if (sz >= 8 && ((sz % 8) == 0))
|
||||||
byte_len = len * (sz / 8);
|
byte_len = len * (sz / 8);
|
||||||
else
|
else if (sz < 8)
|
||||||
/* byte_len = ceil (len * sz / 8) */
|
/* byte_len = ceil (len * sz / 8) */
|
||||||
byte_len = (len * sz + 7) / 8;
|
byte_len = (len * sz + 7) / 8;
|
||||||
|
else
|
||||||
|
/* an internal guile error, really */
|
||||||
|
SCM_MISC_ERROR ("uniform elements larger than 8 bits must fill whole bytes", SCM_EOL);
|
||||||
|
|
||||||
ret = make_bytevector (byte_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
|
ret = make_bytevector (byte_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
|
||||||
memcpy (SCM_BYTEVECTOR_CONTENTS (ret), elts, byte_len);
|
memcpy (SCM_BYTEVECTOR_CONTENTS (ret), elts, byte_len);
|
||||||
|
|
|
@ -190,7 +190,7 @@
|
||||||
#\y
|
#\y
|
||||||
(lambda (c port)
|
(lambda (c port)
|
||||||
(issue-deprecation-warning
|
(issue-deprecation-warning
|
||||||
"The `#y' bitvector syntax is deprecated. Use `bitvector' instead.")
|
"The `#y' bitvector syntax is deprecated. Use `#*' instead.")
|
||||||
(let ((x (read port)))
|
(let ((x (read port)))
|
||||||
(cond
|
(cond
|
||||||
((list? x)
|
((list? x)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue