diff --git a/src/CHANGELOG b/src/CHANGELOG index a2116da51..dd4b8d1c2 100755 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -1,6 +1,12 @@ ECL 9.10.3: =========== +* Visible changes: + + - New function EXT:ARRAY-RAW-DATA returns a non-adjustable vector of type + (UNSIGNED-BYTE 8) with the content of an array. The returned array overlaps + with the original, so any change on one will affect the other. + * Bugs fixed: - In single-threaded builds, ECL did not properly restore the signal mask diff --git a/src/c/array.d b/src/c/array.d index ef15f0f35..0f43e6201 100644 --- a/src/c/array.d +++ b/src/c/array.d @@ -759,6 +759,38 @@ because the total size of the to-array is too small.", 0); from->array.self.t = address_inc(base, j, fromtype); } +cl_object +si_array_raw_data(cl_object x) +{ + cl_elttype et = ecl_array_elttype(x); + cl_index total_size = x->vector.dim * ecl_aet_size[et]; + cl_object output, to_array; + uint8_t *data; + if (et == aet_object) { + FEerror("EXT:ARRAY-RAW-DATA can not get data " + "from an array with element type T.", 0); + } + data = x->vector.self.b8; + to_array = x->array.displaced; + if (to_array == Cnil || ((to_array = ECL_CONS_CAR(to_array)) == Cnil)) { + output = ecl_alloc_object(t_vector); + output->vector.elttype = aet_b8; + output->vector.self.b8 = data; + output->vector.dim = output->vector.fillp = total_size; + output->vector.flags = 0; /* no fill pointer, not adjustable */ + output->vector.displaced = Cnil; + } else { + cl_index displ = data - to_array->vector.self.b8; + output = si_make_vector(@'ext::byte8', + MAKE_FIXNUM(total_size), + Cnil, + Cnil, + si_array_raw_data(to_array), + MAKE_FIXNUM(displ)); + } + @(return output) +} + cl_elttype ecl_array_elttype(cl_object x) { diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h index 1e72d240d..e34ec5946 100644 --- a/src/c/symbols_list.h +++ b/src/c/symbols_list.h @@ -1837,5 +1837,7 @@ cl_symbols[] = { {SYS_ "*QUIT-TAG*", SI_SPECIAL, NULL, -1, OBJNULL}, +{EXT_ "ARRAY-RAW-DATA", EXT_ORDINARY, si_array_raw_data, 1, OBJNULL}, + /* Tag for end of list */ {NULL, CL_ORDINARY, NULL, -1, OBJNULL}}; diff --git a/src/c/symbols_list2.h b/src/c/symbols_list2.h index 35b60f513..cd49d3762 100644 --- a/src/c/symbols_list2.h +++ b/src/c/symbols_list2.h @@ -1837,5 +1837,7 @@ cl_symbols[] = { {SYS_ "*QUIT-TAG*",NULL}, +{EXT_ "ARRAY-RAW-DATA","si_array_raw_data"}, + /* Tag for end of list */ {NULL,NULL}}; diff --git a/src/h/external.h b/src/h/external.h index ed6dc2688..4669bb12b 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -318,6 +318,7 @@ extern ECL_API cl_object cl_array_dimension(cl_object a, cl_object index); extern ECL_API cl_object cl_array_total_size(cl_object a); extern ECL_API cl_object cl_adjustable_array_p(cl_object a); extern ECL_API cl_object cl_array_displacement(cl_object a); +extern ECL_API cl_object si_array_raw_data(cl_object array); extern ECL_API cl_object cl_svref(cl_object x, cl_object index); extern ECL_API cl_object si_svset(cl_object x, cl_object index, cl_object v); extern ECL_API cl_object cl_array_has_fill_pointer_p(cl_object a);