Revert "Revert ABI version, make libgnutls-extra use another ABI version."
[gnutls.git] / guile / src / utils.h
blob17e3655d580556974ec8ed2a5de4d077d0888b92
1 /* GNUTLS --- Guile bindings for GnuTLS.
2 Copyright (C) 2007, 2008 Free Software Foundation
4 GNUTLS 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 GNUTLS 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 GNUTLS; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18 #ifndef GUILE_GNUTLS_UTILS_H
19 #define GUILE_GNUTLS_UTILS_H
21 /* Common utilities. */
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <libguile.h>
30 /* Compiler twiddling. */
32 #ifdef __GNUC__
33 # define EXPECT __builtin_expect
34 # define NO_RETURN __attribute__ ((__noreturn__))
35 #else
36 # define EXPECT(_expr, _value) (_expr)
37 # define NO_RETURN
38 #endif
40 #define EXPECT_TRUE(_expr) EXPECT ((_expr), 1)
41 #define EXPECT_FALSE(_expr) EXPECT ((_expr), 0)
44 /* Arrays as byte vectors. */
46 extern const char scm_gnutls_array_error_message[];
48 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
49 corresponding to ARRAY. */
50 static inline const char *
51 scm_gnutls_get_array (SCM array, scm_t_array_handle *c_handle, size_t *c_len,
52 const char *func_name)
54 const char *c_array = NULL;
55 const scm_t_array_dim *c_dims;
57 scm_array_get_handle (array, c_handle);
58 c_dims = scm_array_handle_dims (c_handle);
59 if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
61 scm_array_handle_release (c_handle);
62 scm_misc_error (func_name, scm_gnutls_array_error_message,
63 scm_list_1 (array));
65 else
67 size_t c_elem_size;
69 c_elem_size = scm_array_handle_uniform_element_size (c_handle);
70 *c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
72 c_array = (char *) scm_array_handle_uniform_elements (c_handle);
75 return (c_array);
78 /* Initialize C_HANDLE and C_LEN and return the contiguous C array
79 corresponding to ARRAY. The returned array can be written to. */
80 static inline char *
81 scm_gnutls_get_writable_array (SCM array, scm_t_array_handle *c_handle,
82 size_t *c_len,
83 const char *func_name)
85 char *c_array = NULL;
86 const scm_t_array_dim *c_dims;
88 scm_array_get_handle (array, c_handle);
89 c_dims = scm_array_handle_dims (c_handle);
90 if ((scm_array_handle_rank (c_handle) != 1) || (c_dims->inc != 1))
92 scm_array_handle_release (c_handle);
93 scm_misc_error (func_name, scm_gnutls_array_error_message,
94 scm_list_1 (array));
96 else
98 size_t c_elem_size;
100 c_elem_size = scm_array_handle_uniform_element_size (c_handle);
101 *c_len = c_elem_size * (c_dims->ubnd - c_dims->lbnd + 1);
103 c_array = (char *) scm_array_handle_uniform_writable_elements (c_handle);
106 return (c_array);
109 #define scm_gnutls_release_array scm_array_handle_release
113 /* Type conversion. */
115 /* Return a list corresponding to the key usage values ORed in C_USAGE. */
116 SCM_API SCM scm_from_gnutls_key_usage_flags (unsigned int c_usage);
118 #endif
120 /* arch-tag: a33400bc-b5e3-429e-80e0-6ff14cab79e7