From fea99690f2e31b08d4261d91509c6fed7d945125 Mon Sep 17 00:00:00 2001 From: Marius Vollmer Date: Thu, 6 Jan 2005 18:44:08 +0000 Subject: [PATCH] (scm_c_uniform_vector_element_size, scm_c_uniform_vector_size): Removed. (scm_array_handle_uniform_element_size): New. --- libguile/srfi-4.c | 35 ++++++++++++++++------------------- libguile/srfi-4.h | 3 +-- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/libguile/srfi-4.c b/libguile/srfi-4.c index 61995c662..eb61b31c2 100644 --- a/libguile/srfi-4.c +++ b/libguile/srfi-4.c @@ -482,15 +482,6 @@ scm_c_uniform_vector_length (SCM v) scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); } -size_t -scm_c_uniform_vector_size (SCM v) -{ - if (scm_is_uniform_vector (v)) - return SCM_UVEC_LENGTH (v) * uvec_sizes[SCM_UVEC_TYPE (v)]; - else - scm_wrong_type_arg_msg (NULL, 0, v, "uniform vector"); -} - SCM_DEFINE (scm_uniform_vector_p, "uniform-vector?", 1, 0, 0, (SCM obj), "Return @code{#t} if @var{obj} is a uniform vector.") @@ -585,21 +576,23 @@ SCM_DEFINE (scm_uniform_vector_to_list, "uniform-vector->list", 1, 0, 0, #undef FUNC_NAME size_t -scm_uniform_vector_element_size (SCM uvec) +scm_array_handle_uniform_element_size (scm_t_array_handle *h) { - if (scm_is_uniform_vector (uvec)) - return uvec_sizes[SCM_UVEC_TYPE (uvec)]; - else - scm_wrong_type_arg_msg (NULL, 0, uvec, "uniform vector"); + SCM vec = h->array; + if (SCM_ARRAYP (vec)) + vec = SCM_ARRAY_V (vec); + if (scm_is_uniform_vector (vec)) + return uvec_sizes[SCM_UVEC_TYPE(vec)]; + scm_wrong_type_arg_msg (NULL, 0, h->array, "uniform array"); } - + /* return the size of an element in a uniform array or 0 if type not found. */ size_t scm_uniform_element_size (SCM obj) { if (scm_is_uniform_vector (obj)) - return scm_uniform_vector_element_size (obj); + return uvec_sizes[SCM_UVEC_TYPE(obj)]; else return 0; } @@ -638,7 +631,7 @@ scm_uniform_vector_writable_elements (SCM uvec, scm_t_array_handle *h, size_t *lenp, ssize_t *incp) { - scm_vector_get_handle (uvec, h); + scm_generalized_vector_get_handle (uvec, h); if (lenp) { scm_t_array_dim *dim = scm_array_handle_dims (h); @@ -696,7 +689,7 @@ SCM_DEFINE (scm_uniform_vector_read_x, "uniform-vector-read!", 1, 3, 0, scm_wrong_type_arg_msg (NULL, 0, uvec, "uniform vector"); base = scm_uniform_vector_writable_elements (uvec, &handle, &vlen, &inc); - sz = scm_uniform_vector_element_size (uvec); + sz = scm_array_handle_uniform_element_size (&handle); if (inc != 1) { @@ -765,6 +758,8 @@ SCM_DEFINE (scm_uniform_vector_read_x, "uniform-vector-read!", 1, 3, 0, ans = n / sz; } + scm_array_handle_release (&handle); + return scm_from_size_t (ans); } #undef FUNC_NAME @@ -806,7 +801,7 @@ SCM_DEFINE (scm_uniform_vector_write, "uniform-vector-write", 1, 3, 0, port_or_fd, SCM_ARG2, FUNC_NAME); base = scm_uniform_vector_elements (uvec, &handle, &vlen, &inc); - sz = scm_uniform_vector_element_size (uvec); + sz = scm_array_handle_uniform_element_size (&handle); if (inc != 1) { @@ -843,6 +838,8 @@ SCM_DEFINE (scm_uniform_vector_write, "uniform-vector-write", 1, 3, 0, ans = n / sz; } + scm_array_handle_release (&handle); + return scm_from_size_t (ans); } #undef FUNC_NAME diff --git a/libguile/srfi-4.h b/libguile/srfi-4.h index a04148dac..07a6f03b0 100644 --- a/libguile/srfi-4.h +++ b/libguile/srfi-4.h @@ -38,10 +38,9 @@ SCM_API SCM scm_uniform_vector_write (SCM v, SCM port_or_fd, SCM_API int scm_is_uniform_vector (SCM obj); SCM_API size_t scm_c_uniform_vector_length (SCM v); -SCM_API size_t scm_c_uniform_vector_size (SCM v); SCM_API SCM scm_c_uniform_vector_ref (SCM v, size_t idx); SCM_API void scm_c_uniform_vector_set_x (SCM v, size_t idx, SCM val); -SCM_API size_t scm_uniform_vector_element_size (SCM v); +SCM_API size_t scm_array_handle_uniform_element_size (scm_t_array_handle *h); SCM_API const void *scm_array_handle_uniform_elements (scm_t_array_handle *h); SCM_API void *scm_array_handle_uniform_writable_elements (scm_t_array_handle *h); SCM_API const void *scm_uniform_vector_elements (SCM uvec,