summaryrefslogtreecommitdiff
path: root/libguile/bytevectors.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/bytevectors.c')
-rw-r--r--libguile/bytevectors.c141
1 files changed, 75 insertions, 66 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c
index 0ac5ea6a6..7dfdab499 100644
--- a/libguile/bytevectors.c
+++ b/libguile/bytevectors.c
@@ -1,51 +1,60 @@
-/* Copyright (C) 2009-2015, 2019 Free Software Foundation, Inc.
- *
- * This library 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.
- *
- * This library 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 this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
+/* Copyright 2009-2015,2018-2019
+ 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/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
-#include <alloca.h>
-#include <assert.h>
-
-#include <gmp.h>
-
-#include "libguile/_scm.h"
-#include "libguile/extensions.h"
-#include "libguile/bytevectors.h"
-#include "libguile/strings.h"
-#include "libguile/validate.h"
-#include "libguile/arrays.h"
-#include "libguile/array-handle.h"
-#include "libguile/uniform.h"
-#include "libguile/srfi-4.h"
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
#include <byteswap.h>
+#include <errno.h>
#include <striconveh.h>
#include <uniconv.h>
#include <unistr.h>
+#include <string.h>
+#include <alloca.h>
+#include <assert.h>
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <gmp.h>
-#include <string.h>
+#include "array-handle.h"
+#include "arrays.h"
+#include "boolean.h"
+#include "dynwind.h"
+#include "extensions.h"
+#include "generalized-vectors.h"
+#include "gsubr.h"
+#include "list.h"
+#include "numbers.h"
+#include "pairs.h"
+#include "ports.h"
+#include "srfi-4.h"
+#include "strings.h"
+#include "symbols.h"
+#include "uniform.h"
+#include "version.h"
+
+#include "bytevectors.h"
@@ -53,12 +62,12 @@
/* Convenience macros. These are used by the various templates (macros) that
are parameterized by integer signedness. */
-#define INT8_T_signed scm_t_int8
-#define INT8_T_unsigned scm_t_uint8
-#define INT16_T_signed scm_t_int16
-#define INT16_T_unsigned scm_t_uint16
-#define INT32_T_signed scm_t_int32
-#define INT32_T_unsigned scm_t_uint32
+#define INT8_T_signed int8_t
+#define INT8_T_unsigned uint8_t
+#define INT16_T_signed int16_t
+#define INT16_T_unsigned uint16_t
+#define INT32_T_signed int32_t
+#define INT32_T_unsigned uint32_t
#define is_signed_int8(_x) (((_x) >= -128L) && ((_x) <= 127L))
#define is_unsigned_int8(_x) ((_x) <= 255UL)
#define is_signed_int16(_x) (((_x) >= -32768L) && ((_x) <= 32767L))
@@ -372,17 +381,17 @@ scm_c_bytevector_length (SCM bv)
}
#undef FUNC_NAME
-scm_t_uint8
+uint8_t
scm_c_bytevector_ref (SCM bv, size_t index)
#define FUNC_NAME "scm_c_bytevector_ref"
{
size_t c_len;
- const scm_t_uint8 *c_bv;
+ const uint8_t *c_bv;
SCM_VALIDATE_BYTEVECTOR (1, bv);
c_len = SCM_BYTEVECTOR_LENGTH (bv);
- c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ c_bv = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
if (SCM_UNLIKELY (index >= c_len))
scm_out_of_range (FUNC_NAME, scm_from_size_t (index));
@@ -392,16 +401,16 @@ scm_c_bytevector_ref (SCM bv, size_t index)
#undef FUNC_NAME
void
-scm_c_bytevector_set_x (SCM bv, size_t index, scm_t_uint8 value)
+scm_c_bytevector_set_x (SCM bv, size_t index, uint8_t value)
#define FUNC_NAME "scm_c_bytevector_set_x"
{
size_t c_len;
- scm_t_uint8 *c_bv;
+ uint8_t *c_bv;
SCM_VALIDATE_MUTABLE_BYTEVECTOR (1, bv);
c_len = SCM_BYTEVECTOR_LENGTH (bv);
- c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ c_bv = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
if (SCM_UNLIKELY (index >= c_len))
scm_out_of_range (FUNC_NAME, scm_from_size_t (index));
@@ -481,7 +490,7 @@ SCM_DEFINE (scm_make_bytevector, "make-bytevector", 1, 1, 0,
{
SCM bv;
size_t c_len;
- scm_t_uint8 c_fill = 0;
+ uint8_t c_fill = 0;
SCM_VALIDATE_SIZE_COPY (1, len, c_len);
if (!scm_is_eq (fill, SCM_UNDEFINED))
@@ -491,16 +500,16 @@ SCM_DEFINE (scm_make_bytevector, "make-bytevector", 1, 1, 0,
value = scm_to_int (fill);
if (SCM_UNLIKELY ((value < -128) || (value > 255)))
scm_out_of_range (FUNC_NAME, fill);
- c_fill = (scm_t_uint8) value;
+ c_fill = (uint8_t) value;
}
bv = make_bytevector (c_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
if (!scm_is_eq (fill, SCM_UNDEFINED))
{
size_t i;
- scm_t_uint8 *contents;
+ uint8_t *contents;
- contents = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ contents = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
for (i = 0; i < c_len; i++)
contents[i] = c_fill;
}
@@ -556,7 +565,7 @@ SCM_DEFINE (scm_bytevector_fill_x, "bytevector-fill!", 2, 0, 0,
#define FUNC_NAME s_scm_bytevector_fill_x
{
size_t c_len, i;
- scm_t_uint8 *c_bv, c_fill;
+ uint8_t *c_bv, c_fill;
int value;
SCM_VALIDATE_MUTABLE_BYTEVECTOR (1, bv);
@@ -564,10 +573,10 @@ SCM_DEFINE (scm_bytevector_fill_x, "bytevector-fill!", 2, 0, 0,
value = scm_to_int (fill);
if (SCM_UNLIKELY ((value < -128) || (value > 255)))
scm_out_of_range (FUNC_NAME, fill);
- c_fill = (scm_t_uint8) value;
+ c_fill = (uint8_t) value;
c_len = SCM_BYTEVECTOR_LENGTH (bv);
- c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ c_bv = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
for (i = 0; i < c_len; i++)
c_bv[i] = c_fill;
@@ -730,12 +739,12 @@ SCM_DEFINE (scm_bytevector_to_u8_list, "bytevector->u8-list", 1, 0, 0,
{
SCM lst, pair;
size_t c_len, i;
- scm_t_uint8 *c_bv;
+ uint8_t *c_bv;
SCM_VALIDATE_BYTEVECTOR (1, bv);
c_len = SCM_BYTEVECTOR_LENGTH (bv);
- c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ c_bv = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
lst = scm_make_list (scm_from_size_t (c_len), SCM_UNSPECIFIED);
for (i = 0, pair = lst;
@@ -756,12 +765,12 @@ SCM_DEFINE (scm_u8_list_to_bytevector, "u8-list->bytevector", 1, 0, 0,
{
SCM bv, item;
size_t c_len, i;
- scm_t_uint8 *c_bv;
+ uint8_t *c_bv;
SCM_VALIDATE_LIST_COPYLEN (1, lst, c_len);
bv = make_bytevector (c_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
- c_bv = (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv);
+ c_bv = (uint8_t *) SCM_BYTEVECTOR_CONTENTS (bv);
for (i = 0; i < c_len; lst = SCM_CDR (lst), i++)
{
@@ -773,7 +782,7 @@ SCM_DEFINE (scm_u8_list_to_bytevector, "u8-list->bytevector", 1, 0, 0,
c_item = SCM_I_INUM (item);
if (SCM_LIKELY ((c_item >= 0) && (c_item < 256)))
- c_bv[i] = (scm_t_uint8) c_item;
+ c_bv[i] = (uint8_t) c_item;
else
goto type_error;
}
@@ -1610,13 +1619,13 @@ SCM_DEFINE (scm_bytevector_s64_native_set_x, "bytevector-s64-native-set!",
union scm_ieee754_float
{
float f;
- scm_t_uint32 i;
+ uint32_t i;
};
union scm_ieee754_double
{
double d;
- scm_t_uint64 i;
+ uint64_t i;
};
@@ -1921,7 +1930,7 @@ utf_encoding_name (char *name, size_t utf_width, SCM endianness)
\
SCM_VALIDATE_STRING (1, str); \
if (scm_is_eq (endianness, SCM_UNDEFINED)) \
- endianness = sym_big; \
+ endianness = sym_big; \
else \
SCM_VALIDATE_SYMBOL (2, endianness); \
\
@@ -1943,7 +1952,7 @@ utf_encoding_name (char *name, size_t utf_width, SCM endianness)
const scm_t_wchar *wbuf = scm_i_string_wide_chars (str); \
c_utf = u32_conv_to_encoding (c_utf_name, \
iconveh_question_mark, \
- (scm_t_uint32 *) wbuf, \
+ (uint32_t *) wbuf, \
c_strlen, NULL, NULL, &c_utf_len); \
if (SCM_UNLIKELY (c_utf == NULL)) \
scm_syserror_msg (FUNC_NAME, "failed to convert string: ~A", \
@@ -1967,12 +1976,12 @@ SCM_DEFINE (scm_string_to_utf8, "string->utf8",
#define FUNC_NAME s_scm_string_to_utf8
{
SCM utf;
- scm_t_uint8 *c_utf;
+ uint8_t *c_utf;
size_t c_utf_len = 0;
SCM_VALIDATE_STRING (1, str);
- c_utf = (scm_t_uint8 *) scm_to_utf8_stringn (str, &c_utf_len);
+ c_utf = (uint8_t *) scm_to_utf8_stringn (str, &c_utf_len);
utf = make_bytevector (c_utf_len, SCM_ARRAY_ELEMENT_TYPE_VU8);
memcpy (SCM_BYTEVECTOR_CONTENTS (utf), c_utf, c_utf_len);
free (c_utf);
@@ -2138,5 +2147,5 @@ scm_bootstrap_bytevectors (void)
void
scm_init_bytevectors (void)
{
-#include "libguile/bytevectors.x"
+#include "bytevectors.x"
}