mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-06 20:20:20 +02:00
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.
125 lines
3.3 KiB
C
125 lines
3.3 KiB
C
#ifndef SCM_BYTEVECTORS_INTERNAL_H
|
||
#define SCM_BYTEVECTORS_INTERNAL_H
|
||
|
||
/* Copyright 2009, 2011, 2018, 2023, 2025
|
||
Free Software Foundation, Inc.
|
||
|
||
This file is part of Guile.
|
||
|
||
Guile is free software: you can redistribute it and/or modify it
|
||
under the terms of the GNU Lesser General Public License as published
|
||
by the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
Guile is distributed in the hope that it will be useful, but WITHOUT
|
||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||
License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public
|
||
License along with Guile. If not, see
|
||
<https://www.gnu.org/licenses/>. */
|
||
|
||
|
||
|
||
#include <libguile/bytevectors.h>
|
||
#include <libguile/error.h>
|
||
#include <libguile/uniform.h>
|
||
|
||
struct scm_bytevector
|
||
{
|
||
scm_t_bits tag_flags_and_element_type;
|
||
size_t length;
|
||
signed char *contents;
|
||
SCM parent;
|
||
signed char inline_contents[];
|
||
};
|
||
|
||
static inline struct scm_bytevector *
|
||
scm_to_bytevector (SCM x)
|
||
{
|
||
if (!SCM_BYTEVECTOR_P (x))
|
||
abort ();
|
||
return (struct scm_bytevector *) SCM_UNPACK_POINTER (x);
|
||
}
|
||
|
||
static inline SCM
|
||
scm_from_bytevector (struct scm_bytevector *bv)
|
||
{
|
||
return SCM_PACK_POINTER (bv);
|
||
}
|
||
|
||
enum scm_bytevector_flags
|
||
{
|
||
SCM_F_BYTEVECTOR_IMMUTABLE = 0x80UL,
|
||
SCM_F_BYTEVECTOR_CONTIGUOUS = 0x100UL
|
||
};
|
||
|
||
static inline signed char*
|
||
scm_bytevector_contents (struct scm_bytevector *bv)
|
||
{
|
||
return bv->contents;
|
||
}
|
||
|
||
static inline SCM
|
||
scm_bytevector_parent (struct scm_bytevector *bv)
|
||
{
|
||
return bv->parent;
|
||
}
|
||
|
||
static inline int
|
||
scm_is_mutable_bytevector (SCM x)
|
||
{
|
||
scm_t_bits tag = SCM_CELL_TYPE (x);
|
||
return (tag & (0x7f | SCM_F_BYTEVECTOR_IMMUTABLE)) == scm_tc7_bytevector;
|
||
}
|
||
|
||
static inline scm_t_array_element_type
|
||
scm_bytevector_element_type (struct scm_bytevector *bv)
|
||
{
|
||
return bv->tag_flags_and_element_type >> 16;
|
||
}
|
||
|
||
static inline int
|
||
scm_bytevector_is_contiguous (struct scm_bytevector *bv)
|
||
{
|
||
return bv->tag_flags_and_element_type & SCM_F_BYTEVECTOR_CONTIGUOUS;
|
||
}
|
||
|
||
static inline int
|
||
scm_bytevector_is_immutable (struct scm_bytevector *bv)
|
||
{
|
||
return bv->tag_flags_and_element_type & SCM_F_BYTEVECTOR_IMMUTABLE;
|
||
}
|
||
|
||
static inline size_t
|
||
scm_bytevector_type_size (struct scm_bytevector *bv)
|
||
{
|
||
return scm_i_array_element_type_sizes[scm_bytevector_element_type (bv)]/8;
|
||
}
|
||
|
||
static inline size_t
|
||
scm_bytevector_typed_length (struct scm_bytevector *bv)
|
||
{
|
||
return bv->length / scm_bytevector_type_size (bv);
|
||
}
|
||
|
||
SCM_INTERNAL struct scm_bytevector*
|
||
scm_i_make_typed_bytevector (size_t, scm_t_array_element_type);
|
||
SCM_INTERNAL SCM scm_c_take_typed_bytevector (signed char *, size_t,
|
||
scm_t_array_element_type, SCM);
|
||
|
||
SCM_INTERNAL void scm_bootstrap_bytevectors (void);
|
||
SCM_INTERNAL void scm_init_bytevectors (void);
|
||
|
||
SCM_INTERNAL SCM scm_i_native_endianness;
|
||
SCM_INTERNAL SCM scm_c_take_gc_bytevector (signed char *, size_t, SCM);
|
||
|
||
SCM_INTERNAL int scm_i_print_bytevector (SCM, SCM, scm_print_state *);
|
||
|
||
SCM_INTERNAL struct scm_bytevector*
|
||
scm_c_shrink_bytevector (struct scm_bytevector*, size_t);
|
||
SCM_INTERNAL void scm_i_bytevector_generalized_set_x (SCM, size_t, SCM);
|
||
SCM_INTERNAL SCM scm_null_bytevector;
|
||
|
||
#endif /* SCM_BYTEVECTORS_INTERNAL_H */
|