Use a TC7 tag instead of a SMOB for bytevectors.
[bpt/guile.git] / libguile / bytevectors.h
CommitLineData
1ee2c72e
LC
1#ifndef SCM_BYTEVECTORS_H
2#define SCM_BYTEVECTORS_H
3
4/* Copyright (C) 2009 Free Software Foundation, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
53befeb7
NJ
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
1ee2c72e 10 *
53befeb7
NJ
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
1ee2c72e
LC
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
53befeb7
NJ
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * 02110-1301 USA
1ee2c72e
LC
20 */
21
22\f
23
24#include "libguile/__scm.h"
25
26
27/* R6RS bytevectors. */
28
29#define SCM_BYTEVECTOR_LENGTH(_bv) \
807e5a66
LC
30 ((size_t) SCM_CELL_WORD_1 (_bv))
31#define SCM_BYTEVECTOR_CONTENTS(_bv) \
1ee2c72e 32 (SCM_BYTEVECTOR_INLINE_P (_bv) \
807e5a66
LC
33 ? (signed char *) SCM_CELL_OBJECT_LOC ((_bv), 2) \
34 : (signed char *) SCM_CELL_WORD_2 (_bv))
1ee2c72e
LC
35
36
37SCM_API SCM scm_endianness_big;
38SCM_API SCM scm_endianness_little;
39
2d34e924 40SCM_API SCM scm_c_make_bytevector (size_t);
404bb5f8
LC
41SCM_API int scm_is_bytevector (SCM);
42SCM_API size_t scm_c_bytevector_length (SCM);
43SCM_API scm_t_uint8 scm_c_bytevector_ref (SCM, size_t);
44SCM_API void scm_c_bytevector_set_x (SCM, size_t, scm_t_uint8);
45
46SCM_API SCM scm_make_bytevector (SCM, SCM);
1ee2c72e
LC
47SCM_API SCM scm_native_endianness (void);
48SCM_API SCM scm_bytevector_p (SCM);
49SCM_API SCM scm_bytevector_length (SCM);
50SCM_API SCM scm_bytevector_eq_p (SCM, SCM);
51SCM_API SCM scm_bytevector_fill_x (SCM, SCM);
52SCM_API SCM scm_bytevector_copy_x (SCM, SCM, SCM, SCM, SCM);
53SCM_API SCM scm_bytevector_copy (SCM);
54
782a82ee
AW
55SCM_API SCM scm_uniform_array_to_bytevector (SCM);
56
1ee2c72e
LC
57SCM_API SCM scm_bytevector_to_u8_list (SCM);
58SCM_API SCM scm_u8_list_to_bytevector (SCM);
59SCM_API SCM scm_uint_list_to_bytevector (SCM, SCM, SCM);
60SCM_API SCM scm_bytevector_to_uint_list (SCM, SCM, SCM);
61SCM_API SCM scm_sint_list_to_bytevector (SCM, SCM, SCM);
62SCM_API SCM scm_bytevector_to_sint_list (SCM, SCM, SCM);
63
64SCM_API SCM scm_bytevector_u16_native_ref (SCM, SCM);
65SCM_API SCM scm_bytevector_s16_native_ref (SCM, SCM);
66SCM_API SCM scm_bytevector_u32_native_ref (SCM, SCM);
67SCM_API SCM scm_bytevector_s32_native_ref (SCM, SCM);
68SCM_API SCM scm_bytevector_u64_native_ref (SCM, SCM);
69SCM_API SCM scm_bytevector_s64_native_ref (SCM, SCM);
70SCM_API SCM scm_bytevector_u8_ref (SCM, SCM);
71SCM_API SCM scm_bytevector_s8_ref (SCM, SCM);
72SCM_API SCM scm_bytevector_uint_ref (SCM, SCM, SCM, SCM);
73SCM_API SCM scm_bytevector_sint_ref (SCM, SCM, SCM, SCM);
74SCM_API SCM scm_bytevector_u16_ref (SCM, SCM, SCM);
75SCM_API SCM scm_bytevector_s16_ref (SCM, SCM, SCM);
76SCM_API SCM scm_bytevector_u32_ref (SCM, SCM, SCM);
77SCM_API SCM scm_bytevector_s32_ref (SCM, SCM, SCM);
78SCM_API SCM scm_bytevector_u64_ref (SCM, SCM, SCM);
79SCM_API SCM scm_bytevector_s64_ref (SCM, SCM, SCM);
80SCM_API SCM scm_bytevector_u16_native_set_x (SCM, SCM, SCM);
81SCM_API SCM scm_bytevector_s16_native_set_x (SCM, SCM, SCM);
82SCM_API SCM scm_bytevector_u32_native_set_x (SCM, SCM, SCM);
83SCM_API SCM scm_bytevector_s32_native_set_x (SCM, SCM, SCM);
84SCM_API SCM scm_bytevector_u64_native_set_x (SCM, SCM, SCM);
85SCM_API SCM scm_bytevector_s64_native_set_x (SCM, SCM, SCM);
86SCM_API SCM scm_bytevector_u8_set_x (SCM, SCM, SCM);
87SCM_API SCM scm_bytevector_s8_set_x (SCM, SCM, SCM);
88SCM_API SCM scm_bytevector_uint_set_x (SCM, SCM, SCM, SCM, SCM);
89SCM_API SCM scm_bytevector_sint_set_x (SCM, SCM, SCM, SCM, SCM);
90SCM_API SCM scm_bytevector_u16_set_x (SCM, SCM, SCM, SCM);
91SCM_API SCM scm_bytevector_s16_set_x (SCM, SCM, SCM, SCM);
92SCM_API SCM scm_bytevector_u32_set_x (SCM, SCM, SCM, SCM);
93SCM_API SCM scm_bytevector_s32_set_x (SCM, SCM, SCM, SCM);
94SCM_API SCM scm_bytevector_u64_set_x (SCM, SCM, SCM, SCM);
95SCM_API SCM scm_bytevector_s64_set_x (SCM, SCM, SCM, SCM);
96SCM_API SCM scm_bytevector_ieee_single_ref (SCM, SCM, SCM);
97SCM_API SCM scm_bytevector_ieee_single_native_ref (SCM, SCM);
98SCM_API SCM scm_bytevector_ieee_single_set_x (SCM, SCM, SCM, SCM);
99SCM_API SCM scm_bytevector_ieee_single_native_set_x (SCM, SCM, SCM);
100SCM_API SCM scm_bytevector_ieee_double_ref (SCM, SCM, SCM);
101SCM_API SCM scm_bytevector_ieee_double_native_ref (SCM, SCM);
102SCM_API SCM scm_bytevector_ieee_double_set_x (SCM, SCM, SCM, SCM);
103SCM_API SCM scm_bytevector_ieee_double_native_set_x (SCM, SCM, SCM);
104SCM_API SCM scm_string_to_utf8 (SCM);
105SCM_API SCM scm_string_to_utf16 (SCM, SCM);
106SCM_API SCM scm_string_to_utf32 (SCM, SCM);
107SCM_API SCM scm_utf8_to_string (SCM);
108SCM_API SCM scm_utf16_to_string (SCM, SCM);
109SCM_API SCM scm_utf32_to_string (SCM, SCM);
110
111
112\f
113/* Internal API. */
114
807e5a66
LC
115#define SCM_BYTEVECTOR_P(x) \
116 (!SCM_IMP (x) && SCM_TYP7(x) == scm_tc7_bytevector)
117#define SCM_BYTEVECTOR_FLAGS(_bv) \
118 (SCM_CELL_TYPE (_bv) >> 7UL)
119#define SCM_SET_BYTEVECTOR_FLAGS(_bv, _f) \
120 SCM_SET_CELL_TYPE ((_bv), scm_tc7_bytevector | ((_f) << 7UL))
121
f332089e
AW
122#define SCM_F_BYTEVECTOR_INLINE 0x1
123#define SCM_BYTEVECTOR_INLINE_P(_bv) \
807e5a66 124 (SCM_BYTEVECTOR_FLAGS (_bv) & SCM_F_BYTEVECTOR_INLINE)
e286c973 125#define SCM_BYTEVECTOR_ELEMENT_TYPE(_bv) \
807e5a66 126 (SCM_BYTEVECTOR_FLAGS (_bv) >> 1UL)
1ee2c72e
LC
127
128/* Hint that is passed to `scm_gc_malloc ()' and friends. */
129#define SCM_GC_BYTEVECTOR "bytevector"
130
e286c973
AW
131SCM_INTERNAL SCM scm_i_make_typed_bytevector (size_t, scm_t_array_element_type);
132SCM_INTERNAL SCM scm_c_take_typed_bytevector (signed char *, size_t,
133 scm_t_array_element_type);
134
cfb4702f
LC
135SCM_INTERNAL void scm_bootstrap_bytevectors (void);
136SCM_INTERNAL void scm_init_bytevectors (void);
1ee2c72e 137
caa92f5e 138SCM_INTERNAL SCM scm_i_native_endianness;
2d34e924 139SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
1ee2c72e 140
807e5a66
LC
141SCM_INTERNAL int scm_i_print_bytevector (SCM, SCM, scm_print_state *);
142
143
1ee2c72e
LC
144#define scm_c_shrink_bytevector(_bv, _len) \
145 (SCM_BYTEVECTOR_INLINE_P (_bv) \
146 ? (_bv) \
147 : scm_i_shrink_bytevector ((_bv), (_len)))
148
2d34e924 149SCM_INTERNAL SCM scm_i_shrink_bytevector (SCM, size_t);
438974d0 150SCM_INTERNAL void scm_i_bytevector_generalized_set_x (SCM, size_t, SCM);
1ee2c72e
LC
151SCM_INTERNAL SCM scm_null_bytevector;
152
153#endif /* SCM_BYTEVECTORS_H */