bytevectors.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef SCM_BYTEVECTORS_H
  2. #define SCM_BYTEVECTORS_H
  3. /* Copyright (C) 2009 Free Software Foundation, Inc.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public License
  7. * as published by the Free Software Foundation; either version 3 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. */
  20. #include "libguile/__scm.h"
  21. /* R6RS bytevectors. */
  22. #define SCM_BYTEVECTOR_LENGTH(_bv) \
  23. ((size_t) SCM_SMOB_DATA (_bv))
  24. #define SCM_BYTEVECTOR_CONTENTS(_bv) \
  25. (SCM_BYTEVECTOR_INLINE_P (_bv) \
  26. ? (signed char *) SCM_SMOB_OBJECT_2_LOC (_bv) \
  27. : (signed char *) SCM_SMOB_DATA_2 (_bv))
  28. SCM_API SCM scm_endianness_big;
  29. SCM_API SCM scm_endianness_little;
  30. SCM_API SCM scm_c_make_bytevector (size_t);
  31. SCM_API int scm_is_bytevector (SCM);
  32. SCM_API size_t scm_c_bytevector_length (SCM);
  33. SCM_API scm_t_uint8 scm_c_bytevector_ref (SCM, size_t);
  34. SCM_API void scm_c_bytevector_set_x (SCM, size_t, scm_t_uint8);
  35. SCM_API SCM scm_make_bytevector (SCM, SCM);
  36. SCM_API SCM scm_native_endianness (void);
  37. SCM_API SCM scm_bytevector_p (SCM);
  38. SCM_API SCM scm_bytevector_length (SCM);
  39. SCM_API SCM scm_bytevector_eq_p (SCM, SCM);
  40. SCM_API SCM scm_bytevector_fill_x (SCM, SCM);
  41. SCM_API SCM scm_bytevector_copy_x (SCM, SCM, SCM, SCM, SCM);
  42. SCM_API SCM scm_bytevector_copy (SCM);
  43. SCM_API SCM scm_uniform_array_to_bytevector (SCM);
  44. SCM_API SCM scm_bytevector_to_u8_list (SCM);
  45. SCM_API SCM scm_u8_list_to_bytevector (SCM);
  46. SCM_API SCM scm_uint_list_to_bytevector (SCM, SCM, SCM);
  47. SCM_API SCM scm_bytevector_to_uint_list (SCM, SCM, SCM);
  48. SCM_API SCM scm_sint_list_to_bytevector (SCM, SCM, SCM);
  49. SCM_API SCM scm_bytevector_to_sint_list (SCM, SCM, SCM);
  50. SCM_API SCM scm_bytevector_u16_native_ref (SCM, SCM);
  51. SCM_API SCM scm_bytevector_s16_native_ref (SCM, SCM);
  52. SCM_API SCM scm_bytevector_u32_native_ref (SCM, SCM);
  53. SCM_API SCM scm_bytevector_s32_native_ref (SCM, SCM);
  54. SCM_API SCM scm_bytevector_u64_native_ref (SCM, SCM);
  55. SCM_API SCM scm_bytevector_s64_native_ref (SCM, SCM);
  56. SCM_API SCM scm_bytevector_u8_ref (SCM, SCM);
  57. SCM_API SCM scm_bytevector_s8_ref (SCM, SCM);
  58. SCM_API SCM scm_bytevector_uint_ref (SCM, SCM, SCM, SCM);
  59. SCM_API SCM scm_bytevector_sint_ref (SCM, SCM, SCM, SCM);
  60. SCM_API SCM scm_bytevector_u16_ref (SCM, SCM, SCM);
  61. SCM_API SCM scm_bytevector_s16_ref (SCM, SCM, SCM);
  62. SCM_API SCM scm_bytevector_u32_ref (SCM, SCM, SCM);
  63. SCM_API SCM scm_bytevector_s32_ref (SCM, SCM, SCM);
  64. SCM_API SCM scm_bytevector_u64_ref (SCM, SCM, SCM);
  65. SCM_API SCM scm_bytevector_s64_ref (SCM, SCM, SCM);
  66. SCM_API SCM scm_bytevector_u16_native_set_x (SCM, SCM, SCM);
  67. SCM_API SCM scm_bytevector_s16_native_set_x (SCM, SCM, SCM);
  68. SCM_API SCM scm_bytevector_u32_native_set_x (SCM, SCM, SCM);
  69. SCM_API SCM scm_bytevector_s32_native_set_x (SCM, SCM, SCM);
  70. SCM_API SCM scm_bytevector_u64_native_set_x (SCM, SCM, SCM);
  71. SCM_API SCM scm_bytevector_s64_native_set_x (SCM, SCM, SCM);
  72. SCM_API SCM scm_bytevector_u8_set_x (SCM, SCM, SCM);
  73. SCM_API SCM scm_bytevector_s8_set_x (SCM, SCM, SCM);
  74. SCM_API SCM scm_bytevector_uint_set_x (SCM, SCM, SCM, SCM, SCM);
  75. SCM_API SCM scm_bytevector_sint_set_x (SCM, SCM, SCM, SCM, SCM);
  76. SCM_API SCM scm_bytevector_u16_set_x (SCM, SCM, SCM, SCM);
  77. SCM_API SCM scm_bytevector_s16_set_x (SCM, SCM, SCM, SCM);
  78. SCM_API SCM scm_bytevector_u32_set_x (SCM, SCM, SCM, SCM);
  79. SCM_API SCM scm_bytevector_s32_set_x (SCM, SCM, SCM, SCM);
  80. SCM_API SCM scm_bytevector_u64_set_x (SCM, SCM, SCM, SCM);
  81. SCM_API SCM scm_bytevector_s64_set_x (SCM, SCM, SCM, SCM);
  82. SCM_API SCM scm_bytevector_ieee_single_ref (SCM, SCM, SCM);
  83. SCM_API SCM scm_bytevector_ieee_single_native_ref (SCM, SCM);
  84. SCM_API SCM scm_bytevector_ieee_single_set_x (SCM, SCM, SCM, SCM);
  85. SCM_API SCM scm_bytevector_ieee_single_native_set_x (SCM, SCM, SCM);
  86. SCM_API SCM scm_bytevector_ieee_double_ref (SCM, SCM, SCM);
  87. SCM_API SCM scm_bytevector_ieee_double_native_ref (SCM, SCM);
  88. SCM_API SCM scm_bytevector_ieee_double_set_x (SCM, SCM, SCM, SCM);
  89. SCM_API SCM scm_bytevector_ieee_double_native_set_x (SCM, SCM, SCM);
  90. SCM_API SCM scm_string_to_utf8 (SCM);
  91. SCM_API SCM scm_string_to_utf16 (SCM, SCM);
  92. SCM_API SCM scm_string_to_utf32 (SCM, SCM);
  93. SCM_API SCM scm_utf8_to_string (SCM);
  94. SCM_API SCM scm_utf16_to_string (SCM, SCM);
  95. SCM_API SCM scm_utf32_to_string (SCM, SCM);
  96. /* Internal API. */
  97. /* The threshold (in octets) under which bytevectors are stored "in-line",
  98. i.e., without allocating memory beside the SMOB itself (a double cell).
  99. This optimization is necessary since small bytevectors are expected to be
  100. common. */
  101. #define SCM_BYTEVECTOR_P(_bv) \
  102. SCM_SMOB_PREDICATE (scm_tc16_bytevector, _bv)
  103. #define SCM_BYTEVECTOR_INLINE_THRESHOLD (2 * sizeof (SCM))
  104. #define SCM_BYTEVECTOR_INLINEABLE_SIZE_P(_size) \
  105. ((_size) <= SCM_BYTEVECTOR_INLINE_THRESHOLD)
  106. #define SCM_BYTEVECTOR_INLINE_P(_bv) \
  107. (SCM_BYTEVECTOR_INLINEABLE_SIZE_P (SCM_BYTEVECTOR_LENGTH (_bv)))
  108. /* Hint that is passed to `scm_gc_malloc ()' and friends. */
  109. #define SCM_GC_BYTEVECTOR "bytevector"
  110. SCM_INTERNAL void scm_bootstrap_bytevectors (void);
  111. SCM_INTERNAL void scm_init_bytevectors (void);
  112. SCM_INTERNAL scm_t_bits scm_tc16_bytevector;
  113. SCM_INTERNAL SCM scm_i_native_endianness;
  114. SCM_INTERNAL SCM scm_c_take_bytevector (signed char *, size_t);
  115. #define scm_c_shrink_bytevector(_bv, _len) \
  116. (SCM_BYTEVECTOR_INLINE_P (_bv) \
  117. ? (_bv) \
  118. : scm_i_shrink_bytevector ((_bv), (_len)))
  119. SCM_INTERNAL SCM scm_i_shrink_bytevector (SCM, size_t);
  120. SCM_INTERNAL void scm_i_bytevector_generalized_set_x (SCM, size_t, SCM);
  121. SCM_INTERNAL SCM scm_null_bytevector;
  122. #endif /* SCM_BYTEVECTORS_H */