Add `.gitignore'.
[guile-r6rs-libs.git] / src / bytevector.h
bloba3e0f2c6e88f63e5ade06510108dff7310b60d63
1 /* Guile-R6RS-Libs --- Implementation of R6RS standard libraries.
2 Copyright (C) 2007 Ludovic Courtès <ludovic.courtes@laas.fr>
4 Guile-R6RS-Libs is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 Guile-R6RS-Libs is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with Guile-R6RS-Libs; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18 #ifndef GUILE_R6RS_BYTEVECTOR
19 #define GUILE_R6RS_BYTEVECTOR
21 /* R6RS bytevectors. */
23 #include <libguile.h>
25 SCM_API void scm_init_r6rs_bytevector (void);
27 #define SCM_VALIDATE_R6RS_BYTEVECTOR(_pos, _obj) \
28 SCM_VALIDATE_SMOB ((_pos), (_obj), r6rs_bytevector);
30 #define SCM_R6RS_BYTEVECTOR_LENGTH(_bv) \
31 ((unsigned) SCM_SMOB_DATA (_bv))
32 #define SCM_R6RS_BYTEVECTOR_CONTENTS(_bv) \
33 (SCM_R6RS_BYTEVECTOR_INLINE_P (_bv) \
34 ? (signed char *) SCM_SMOB_OBJECT_2_LOC (_bv) \
35 : (signed char *) SCM_SMOB_DATA_2 (_bv))
37 SCM_API SCM scm_r6rs_make_bytevector (SCM, SCM);
38 SCM_API SCM scm_r6rs_c_make_bytevector (unsigned);
39 SCM_API SCM scm_r6rs_native_endianness (void);
40 SCM_API SCM scm_r6rs_bytevector_p (SCM);
41 SCM_API SCM scm_r6rs_bytevector_length (SCM);
42 SCM_API SCM scm_r6rs_bytevector_eq_p (SCM, SCM);
43 SCM_API SCM scm_r6rs_bytevector_fill_x (SCM, SCM);
44 SCM_API SCM scm_r6rs_bytevector_copy_x (SCM, SCM, SCM, SCM, SCM);
45 SCM_API SCM scm_r6rs_bytevector_copy (SCM);
47 SCM_API SCM scm_r6rs_bytevector_to_u8_list (SCM);
48 SCM_API SCM scm_r6rs_u8_list_to_bytevector (SCM);
49 SCM_API SCM scm_r6rs_uint_list_to_bytevector (SCM, SCM, SCM);
50 SCM_API SCM scm_r6rs_bytevector_to_uint_list (SCM, SCM, SCM);
51 SCM_API SCM scm_r6rs_sint_list_to_bytevector (SCM, SCM, SCM);
52 SCM_API SCM scm_r6rs_bytevector_to_sint_list (SCM, SCM, SCM);
54 SCM_API SCM scm_r6rs_bytevector_u16_native_ref (SCM, SCM);
55 SCM_API SCM scm_r6rs_bytevector_s16_native_ref (SCM, SCM);
56 SCM_API SCM scm_r6rs_bytevector_u32_native_ref (SCM, SCM);
57 SCM_API SCM scm_r6rs_bytevector_s32_native_ref (SCM, SCM);
58 SCM_API SCM scm_r6rs_bytevector_u64_native_ref (SCM, SCM);
59 SCM_API SCM scm_r6rs_bytevector_s64_native_ref (SCM, SCM);
60 SCM_API SCM scm_r6rs_bytevector_u8_ref (SCM, SCM);
61 SCM_API SCM scm_r6rs_bytevector_s8_ref (SCM, SCM);
62 SCM_API SCM scm_r6rs_bytevector_uint_ref (SCM, SCM, SCM, SCM);
63 SCM_API SCM scm_r6rs_bytevector_sint_ref (SCM, SCM, SCM, SCM);
64 SCM_API SCM scm_r6rs_bytevector_u16_ref (SCM, SCM, SCM);
65 SCM_API SCM scm_r6rs_bytevector_s16_ref (SCM, SCM, SCM);
66 SCM_API SCM scm_r6rs_bytevector_u32_ref (SCM, SCM, SCM);
67 SCM_API SCM scm_r6rs_bytevector_s32_ref (SCM, SCM, SCM);
68 SCM_API SCM scm_r6rs_bytevector_u64_ref (SCM, SCM, SCM);
69 SCM_API SCM scm_r6rs_bytevector_s64_ref (SCM, SCM, SCM);
70 SCM_API SCM scm_r6rs_bytevector_u16_native_set_x (SCM, SCM, SCM);
71 SCM_API SCM scm_r6rs_bytevector_s16_native_set_x (SCM, SCM, SCM);
72 SCM_API SCM scm_r6rs_bytevector_u32_native_set_x (SCM, SCM, SCM);
73 SCM_API SCM scm_r6rs_bytevector_s32_native_set_x (SCM, SCM, SCM);
74 SCM_API SCM scm_r6rs_bytevector_u64_native_set_x (SCM, SCM, SCM);
75 SCM_API SCM scm_r6rs_bytevector_s64_native_set_x (SCM, SCM, SCM);
76 SCM_API SCM scm_r6rs_bytevector_u8_set_x (SCM, SCM, SCM);
77 SCM_API SCM scm_r6rs_bytevector_s8_set_x (SCM, SCM, SCM);
78 SCM_API SCM scm_r6rs_bytevector_uint_set_x (SCM, SCM, SCM, SCM, SCM);
79 SCM_API SCM scm_r6rs_bytevector_sint_set_x (SCM, SCM, SCM, SCM, SCM);
80 SCM_API SCM scm_r6rs_bytevector_u16_set_x (SCM, SCM, SCM, SCM);
81 SCM_API SCM scm_r6rs_bytevector_s16_set_x (SCM, SCM, SCM, SCM);
82 SCM_API SCM scm_r6rs_bytevector_u32_set_x (SCM, SCM, SCM, SCM);
83 SCM_API SCM scm_r6rs_bytevector_s32_set_x (SCM, SCM, SCM, SCM);
84 SCM_API SCM scm_r6rs_bytevector_u64_set_x (SCM, SCM, SCM, SCM);
85 SCM_API SCM scm_r6rs_bytevector_s64_set_x (SCM, SCM, SCM, SCM);
86 SCM_API SCM scm_r6rs_bytevector_ieee_single_ref (SCM, SCM, SCM);
87 SCM_API SCM scm_r6rs_bytevector_ieee_single_native_ref (SCM, SCM);
88 SCM_API SCM scm_r6rs_bytevector_ieee_single_set_x (SCM, SCM, SCM, SCM);
89 SCM_API SCM scm_r6rs_bytevector_ieee_single_native_set_x (SCM, SCM, SCM);
90 SCM_API SCM scm_r6rs_bytevector_ieee_double_ref (SCM, SCM, SCM);
91 SCM_API SCM scm_r6rs_bytevector_ieee_double_native_ref (SCM, SCM);
92 SCM_API SCM scm_r6rs_bytevector_ieee_double_set_x (SCM, SCM, SCM, SCM);
93 SCM_API SCM scm_r6rs_bytevector_ieee_double_native_set_x (SCM, SCM, SCM);
96 /* Internal API. */
98 /* The threshold (in octets) under which bytevectors are stored "in-line",
99 i.e., without allocating memory beside the SMOB itself (a double cell).
100 This optimization is necessary since small bytevectors are expected to be
101 common. */
102 #define SCM_R6RS_BYTEVECTOR_INLINE_THRESHOLD (2 * sizeof (SCM))
103 #define SCM_R6RS_BYTEVECTOR_INLINEABLE_SIZE_P(_size) \
104 ((_size) <= SCM_R6RS_BYTEVECTOR_INLINE_THRESHOLD)
105 #define SCM_R6RS_BYTEVECTOR_INLINE_P(_bv) \
106 (SCM_R6RS_BYTEVECTOR_INLINEABLE_SIZE_P (SCM_R6RS_BYTEVECTOR_LENGTH (_bv)))
108 /* Hint that is passed to `scm_gc_malloc ()' and friends. */
109 #define SCM_GC_BYTEVECTOR "r6rs-bytevector"
111 SCM_API scm_t_bits scm_tc16_r6rs_bytevector;
112 SCM_API SCM scm_r6rs_c_take_bytevector (signed char *, unsigned);
114 #define scm_r6rs_c_shrink_bytevector(_bv, _len) \
115 (SCM_R6RS_BYTEVECTOR_INLINE_P (_bv) \
116 ? (_bv) \
117 : scm_r6rs_i_shrink_bytevector ((_bv), (_len)))
119 SCM_API SCM scm_r6rs_i_shrink_bytevector (SCM, unsigned);
120 SCM_API SCM scm_r6rs_null_bytevector;
122 #endif
124 /* arch-tag: b727a1e1-ed81-4c92-8152-538928090c84