1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 13:00:26 +02:00

Do not use array handles in scm_vector

* libguile/vectors.c (scm_vector): Use SCM_I_VECTOR_WELTS on new vector
  instead of generic scm_vector_elements; cf. scm_vector_copy().

  (scm_vector_elements): Forward to scm_vector_writable_elements().

  (scm_vector_writable_elements): Remove special error message for weak
  vector arg.

* libguile/generalized-vectors.c (SCM_VALIDATE_VECTOR_WITH_HANDLE):
  Remove unused macro.

* libguile/array-handle.c (scm_array_handle_elements): Forward to
  scm_array_handle_writable_elements().
This commit is contained in:
Daniel Llorens 2015-02-25 09:47:40 +01:00
parent cea5139e65
commit da81901c9a
3 changed files with 19 additions and 41 deletions

View file

@ -320,9 +320,7 @@ scm_array_handle_release (scm_t_array_handle *h)
const SCM * const SCM *
scm_array_handle_elements (scm_t_array_handle *h) scm_array_handle_elements (scm_t_array_handle *h)
{ {
if (h->element_type != SCM_ARRAY_ELEMENT_TYPE_SCM) return scm_array_handle_writable_elements (h);
scm_wrong_type_arg_msg (NULL, 0, h->array, "non-uniform array");
return ((const SCM*)h->elements) + h->base;
} }
SCM * SCM *

View file

@ -70,10 +70,6 @@ SCM_DEFINE (scm_make_generalized_vector, "make-generalized-vector", 2, 1, 0,
#undef FUNC_NAME #undef FUNC_NAME
#define SCM_VALIDATE_VECTOR_WITH_HANDLE(pos, val, handle) \
scm_generalized_vector_get_handle (val, handle)
void void
scm_generalized_vector_get_handle (SCM vec, scm_t_array_handle *h) scm_generalized_vector_get_handle (SCM vec, scm_t_array_handle *h)
{ {

View file

@ -59,26 +59,13 @@ const SCM *
scm_vector_elements (SCM vec, scm_t_array_handle *h, scm_vector_elements (SCM vec, scm_t_array_handle *h,
size_t *lenp, ssize_t *incp) size_t *lenp, ssize_t *incp)
{ {
if (SCM_I_WVECTP (vec)) return scm_vector_writable_elements (vec, h, lenp, incp);
scm_wrong_type_arg_msg (NULL, 0, vec, "non-weak vector");
scm_generalized_vector_get_handle (vec, h);
if (lenp)
{
scm_t_array_dim *dim = scm_array_handle_dims (h);
*lenp = dim->ubnd - dim->lbnd + 1;
*incp = dim->inc;
}
return scm_array_handle_elements (h);
} }
SCM * SCM *
scm_vector_writable_elements (SCM vec, scm_t_array_handle *h, scm_vector_writable_elements (SCM vec, scm_t_array_handle *h,
size_t *lenp, ssize_t *incp) size_t *lenp, ssize_t *incp)
{ {
if (SCM_I_WVECTP (vec))
scm_wrong_type_arg_msg (NULL, 0, vec, "non-weak vector");
scm_generalized_vector_get_handle (vec, h); scm_generalized_vector_get_handle (vec, h);
if (lenp) if (lenp)
{ {
@ -141,12 +128,11 @@ SCM_DEFINE (scm_vector, "vector", 0, 0, 1,
SCM res; SCM res;
SCM *data; SCM *data;
long i, len; long i, len;
scm_t_array_handle handle;
SCM_VALIDATE_LIST_COPYLEN (1, l, len); SCM_VALIDATE_LIST_COPYLEN (1, l, len);
res = scm_c_make_vector (len, SCM_UNSPECIFIED); res = scm_c_make_vector (len, SCM_UNSPECIFIED);
data = scm_vector_writable_elements (res, &handle, NULL, NULL); data = SCM_I_VECTOR_WELTS (res);
i = 0; i = 0;
while (scm_is_pair (l) && i < len) while (scm_is_pair (l) && i < len)
{ {
@ -155,8 +141,6 @@ SCM_DEFINE (scm_vector, "vector", 0, 0, 1,
i += 1; i += 1;
} }
scm_array_handle_release (&handle);
return res; return res;
} }
#undef FUNC_NAME #undef FUNC_NAME