Import R6RS bytevectors and I/O ports from Guile-R6RS-Libs 0.2.
[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
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21\f
22
23#include "libguile/__scm.h"
24
25
26/* R6RS bytevectors. */
27
28#define SCM_BYTEVECTOR_LENGTH(_bv) \
29 ((unsigned) SCM_SMOB_DATA (_bv))
30#define SCM_BYTEVECTOR_CONTENTS(_bv) \
31 (SCM_BYTEVECTOR_INLINE_P (_bv) \
32 ? (signed char *) SCM_SMOB_OBJECT_2_LOC (_bv) \
33 : (signed char *) SCM_SMOB_DATA_2 (_bv))
34
35
36SCM_API SCM scm_endianness_big;
37SCM_API SCM scm_endianness_little;
38
39SCM_API SCM scm_make_bytevector (SCM, SCM);
40SCM_API SCM scm_c_make_bytevector (unsigned);
41SCM_API SCM scm_native_endianness (void);
42SCM_API SCM scm_bytevector_p (SCM);
43SCM_API SCM scm_bytevector_length (SCM);
44SCM_API SCM scm_bytevector_eq_p (SCM, SCM);
45SCM_API SCM scm_bytevector_fill_x (SCM, SCM);
46SCM_API SCM scm_bytevector_copy_x (SCM, SCM, SCM, SCM, SCM);
47SCM_API SCM scm_bytevector_copy (SCM);
48
49SCM_API SCM scm_bytevector_to_u8_list (SCM);
50SCM_API SCM scm_u8_list_to_bytevector (SCM);
51SCM_API SCM scm_uint_list_to_bytevector (SCM, SCM, SCM);
52SCM_API SCM scm_bytevector_to_uint_list (SCM, SCM, SCM);
53SCM_API SCM scm_sint_list_to_bytevector (SCM, SCM, SCM);
54SCM_API SCM scm_bytevector_to_sint_list (SCM, SCM, SCM);
55
56SCM_API SCM scm_bytevector_u16_native_ref (SCM, SCM);
57SCM_API SCM scm_bytevector_s16_native_ref (SCM, SCM);
58SCM_API SCM scm_bytevector_u32_native_ref (SCM, SCM);
59SCM_API SCM scm_bytevector_s32_native_ref (SCM, SCM);
60SCM_API SCM scm_bytevector_u64_native_ref (SCM, SCM);
61SCM_API SCM scm_bytevector_s64_native_ref (SCM, SCM);
62SCM_API SCM scm_bytevector_u8_ref (SCM, SCM);
63SCM_API SCM scm_bytevector_s8_ref (SCM, SCM);
64SCM_API SCM scm_bytevector_uint_ref (SCM, SCM, SCM, SCM);
65SCM_API SCM scm_bytevector_sint_ref (SCM, SCM, SCM, SCM);
66SCM_API SCM scm_bytevector_u16_ref (SCM, SCM, SCM);
67SCM_API SCM scm_bytevector_s16_ref (SCM, SCM, SCM);
68SCM_API SCM scm_bytevector_u32_ref (SCM, SCM, SCM);
69SCM_API SCM scm_bytevector_s32_ref (SCM, SCM, SCM);
70SCM_API SCM scm_bytevector_u64_ref (SCM, SCM, SCM);
71SCM_API SCM scm_bytevector_s64_ref (SCM, SCM, SCM);
72SCM_API SCM scm_bytevector_u16_native_set_x (SCM, SCM, SCM);
73SCM_API SCM scm_bytevector_s16_native_set_x (SCM, SCM, SCM);
74SCM_API SCM scm_bytevector_u32_native_set_x (SCM, SCM, SCM);
75SCM_API SCM scm_bytevector_s32_native_set_x (SCM, SCM, SCM);
76SCM_API SCM scm_bytevector_u64_native_set_x (SCM, SCM, SCM);
77SCM_API SCM scm_bytevector_s64_native_set_x (SCM, SCM, SCM);
78SCM_API SCM scm_bytevector_u8_set_x (SCM, SCM, SCM);
79SCM_API SCM scm_bytevector_s8_set_x (SCM, SCM, SCM);
80SCM_API SCM scm_bytevector_uint_set_x (SCM, SCM, SCM, SCM, SCM);
81SCM_API SCM scm_bytevector_sint_set_x (SCM, SCM, SCM, SCM, SCM);
82SCM_API SCM scm_bytevector_u16_set_x (SCM, SCM, SCM, SCM);
83SCM_API SCM scm_bytevector_s16_set_x (SCM, SCM, SCM, SCM);
84SCM_API SCM scm_bytevector_u32_set_x (SCM, SCM, SCM, SCM);
85SCM_API SCM scm_bytevector_s32_set_x (SCM, SCM, SCM, SCM);
86SCM_API SCM scm_bytevector_u64_set_x (SCM, SCM, SCM, SCM);
87SCM_API SCM scm_bytevector_s64_set_x (SCM, SCM, SCM, SCM);
88SCM_API SCM scm_bytevector_ieee_single_ref (SCM, SCM, SCM);
89SCM_API SCM scm_bytevector_ieee_single_native_ref (SCM, SCM);
90SCM_API SCM scm_bytevector_ieee_single_set_x (SCM, SCM, SCM, SCM);
91SCM_API SCM scm_bytevector_ieee_single_native_set_x (SCM, SCM, SCM);
92SCM_API SCM scm_bytevector_ieee_double_ref (SCM, SCM, SCM);
93SCM_API SCM scm_bytevector_ieee_double_native_ref (SCM, SCM);
94SCM_API SCM scm_bytevector_ieee_double_set_x (SCM, SCM, SCM, SCM);
95SCM_API SCM scm_bytevector_ieee_double_native_set_x (SCM, SCM, SCM);
96SCM_API SCM scm_string_to_utf8 (SCM);
97SCM_API SCM scm_string_to_utf16 (SCM, SCM);
98SCM_API SCM scm_string_to_utf32 (SCM, SCM);
99SCM_API SCM scm_utf8_to_string (SCM);
100SCM_API SCM scm_utf16_to_string (SCM, SCM);
101SCM_API SCM scm_utf32_to_string (SCM, SCM);
102
103
104\f
105/* Internal API. */
106
107/* The threshold (in octets) under which bytevectors are stored "in-line",
108 i.e., without allocating memory beside the SMOB itself (a double cell).
109 This optimization is necessary since small bytevectors are expected to be
110 common. */
111#define SCM_BYTEVECTOR_INLINE_THRESHOLD (2 * sizeof (SCM))
112#define SCM_BYTEVECTOR_INLINEABLE_SIZE_P(_size) \
113 ((_size) <= SCM_BYTEVECTOR_INLINE_THRESHOLD)
114#define SCM_BYTEVECTOR_INLINE_P(_bv) \
115 (SCM_BYTEVECTOR_INLINEABLE_SIZE_P (SCM_BYTEVECTOR_LENGTH (_bv)))
116
117/* Hint that is passed to `scm_gc_malloc ()' and friends. */
118#define SCM_GC_BYTEVECTOR "bytevector"
119
120SCM_API void scm_init_bytevectors (void);
121
122SCM_INTERNAL scm_t_bits scm_tc16_bytevector;
123SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, unsigned);
124
125#define scm_c_shrink_bytevector(_bv, _len) \
126 (SCM_BYTEVECTOR_INLINE_P (_bv) \
127 ? (_bv) \
128 : scm_i_shrink_bytevector ((_bv), (_len)))
129
130SCM_INTERNAL SCM scm_i_shrink_bytevector (SCM, unsigned);
131SCM_INTERNAL SCM scm_null_bytevector;
132
133#endif /* SCM_BYTEVECTORS_H */