#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 . */ #include #include #include 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 */