diff options
author | Andy Wingo <wingo@pobox.com> | 2009-09-17 13:52:09 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-09-18 16:27:32 +0200 |
commit | f5a51caec1bf1900b269da6e07fe466199372970 (patch) | |
tree | e554326259aa903c6e450e0e10ed36208f5b9d81 /libguile/arrays.c | |
parent | c5923112fed7b92ff5f1eeea03c74117b2f75490 (diff) | |
download | guile-f5a51caec1bf1900b269da6e07fe466199372970.tar.gz |
fix bitvectors after the array handle refactoring
* libguile/uniform.h (scm_array_handle_uniform_element_bit_size): New
public accessor.
* libguile/uniform.c (scm_array_handle_uniform_element_size): Better
errors in non-byte-aligned arrays.
(scm_uniform_vector_element_type, scm_uniform_vector_element_size)
(scm_c_uniform_vector_ref, scm_c_uniform_vector_set_x):
(scm_uniform_vector_to_list): Don't require byte-aligned access.
* libguile/bytevectors.c (scm_uniform_array_to_bytevector):
* libguile/arrays.c (scm_from_contiguous_typed_array): Fix for
uniform arrays whose element size is not a multiple of the byte size.
Diffstat (limited to 'libguile/arrays.c')
-rw-r--r-- | libguile/arrays.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/libguile/arrays.c b/libguile/arrays.c index 2be9ec3f0..62ce83e3b 100644 --- a/libguile/arrays.c +++ b/libguile/arrays.c @@ -211,7 +211,7 @@ scm_from_contiguous_typed_array (SCM type, SCM bounds, const void *bytes, scm_t_array_dim *s; SCM ra; scm_t_array_handle h; - void *base; + void *elts; size_t sz; ra = scm_i_shap2ra (bounds); @@ -230,16 +230,24 @@ scm_from_contiguous_typed_array (SCM type, SCM bounds, const void *bytes, scm_array_get_handle (ra, &h); - base = scm_array_handle_uniform_writable_elements (&h); - sz = scm_array_handle_uniform_element_size (&h); + elts = h.writable_elements; + sz = scm_array_handle_uniform_element_bit_size (&h); scm_array_handle_release (&h); - if (byte_len % sz) - SCM_MISC_ERROR ("byte length not a multiple of the unit size", SCM_EOL); - if (byte_len / sz != rlen) - SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL); + if (sz >= 8 && ((sz % 8) == 0)) + { + if (byte_len % (sz / 8)) + SCM_MISC_ERROR ("byte length not a multiple of the unit size", SCM_EOL); + if (byte_len / (sz / 8) != rlen) + SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL); + } + else + { + if (rlen * (sz / 8) + rlen * (sz % 8) / 8 != byte_len) + SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL); + } - memcpy (base, bytes, byte_len); + memcpy (elts, bytes, byte_len); if (1 == SCM_I_ARRAY_NDIM (ra) && 0 == SCM_I_ARRAY_BASE (ra)) if (s->ubnd < s->lbnd || (0 == s->lbnd && 1 == s->inc)) |