Merge remote-tracking branch 'origin/stable-2.0'
[bpt/guile.git] / libguile / inline.h
1 /* classes: h_files */
2
3 #ifndef SCM_INLINE_H
4 #define SCM_INLINE_H
5
6 /* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010,
7 * 2011, 2012 Free Software Foundation, Inc.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 3 of
12 * the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25 /* This file is for inline functions. On platforms that don't support
26 inlining functions, they are turned into ordinary functions. On
27 platforms that do support inline functions, the definitions are still
28 compiled into the library, once, in inline.c. */
29
30 #include "libguile/__scm.h"
31
32 #include "libguile/gc.h"
33 #include "libguile/threads.h"
34 #include "libguile/array-handle.h"
35 #include "libguile/ports.h"
36 #include "libguile/numbers.h"
37 #include "libguile/error.h"
38
39
40 SCM_INLINE SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t pos);
41 SCM_INLINE void scm_array_handle_set (scm_t_array_handle *h, ssize_t pos, SCM val);
42
43 SCM_INLINE int scm_is_string (SCM x);
44
45 SCM_INLINE SCM scm_cell (scm_t_bits car, scm_t_bits cdr);
46 SCM_INLINE SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr,
47 scm_t_bits ccr, scm_t_bits cdr);
48 SCM_INLINE SCM scm_words (scm_t_bits car, scm_t_uint32 n_words);
49
50 #if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES
51 /* Either inlining, or being included from inline.c. */
52
53 SCM_INLINE_IMPLEMENTATION SCM
54 scm_array_handle_ref (scm_t_array_handle *h, ssize_t p)
55 {
56 if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base))
57 /* catch overflow */
58 scm_out_of_range (NULL, scm_from_ssize_t (p));
59 /* perhaps should catch overflow here too */
60 return h->impl->vref (h, h->base + p);
61 }
62
63 SCM_INLINE_IMPLEMENTATION void
64 scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v)
65 {
66 if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base))
67 /* catch overflow */
68 scm_out_of_range (NULL, scm_from_ssize_t (p));
69 /* perhaps should catch overflow here too */
70 h->impl->vset (h, h->base + p, v);
71 }
72
73 SCM_INLINE_IMPLEMENTATION int
74 scm_is_string (SCM x)
75 {
76 return SCM_HAS_TYP7 (x, scm_tc7_string);
77 }
78
79 #endif
80 #endif