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

Move private bytevectors API to a separate header

Also give bytevectors a private type (a struct).

* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Remove.
(SCM_BYTEVECTOR_LENGTH):
(SCM_BYTEVECTOR_CONTENTS): Proxy to the C accessors.
(SCM_BYTEVECTOR_PARENT): Remove from public API.
(SCM_BYTEVECTOR_P, SCM_VALIDATE_BYTEVECTOR): Make public.
(scm_c_bytevector_contents): New function.
* libguile/bytevectors-internal.h: New file.
* libguile/Makefile.am (noinst_HEADERS): Add new file.

* libguile/bytevectors.c:
* libguile/array-handle.c:
* libguile/arrays.c:
* libguile/foreign.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/loader.c:
* libguile/print.c:
* libguile/r6rs-ports.c:
* libguile/srfi-4.c:
* libguile/strings.c: Adapt to use bytevectors-internal.h as needed, and
sometimes to use the internal bytevector type.
This commit is contained in:
Andy Wingo 2025-06-02 09:08:35 +02:00
parent 51bc69dd1c
commit 0134abce74
14 changed files with 310 additions and 276 deletions

View file

@ -26,7 +26,7 @@
#include <string.h>
#include "boolean.h"
#include "bytevectors.h"
#include "bytevectors-internal.h"
#include "error.h"
#include "eval.h"
#include "extensions.h"
@ -119,7 +119,7 @@
#define DEFINE_SRFI_4_C_FUNCS(TAG, tag, ctype, width) \
SCM scm_take_##tag##vector (ctype *data, size_t n) \
{ \
return scm_c_take_typed_bytevector ((int8_t*)data, n, ETYPE (TAG), \
return scm_c_take_typed_bytevector ((int8_t*)data, n, ETYPE (TAG), \
SCM_BOOL_F); \
} \
const ctype* scm_array_handle_##tag##_elements (scm_t_array_handle *h) \
@ -248,17 +248,12 @@ SCM_DEFINE (scm_make_srfi_4_vector, "make-srfi-4-vector", 2, 1, 0,
case SCM_ARRAY_ELEMENT_TYPE_C32:
case SCM_ARRAY_ELEMENT_TYPE_C64:
{
SCM ret;
c_len = scm_to_size_t (len);
ret = scm_i_make_typed_bytevector (c_len, c_type);
SCM ret = scm_from_bytevector
(scm_i_make_typed_bytevector (c_len, c_type));
if (SCM_UNBNDP (fill) || scm_is_eq (len, SCM_INUM0))
; /* pass */
else if (scm_is_true (scm_zero_p (fill)))
memset (SCM_BYTEVECTOR_CONTENTS (ret), 0,
SCM_BYTEVECTOR_LENGTH (ret));
else
/* FIXME: Shouldn't be able to fill a u16 vector with 0.0. */
if (!SCM_UNBNDP (fill) && scm_is_false (scm_zero_p (fill)))
{
scm_t_array_handle h;
size_t i;
@ -283,7 +278,7 @@ SCM_DEFINE (scm_srfi_4_vector_type_size, "srfi-4-vector-type-size", 1, 0, 0,
#define FUNC_NAME s_scm_srfi_4_vector_type_size
{
SCM_VALIDATE_BYTEVECTOR (1, vec);
return scm_from_size_t (SCM_BYTEVECTOR_TYPE_SIZE (vec));
return scm_from_size_t (scm_bytevector_type_size (scm_to_bytevector (vec)));
}
#undef FUNC_NAME