From 7c3f72776d276684c697ec5da1c3af8511bc3823 Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Tue, 12 Jun 2012 22:41:21 +0200 Subject: [PATCH] New function ecl_array_rank() --- src/c/array.d | 23 +++++++++++++++++++---- src/h/external.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/c/array.d b/src/c/array.d index 3b7eb41d1..635b30dc5 100644 --- a/src/c/array.d +++ b/src/c/array.d @@ -847,10 +847,25 @@ ecl_array_elttype(cl_object x) cl_object cl_array_rank(cl_object a) { - if (ecl_unlikely(!ECL_ARRAYP(a))) - FEwrong_type_only_arg(@[array-rank], a, @[array]); - @(return ((type_of(a) == t_array) ? ecl_make_fixnum(a->array.rank) - : ecl_make_fixnum(1))) + @(return ecl_make_fixnum(ecl_array_rank(a))) +} + +cl_index +ecl_array_rank(cl_object a) +{ + switch (type_of(a)) { + case t_array: + return a->array.rank; +#ifdef ECL_UNICODE + case t_string: +#endif + case t_base_string: + case t_vector: + case t_bitvector: + return 1; + default: + FEwrong_type_only_arg(@[array-dimension], a, @[array]); + } } cl_object diff --git a/src/h/external.h b/src/h/external.h index 50716e56a..6d9e1d5f7 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -357,6 +357,7 @@ extern ECL_API cl_object si_fill_array_with_elt(cl_object array, cl_object elt, extern ECL_API void FEwrong_dimensions(cl_object a, cl_index rank) ecl_attr_noreturn; extern ECL_API cl_index ecl_to_index(cl_object n); extern ECL_API cl_index ecl_array_dimension(cl_object x, cl_index n); +extern ECL_API cl_index ecl_array_rank(cl_object x); extern ECL_API cl_object ecl_aref_unsafe(cl_object x, cl_index index); extern ECL_API cl_object ecl_aset_unsafe(cl_object x, cl_index index, cl_object value); extern ECL_API cl_object ecl_aref(cl_object x, cl_index index);