Commit | Line | Data |
---|---|---|
16ea9620 MV |
1 | /* classes: h_files */ |
2 | ||
3 | #ifndef SCM_INLINE_H | |
4 | #define SCM_INLINE_H | |
5 | ||
452c5ad9 LC |
6 | /* Copyright (C) 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010, |
7 | * 2011 Free Software Foundation, Inc. | |
16ea9620 | 8 | * |
73be1d9e | 9 | * This library is free software; you can redistribute it and/or |
53befeb7 NJ |
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. | |
16ea9620 | 13 | * |
53befeb7 NJ |
14 | * This library is distributed in the hope that it will be useful, but |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
73be1d9e MV |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | * Lesser General Public License for more details. | |
16ea9620 | 18 | * |
73be1d9e MV |
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 | |
53befeb7 NJ |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | * 02110-1301 USA | |
73be1d9e | 23 | */ |
16ea9620 MV |
24 | |
25 | /* This file is for inline functions. On platforms that don't support | |
4cf77f09 AW |
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. */ | |
16ea9620 | 29 | |
f5c2af4b | 30 | #include "libguile/__scm.h" |
1e71eafb | 31 | |
16ea9620 MV |
32 | #include "libguile/pairs.h" |
33 | #include "libguile/gc.h" | |
9bc4701c | 34 | #include "libguile/threads.h" |
2a610be5 | 35 | #include "libguile/array-handle.h" |
f5c2af4b | 36 | #include "libguile/ports.h" |
2a610be5 | 37 | #include "libguile/numbers.h" |
f5c2af4b | 38 | #include "libguile/error.h" |
16ea9620 | 39 | |
c8a1bdc4 | 40 | |
4cf77f09 AW |
41 | SCM_INLINE SCM scm_array_handle_ref (scm_t_array_handle *h, ssize_t pos); |
42 | SCM_INLINE void scm_array_handle_set (scm_t_array_handle *h, ssize_t pos, SCM val); | |
60e7529a | 43 | |
4cf77f09 AW |
44 | SCM_INLINE int scm_is_pair (SCM x); |
45 | SCM_INLINE int scm_is_string (SCM x); | |
f5c2af4b | 46 | |
ff670362 AW |
47 | SCM_INLINE SCM scm_cell (scm_t_bits car, scm_t_bits cdr); |
48 | SCM_INLINE SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr, | |
49 | scm_t_bits ccr, scm_t_bits cdr); | |
50 | SCM_INLINE SCM scm_words (scm_t_bits car, scm_t_uint16 n_words); | |
6253f3f1 | 51 | |
ff670362 AW |
52 | #if SCM_CAN_INLINE || defined SCM_INLINE_C_IMPLEMENTING_INLINES |
53 | /* Either inlining, or being included from inline.c. */ | |
6253f3f1 | 54 | |
4cf77f09 | 55 | SCM_INLINE_IMPLEMENTATION SCM |
9598a406 MV |
56 | scm_array_handle_ref (scm_t_array_handle *h, ssize_t p) |
57 | { | |
6d7c4402 | 58 | if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) |
2a610be5 AW |
59 | /* catch overflow */ |
60 | scm_out_of_range (NULL, scm_from_ssize_t (p)); | |
61 | /* perhaps should catch overflow here too */ | |
62 | return h->impl->vref (h, h->base + p); | |
9598a406 | 63 | } |
eab1b259 | 64 | |
4cf77f09 | 65 | SCM_INLINE_IMPLEMENTATION void |
9598a406 MV |
66 | scm_array_handle_set (scm_t_array_handle *h, ssize_t p, SCM v) |
67 | { | |
3245c0fb | 68 | if (SCM_UNLIKELY (p < 0 && ((size_t)-p) > h->base)) |
2a610be5 AW |
69 | /* catch overflow */ |
70 | scm_out_of_range (NULL, scm_from_ssize_t (p)); | |
71 | /* perhaps should catch overflow here too */ | |
72 | h->impl->vset (h, h->base + p, v); | |
9598a406 | 73 | } |
eab1b259 | 74 | |
4cf77f09 | 75 | SCM_INLINE_IMPLEMENTATION int |
d5ad4aa6 MV |
76 | scm_is_pair (SCM x) |
77 | { | |
23f2b9a3 KR |
78 | /* The following "workaround_for_gcc_295" avoids bad code generated by |
79 | i386 gcc 2.95.4 (the Debian packaged 2.95.4-24 at least). | |
80 | ||
81 | Under the default -O2 the inlined SCM_I_CONSP test gets "optimized" so | |
82 | the fetch of the tag word from x is done before confirming it's a | |
83 | non-immediate (SCM_NIMP). Needless to say that bombs badly if x is a | |
84 | immediate. This was seen to afflict scm_srfi1_split_at and something | |
85 | deep in the bowels of ceval(). In both cases segvs resulted from | |
86 | deferencing a random immediate value. srfi-1.test exposes the problem | |
87 | through a short list, the immediate being SCM_EOL in that case. | |
88 | Something in syntax.test exposed the ceval() problem. | |
89 | ||
90 | Just "volatile SCM workaround_for_gcc_295 = lst" is enough to avoid the | |
91 | problem, without even using that variable. The "w=w" is just to | |
92 | prevent a warning about it being unused. | |
93 | */ | |
94 | #if defined (__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 95 | |
95 | volatile SCM workaround_for_gcc_295 = x; | |
96 | workaround_for_gcc_295 = workaround_for_gcc_295; | |
97 | #endif | |
98 | ||
d5ad4aa6 MV |
99 | return SCM_I_CONSP (x); |
100 | } | |
101 | ||
4cf77f09 | 102 | SCM_INLINE_IMPLEMENTATION int |
183f7849 LC |
103 | scm_is_string (SCM x) |
104 | { | |
dc7da0be | 105 | return SCM_HAS_TYP7 (x, scm_tc7_string); |
183f7849 | 106 | } |
f5c2af4b | 107 | |
16ea9620 | 108 | #endif |
16ea9620 | 109 | #endif |