1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

* srfi-4.c (take_uvec): New.

(alloc_uvec): Use it.
* srfi-4.h, srfi-4.i.c (scm_take_u8vector, etc): New.
This commit is contained in:
Marius Vollmer 2004-10-27 19:25:14 +00:00
parent 2a7bd73833
commit faa0036593
3 changed files with 30 additions and 3 deletions

View file

@ -217,13 +217,19 @@ uvec_assert (int type, SCM obj)
scm_wrong_type_arg_msg (NULL, 0, obj, uvec_names[type]); scm_wrong_type_arg_msg (NULL, 0, obj, uvec_names[type]);
} }
static SCM
take_uvec (int type, const void *base, size_t len)
{
SCM_RETURN_NEWSMOB3 (scm_tc16_uvec, type, len, (scm_t_bits) base);
}
/* Create a new, uninitialized homogeneous numeric vector of type TYPE /* Create a new, uninitialized homogeneous numeric vector of type TYPE
with space for LEN elements. */ with space for LEN elements. */
static SCM static SCM
alloc_uvec (int type, size_t c_len) alloc_uvec (int type, size_t len)
{ {
void *base = scm_gc_malloc (c_len * uvec_sizes[type], uvec_names[type]); void *base = scm_gc_malloc (len * uvec_sizes[type], uvec_names[type]);
SCM_RETURN_NEWSMOB3 (scm_tc16_uvec, type, c_len, (scm_t_bits) base); return take_uvec (type, base, len);
} }
/* GCC doesn't seem to want to optimize unused switch clauses away, /* GCC doesn't seem to want to optimize unused switch clauses away,
@ -573,6 +579,9 @@ scm_uniform_vector_release (SCM uvec)
/* Nothing to do right now, but this function might come in handy /* Nothing to do right now, but this function might come in handy
when uniform vectors need to be locked when giving away a pointer when uniform vectors need to be locked when giving away a pointer
to their elements. to their elements.
Also, a call to scm_uniform_vector acts like
scm_remember_upto_here, which is needed in any case.
*/ */
} }

View file

@ -44,6 +44,7 @@ SCM_API void scm_uniform_vector_release (SCM uvec);
SCM_API SCM scm_u8vector_p (SCM obj); SCM_API SCM scm_u8vector_p (SCM obj);
SCM_API SCM scm_make_u8vector (SCM n, SCM fill); SCM_API SCM scm_make_u8vector (SCM n, SCM fill);
SCM_API SCM scm_take_u8vector (const scm_t_uint8 *data, size_t n);
SCM_API SCM scm_u8vector (SCM l); SCM_API SCM scm_u8vector (SCM l);
SCM_API SCM scm_u8vector_length (SCM uvec); SCM_API SCM scm_u8vector_length (SCM uvec);
SCM_API SCM scm_u8vector_ref (SCM uvec, SCM index); SCM_API SCM scm_u8vector_ref (SCM uvec, SCM index);
@ -54,6 +55,7 @@ SCM_API scm_t_uint8 *scm_u8vector_elements (SCM uvec);
SCM_API SCM scm_s8vector_p (SCM obj); SCM_API SCM scm_s8vector_p (SCM obj);
SCM_API SCM scm_make_s8vector (SCM n, SCM fill); SCM_API SCM scm_make_s8vector (SCM n, SCM fill);
SCM_API SCM scm_take_s8vector (const scm_t_int8 *data, size_t n);
SCM_API SCM scm_s8vector (SCM l); SCM_API SCM scm_s8vector (SCM l);
SCM_API SCM scm_s8vector_length (SCM uvec); SCM_API SCM scm_s8vector_length (SCM uvec);
SCM_API SCM scm_s8vector_ref (SCM uvec, SCM index); SCM_API SCM scm_s8vector_ref (SCM uvec, SCM index);
@ -64,6 +66,7 @@ SCM_API scm_t_int8 *scm_s8vector_elements (SCM uvec);
SCM_API SCM scm_u16vector_p (SCM obj); SCM_API SCM scm_u16vector_p (SCM obj);
SCM_API SCM scm_make_u16vector (SCM n, SCM fill); SCM_API SCM scm_make_u16vector (SCM n, SCM fill);
SCM_API SCM scm_take_u16vector (const scm_t_uint16 *data, size_t n);
SCM_API SCM scm_u16vector (SCM l); SCM_API SCM scm_u16vector (SCM l);
SCM_API SCM scm_u16vector_length (SCM uvec); SCM_API SCM scm_u16vector_length (SCM uvec);
SCM_API SCM scm_u16vector_ref (SCM uvec, SCM index); SCM_API SCM scm_u16vector_ref (SCM uvec, SCM index);
@ -74,6 +77,7 @@ SCM_API scm_t_uint16 *scm_u16vector_elements (SCM uvec);
SCM_API SCM scm_s16vector_p (SCM obj); SCM_API SCM scm_s16vector_p (SCM obj);
SCM_API SCM scm_make_s16vector (SCM n, SCM fill); SCM_API SCM scm_make_s16vector (SCM n, SCM fill);
SCM_API SCM scm_take_s16vector (const scm_t_int16 *data, size_t n);
SCM_API SCM scm_s16vector (SCM l); SCM_API SCM scm_s16vector (SCM l);
SCM_API SCM scm_s16vector_length (SCM uvec); SCM_API SCM scm_s16vector_length (SCM uvec);
SCM_API SCM scm_s16vector_ref (SCM uvec, SCM index); SCM_API SCM scm_s16vector_ref (SCM uvec, SCM index);
@ -84,6 +88,7 @@ SCM_API scm_t_int16 *scm_s16vector_elements (SCM uvec);
SCM_API SCM scm_u32vector_p (SCM obj); SCM_API SCM scm_u32vector_p (SCM obj);
SCM_API SCM scm_make_u32vector (SCM n, SCM fill); SCM_API SCM scm_make_u32vector (SCM n, SCM fill);
SCM_API SCM scm_take_u32vector (const scm_t_uint32 *data, size_t n);
SCM_API SCM scm_u32vector (SCM l); SCM_API SCM scm_u32vector (SCM l);
SCM_API SCM scm_u32vector_length (SCM uvec); SCM_API SCM scm_u32vector_length (SCM uvec);
SCM_API SCM scm_u32vector_ref (SCM uvec, SCM index); SCM_API SCM scm_u32vector_ref (SCM uvec, SCM index);
@ -94,6 +99,7 @@ SCM_API scm_t_uint32 *scm_u32vector_elements (SCM uvec);
SCM_API SCM scm_s32vector_p (SCM obj); SCM_API SCM scm_s32vector_p (SCM obj);
SCM_API SCM scm_make_s32vector (SCM n, SCM fill); SCM_API SCM scm_make_s32vector (SCM n, SCM fill);
SCM_API SCM scm_take_s32vector (const scm_t_int32 *data, size_t n);
SCM_API SCM scm_s32vector (SCM l); SCM_API SCM scm_s32vector (SCM l);
SCM_API SCM scm_s32vector_length (SCM uvec); SCM_API SCM scm_s32vector_length (SCM uvec);
SCM_API SCM scm_s32vector_ref (SCM uvec, SCM index); SCM_API SCM scm_s32vector_ref (SCM uvec, SCM index);
@ -104,6 +110,7 @@ SCM_API scm_t_int32 *scm_s32vector_elements (SCM uvec);
SCM_API SCM scm_u64vector_p (SCM obj); SCM_API SCM scm_u64vector_p (SCM obj);
SCM_API SCM scm_make_u64vector (SCM n, SCM fill); SCM_API SCM scm_make_u64vector (SCM n, SCM fill);
SCM_API SCM scm_take_u64vector (const scm_t_uint64 *data, size_t n);
SCM_API SCM scm_u64vector (SCM l); SCM_API SCM scm_u64vector (SCM l);
SCM_API SCM scm_u64vector_length (SCM uvec); SCM_API SCM scm_u64vector_length (SCM uvec);
SCM_API SCM scm_u64vector_ref (SCM uvec, SCM index); SCM_API SCM scm_u64vector_ref (SCM uvec, SCM index);
@ -114,6 +121,7 @@ SCM_API scm_t_uint64 *scm_u64vector_elements (SCM uvec);
SCM_API SCM scm_s64vector_p (SCM obj); SCM_API SCM scm_s64vector_p (SCM obj);
SCM_API SCM scm_make_s64vector (SCM n, SCM fill); SCM_API SCM scm_make_s64vector (SCM n, SCM fill);
SCM_API SCM scm_take_s64vector (const scm_t_int64 *data, size_t n);
SCM_API SCM scm_s64vector (SCM l); SCM_API SCM scm_s64vector (SCM l);
SCM_API SCM scm_s64vector_length (SCM uvec); SCM_API SCM scm_s64vector_length (SCM uvec);
SCM_API SCM scm_s64vector_ref (SCM uvec, SCM index); SCM_API SCM scm_s64vector_ref (SCM uvec, SCM index);
@ -124,6 +132,7 @@ SCM_API scm_t_int64 *scm_s64vector_elements (SCM uvec);
SCM_API SCM scm_f32vector_p (SCM obj); SCM_API SCM scm_f32vector_p (SCM obj);
SCM_API SCM scm_make_f32vector (SCM n, SCM fill); SCM_API SCM scm_make_f32vector (SCM n, SCM fill);
SCM_API SCM scm_take_f32vector (const float *data, size_t n);
SCM_API SCM scm_f32vector (SCM l); SCM_API SCM scm_f32vector (SCM l);
SCM_API SCM scm_f32vector_length (SCM uvec); SCM_API SCM scm_f32vector_length (SCM uvec);
SCM_API SCM scm_f32vector_ref (SCM uvec, SCM index); SCM_API SCM scm_f32vector_ref (SCM uvec, SCM index);
@ -134,6 +143,7 @@ SCM_API float *scm_f32vector_elements (SCM uvec);
SCM_API SCM scm_f64vector_p (SCM obj); SCM_API SCM scm_f64vector_p (SCM obj);
SCM_API SCM scm_make_f64vector (SCM n, SCM fill); SCM_API SCM scm_make_f64vector (SCM n, SCM fill);
SCM_API SCM scm_take_f64vector (const double *data, size_t n);
SCM_API SCM scm_f64vector (SCM l); SCM_API SCM scm_f64vector (SCM l);
SCM_API SCM scm_f64vector_length (SCM uvec); SCM_API SCM scm_f64vector_length (SCM uvec);
SCM_API SCM scm_f64vector_ref (SCM uvec, SCM index); SCM_API SCM scm_f64vector_ref (SCM uvec, SCM index);

View file

@ -53,6 +53,14 @@ SCM_DEFINE (F(scm_make_,TAG,vector), "make-"S(TAG)"vector", 1, 1, 0,
} }
#undef FUNC_NAME #undef FUNC_NAME
SCM
F(scm_take_,TAG,vector) (const CTYPE *data, size_t n)
{
scm_gc_register_collectable_memory ((void *)data, n*sizeof(CTYPE),
uvec_names[TYPE]);
return take_uvec (TYPE, data, n);
}
SCM_DEFINE (F(scm_,TAG,vector), S(TAG)"vector", 0, 0, 1, SCM_DEFINE (F(scm_,TAG,vector), S(TAG)"vector", 0, 0, 1,
(SCM l), (SCM l),
"Return a newly allocated homogeneous numeric vector containing\n" "Return a newly allocated homogeneous numeric vector containing\n"