1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-07 20:50: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

@ -1,4 +1,4 @@
/* Copyright 1995-1998,2000-2006,2009,2011,2013-2014,2018
/* Copyright 1995-1998,2000-2006,2009,2011,2013-2014,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
@ -30,6 +30,7 @@
#include "boolean.h"
#include "bitvectors.h"
#include "bytevectors.h"
#include "bytevectors-internal.h"
#include "list.h"
#include "numbers.h"
#include "pairs.h"
@ -78,11 +79,10 @@ bytevector_c32_ref (SCM bv, size_t pos)
char *c_bv;
float real, imag;
if (!SCM_BYTEVECTOR_P (bv))
abort ();
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv);
struct scm_bytevector *bvp = scm_to_bytevector (bv);
c_bv = (char *) bvp->contents;
pos *= 2 * sizeof (float);
if (pos + 2 * sizeof (float) - 1 >= SCM_BYTEVECTOR_LENGTH (bv))
if (pos + 2 * sizeof (float) - 1 >= bvp->length)
abort ();
memcpy (&real, &c_bv[pos], sizeof (float));
@ -96,11 +96,10 @@ bytevector_c64_ref (SCM bv, size_t pos)
char *c_bv;
double real, imag;
if (!SCM_BYTEVECTOR_P (bv))
abort ();
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv);
struct scm_bytevector *bvp = scm_to_bytevector (bv);
c_bv = (char *) bvp->contents;
pos *= 2 * sizeof (double);
if (pos + 2 * sizeof (double) - 1 >= SCM_BYTEVECTOR_LENGTH (bv))
if (pos + 2 * sizeof (double) - 1 >= bvp->length)
abort ();
memcpy (&real, &c_bv[pos], sizeof (double));
@ -114,11 +113,10 @@ bytevector_c32_set (SCM bv, size_t pos, SCM val)
char *c_bv;
float real, imag;
if (!SCM_BYTEVECTOR_P (bv))
abort ();
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv);
struct scm_bytevector *bvp = scm_to_bytevector (bv);
c_bv = (char *) bvp->contents;
pos *= 2 * sizeof (float);
if (pos + 2 * sizeof (float) - 1 >= SCM_BYTEVECTOR_LENGTH (bv))
if (pos + 2 * sizeof (float) - 1 >= bvp->length)
abort ();
real = scm_c_real_part (val);
@ -133,11 +131,10 @@ bytevector_c64_set (SCM bv, size_t pos, SCM val)
char *c_bv;
double real, imag;
if (!SCM_BYTEVECTOR_P (bv))
abort ();
c_bv = (char *) SCM_BYTEVECTOR_CONTENTS (bv);
struct scm_bytevector *bvp = scm_to_bytevector (bv);
c_bv = (char *) bvp->contents;
pos *= 2 * sizeof (double);
if (pos + 2 * sizeof (double) - 1 >= SCM_BYTEVECTOR_LENGTH (bv))
if (pos + 2 * sizeof (double) - 1 >= bvp->length)
abort ();
real = scm_c_real_part (val);
@ -222,8 +219,9 @@ scm_array_get_handle (SCM array, scm_t_array_handle *h)
scm_t_vector_ref vref;
scm_t_vector_set vset;
element_type = SCM_BYTEVECTOR_ELEMENT_TYPE (array);
length = SCM_BYTEVECTOR_TYPED_LENGTH (array);
struct scm_bytevector *bv = scm_to_bytevector (array);
element_type = scm_bytevector_element_type (bv);
length = scm_bytevector_typed_length (bv);
switch (element_type)
{
@ -257,8 +255,8 @@ scm_array_get_handle (SCM array, scm_t_array_handle *h)
}
initialize_vector_handle (h, length, element_type, vref, vset,
SCM_BYTEVECTOR_CONTENTS (array),
SCM_MUTABLE_BYTEVECTOR_P (array));
bv->contents,
!scm_bytevector_is_immutable (bv));
}
break;
case scm_tc7_array: