Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: h_files */ |
2 | ||
61045190 DH |
3 | #ifndef SCM_GC_H |
4 | #define SCM_GC_H | |
8c494e99 | 5 | |
0d558fbb | 6 | /* Copyright (C) 1995,1996,1998,1999,2000,2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
a00c95d9 | 7 | * |
73be1d9e MV |
8 | * This library is free software; you can redistribute it and/or |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
a00c95d9 | 12 | * |
73be1d9e | 13 | * This library is distributed in the hope that it will be useful, |
0f2d19dd | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 | * Lesser General Public License for more details. | |
a00c95d9 | 17 | * |
73be1d9e MV |
18 | * You should have received a copy of the GNU Lesser General Public |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | */ | |
d3a6bc94 | 22 | |
0f2d19dd JB |
23 | \f |
24 | ||
b4309c3c | 25 | #include "libguile/__scm.h" |
2549a709 | 26 | |
9b3e180c | 27 | #include "libguile/hooks.h" |
9de87eea | 28 | #include "libguile/threads.h" |
9bc4701c | 29 | |
0f2d19dd JB |
30 | \f |
31 | ||
228a24ef | 32 | typedef struct scm_t_cell |
2549a709 | 33 | { |
33c527ec MV |
34 | SCM word_0; |
35 | SCM word_1; | |
228a24ef | 36 | } scm_t_cell; |
2549a709 | 37 | |
c8a1bdc4 HWN |
38 | /* |
39 | CARDS | |
40 | ||
41 | A card is a small `page' of memory; it will be the unit for lazy | |
42 | sweeping, generations, etc. The first cell of a card contains a | |
33c527ec MV |
43 | pointer to the mark bitvector, so that we can find the bitvector |
44 | efficiently: we knock off some lowerorder bits. | |
c8a1bdc4 | 45 | |
33c527ec | 46 | The size on a 32 bit machine is 256 cells = 2kb. The card [XXX] |
c8a1bdc4 | 47 | */ |
2549a709 | 48 | |
2549a709 DH |
49 | |
50 | ||
33c527ec MV |
51 | /* Cray machines have pointers that are incremented once for each |
52 | * word, rather than each byte, the 3 most significant bits encode the | |
53 | * byte within the word. The following macros deal with this by | |
54 | * storing the native Cray pointers like the ones that looks like scm | |
55 | * expects. This is done for any pointers that point to a cell, | |
e618c9a3 | 56 | * pointers to scm_vector elts, functions, &c are not munged. |
2549a709 DH |
57 | */ |
58 | #ifdef _UNICOS | |
c8a1bdc4 | 59 | # define SCM2PTR(x) ((scm_t_cell *) (SCM_UNPACK (x) >> 3)) |
92c2555f | 60 | # define PTR2SCM(x) (SCM_PACK (((scm_t_bits) (x)) << 3)) |
2549a709 | 61 | #else |
c8a1bdc4 | 62 | # define SCM2PTR(x) ((scm_t_cell *) (SCM_UNPACK (x))) |
92c2555f | 63 | # define PTR2SCM(x) (SCM_PACK ((scm_t_bits) (x))) |
2549a709 DH |
64 | #endif /* def _UNICOS */ |
65 | ||
c8a1bdc4 | 66 | |
e618c9a3 | 67 | #define SCM_GC_CARD_N_HEADER_CELLS 1 |
f91f77e6 | 68 | #define SCM_GC_CARD_N_CELLS 256 |
c8a1bdc4 | 69 | #define SCM_GC_SIZEOF_CARD SCM_GC_CARD_N_CELLS * sizeof (scm_t_cell) |
e618c9a3 | 70 | |
c8a1bdc4 | 71 | #define SCM_GC_CARD_BVEC(card) ((scm_t_c_bvec_long *) ((card)->word_0)) |
34d19ef6 | 72 | #define SCM_GC_SET_CARD_BVEC(card, bvec) \ |
33c527ec | 73 | ((card)->word_0 = (SCM) (bvec)) |
c014a02e | 74 | #define SCM_GC_GET_CARD_FLAGS(card) ((long) ((card)->word_1)) |
322ec19d | 75 | #define SCM_GC_SET_CARD_FLAGS(card, flags) \ |
33c527ec | 76 | ((card)->word_1 = (SCM) (flags)) |
e618c9a3 | 77 | |
33c527ec MV |
78 | #define SCM_GC_GET_CARD_FLAG(card, shift) \ |
79 | (SCM_GC_GET_CARD_FLAGS (card) & (1L << (shift))) | |
322ec19d | 80 | #define SCM_GC_SET_CARD_FLAG(card, shift) \ |
33c527ec | 81 | (SCM_GC_SET_CARD_FLAGS (card, SCM_GC_GET_CARD_FLAGS(card) | (1L << (shift)))) |
c8a1bdc4 | 82 | #define SCM_GC_CLEAR_CARD_FLAG(card, shift) \ |
33c527ec | 83 | (SCM_GC_SET_CARD_FLAGS (card, SCM_GC_GET_CARD_FLAGS(card) & ~(1L << (shift)))) |
e618c9a3 | 84 | |
1383773b HWN |
85 | /* |
86 | Remove card flags. They hamper lazy initialization, and aren't used | |
87 | anyways. | |
88 | */ | |
e618c9a3 ML |
89 | |
90 | /* card addressing. for efficiency, cards are *always* aligned to | |
91 | SCM_GC_CARD_SIZE. */ | |
92 | ||
33c527ec | 93 | #define SCM_GC_CARD_SIZE_MASK (SCM_GC_SIZEOF_CARD-1) |
e618c9a3 ML |
94 | #define SCM_GC_CARD_ADDR_MASK (~SCM_GC_CARD_SIZE_MASK) |
95 | ||
c8a1bdc4 | 96 | #define SCM_GC_CELL_CARD(x) ((scm_t_cell *) ((long) (x) & SCM_GC_CARD_ADDR_MASK)) |
c014a02e | 97 | #define SCM_GC_CELL_OFFSET(x) (((long) (x) & SCM_GC_CARD_SIZE_MASK) >> SCM_CELL_SIZE_SHIFT) |
e618c9a3 | 98 | #define SCM_GC_CELL_BVEC(x) SCM_GC_CARD_BVEC (SCM_GC_CELL_CARD (x)) |
c5b0618d | 99 | #define SCM_GC_SET_CELL_BVEC(x, bvec) SCM_GC_SET_CARD_BVEC (SCM_GC_CELL_CARD (x), bvec) |
e618c9a3 ML |
100 | #define SCM_GC_CELL_GET_BIT(x) SCM_C_BVEC_GET (SCM_GC_CELL_BVEC (x), SCM_GC_CELL_OFFSET (x)) |
101 | #define SCM_GC_CELL_SET_BIT(x) SCM_C_BVEC_SET (SCM_GC_CELL_BVEC (x), SCM_GC_CELL_OFFSET (x)) | |
c8a1bdc4 | 102 | #define SCM_GC_CELL_CLEAR_BIT(x) SCM_C_BVEC_CLEAR (SCM_GC_CELL_BVEC (x), SCM_GC_CELL_OFFSET (x)) |
e618c9a3 | 103 | |
c8a1bdc4 | 104 | #define SCM_GC_CARD_UP(x) SCM_GC_CELL_CARD ((char *) (x) + SCM_GC_SIZEOF_CARD - 1) |
e618c9a3 ML |
105 | #define SCM_GC_CARD_DOWN SCM_GC_CELL_CARD |
106 | ||
107 | /* low level bit banging aids */ | |
c8a1bdc4 | 108 | typedef unsigned long scm_t_c_bvec_long; |
e618c9a3 | 109 | |
48c046bc | 110 | #if (SCM_SIZEOF_UNSIGNED_LONG == 8) |
c8a1bdc4 | 111 | # define SCM_C_BVEC_LONG_BITS 64 |
e618c9a3 ML |
112 | # define SCM_C_BVEC_OFFSET_SHIFT 6 |
113 | # define SCM_C_BVEC_POS_MASK 63 | |
114 | # define SCM_CELL_SIZE_SHIFT 4 | |
115 | #else | |
c8a1bdc4 | 116 | # define SCM_C_BVEC_LONG_BITS 32 |
e618c9a3 ML |
117 | # define SCM_C_BVEC_OFFSET_SHIFT 5 |
118 | # define SCM_C_BVEC_POS_MASK 31 | |
119 | # define SCM_CELL_SIZE_SHIFT 3 | |
120 | #endif | |
121 | ||
122 | #define SCM_C_BVEC_OFFSET(pos) (pos >> SCM_C_BVEC_OFFSET_SHIFT) | |
123 | ||
124 | #define SCM_C_BVEC_GET(bvec, pos) (bvec[SCM_C_BVEC_OFFSET (pos)] & (1L << (pos & SCM_C_BVEC_POS_MASK))) | |
125 | #define SCM_C_BVEC_SET(bvec, pos) (bvec[SCM_C_BVEC_OFFSET (pos)] |= (1L << (pos & SCM_C_BVEC_POS_MASK))) | |
c8a1bdc4 | 126 | #define SCM_C_BVEC_CLEAR(bvec, pos) (bvec[SCM_C_BVEC_OFFSET (pos)] &= ~(1L << (pos & SCM_C_BVEC_POS_MASK))) |
e618c9a3 ML |
127 | |
128 | /* testing and changing GC marks */ | |
c8a1bdc4 HWN |
129 | #define SCM_GC_MARK_P(x) SCM_GC_CELL_GET_BIT (x) |
130 | #define SCM_SET_GC_MARK(x) SCM_GC_CELL_SET_BIT (x) | |
131 | #define SCM_CLEAR_GC_MARK(x) SCM_GC_CELL_CLEAR_BIT (x) | |
1fc8902f DH |
132 | |
133 | /* Low level cell data accessing macros. These macros should only be used | |
134 | * from within code related to garbage collection issues, since they will | |
135 | * never check the cells they are applied to - not even if guile is compiled | |
136 | * in debug mode. In particular these macros will even work for free cells, | |
137 | * which should never be encountered by user code. */ | |
138 | ||
33c527ec MV |
139 | #define SCM_GC_CELL_OBJECT(x, n) (((SCM *)SCM2PTR (x)) [n]) |
140 | #define SCM_GC_CELL_WORD(x, n) (SCM_UNPACK (SCM_GC_CELL_OBJECT ((x), (n)))) | |
141 | ||
142 | #define SCM_GC_SET_CELL_OBJECT(x, n, v) ((((SCM *)SCM2PTR (x)) [n]) = (v)) | |
143 | #define SCM_GC_SET_CELL_WORD(x, n, v) \ | |
144 | (SCM_GC_SET_CELL_OBJECT ((x), (n), SCM_PACK (v))) | |
145 | ||
146 | #define SCM_GC_CELL_TYPE(x) (SCM_GC_CELL_OBJECT ((x), 0)) | |
1fc8902f DH |
147 | |
148 | ||
149 | /* Except for the garbage collector, no part of guile should ever run over a | |
150 | * free cell. Thus, if guile is compiled in debug mode the SCM_CELL_* and | |
151 | * SCM_SET_CELL_* macros below report an error if they are applied to a free | |
152 | * cell. Some other plausibility checks are also performed. However, if | |
153 | * guile is not compiled in debug mode, there won't be any time penalty at all | |
154 | * when using these macros. */ | |
2549a709 | 155 | |
406c7d90 DH |
156 | #if (SCM_DEBUG_CELL_ACCESSES == 1) |
157 | # define SCM_VALIDATE_CELL(cell, expr) (scm_assert_cell_valid (cell), (expr)) | |
708cb87c | 158 | #else |
61045190 | 159 | # define SCM_VALIDATE_CELL(cell, expr) (expr) |
708cb87c | 160 | #endif |
46d53380 | 161 | |
f706a58b | 162 | #define SCM_CELL_WORD(x, n) \ |
1fc8902f | 163 | SCM_VALIDATE_CELL ((x), SCM_GC_CELL_WORD ((x), (n))) |
33c527ec MV |
164 | #define SCM_CELL_WORD_0(x) SCM_CELL_WORD ((x), 0) |
165 | #define SCM_CELL_WORD_1(x) SCM_CELL_WORD ((x), 1) | |
166 | #define SCM_CELL_WORD_2(x) SCM_CELL_WORD ((x), 2) | |
167 | #define SCM_CELL_WORD_3(x) SCM_CELL_WORD ((x), 3) | |
2549a709 | 168 | |
f706a58b | 169 | #define SCM_CELL_OBJECT(x, n) \ |
1fc8902f | 170 | SCM_VALIDATE_CELL ((x), SCM_GC_CELL_OBJECT ((x), (n))) |
33c527ec MV |
171 | #define SCM_CELL_OBJECT_0(x) SCM_CELL_OBJECT ((x), 0) |
172 | #define SCM_CELL_OBJECT_1(x) SCM_CELL_OBJECT ((x), 1) | |
173 | #define SCM_CELL_OBJECT_2(x) SCM_CELL_OBJECT ((x), 2) | |
174 | #define SCM_CELL_OBJECT_3(x) SCM_CELL_OBJECT ((x), 3) | |
2549a709 | 175 | |
f706a58b | 176 | #define SCM_SET_CELL_WORD(x, n, v) \ |
1fc8902f | 177 | SCM_VALIDATE_CELL ((x), SCM_GC_SET_CELL_WORD ((x), (n), (v))) |
33c527ec MV |
178 | #define SCM_SET_CELL_WORD_0(x, v) SCM_SET_CELL_WORD ((x), 0, (v)) |
179 | #define SCM_SET_CELL_WORD_1(x, v) SCM_SET_CELL_WORD ((x), 1, (v)) | |
180 | #define SCM_SET_CELL_WORD_2(x, v) SCM_SET_CELL_WORD ((x), 2, (v)) | |
181 | #define SCM_SET_CELL_WORD_3(x, v) SCM_SET_CELL_WORD ((x), 3, (v)) | |
2549a709 | 182 | |
f706a58b | 183 | #define SCM_SET_CELL_OBJECT(x, n, v) \ |
1fc8902f | 184 | SCM_VALIDATE_CELL ((x), SCM_GC_SET_CELL_OBJECT ((x), (n), (v))) |
33c527ec MV |
185 | #define SCM_SET_CELL_OBJECT_0(x, v) SCM_SET_CELL_OBJECT ((x), 0, (v)) |
186 | #define SCM_SET_CELL_OBJECT_1(x, v) SCM_SET_CELL_OBJECT ((x), 1, (v)) | |
187 | #define SCM_SET_CELL_OBJECT_2(x, v) SCM_SET_CELL_OBJECT ((x), 2, (v)) | |
188 | #define SCM_SET_CELL_OBJECT_3(x, v) SCM_SET_CELL_OBJECT ((x), 3, (v)) | |
2549a709 DH |
189 | |
190 | #define SCM_CELL_TYPE(x) SCM_CELL_WORD_0 (x) | |
33c527ec | 191 | #define SCM_SET_CELL_TYPE(x, t) SCM_SET_CELL_WORD_0 ((x), (t)) |
2549a709 | 192 | |
1fc8902f DH |
193 | /* Freelists consist of linked cells where the type entry holds the value |
194 | * scm_tc_free_cell and the second entry holds a pointer to the next cell of | |
195 | * the freelist. Due to this structure, freelist cells are not cons cells | |
196 | * and thus may not be accessed using SCM_CAR and SCM_CDR. */ | |
61045190 | 197 | |
c8a1bdc4 HWN |
198 | /* |
199 | SCM_FREECELL_P removed ; the semantics are ambiguous with lazy | |
200 | sweeping. Could mean "this cell is no longer in use (will be swept)" | |
201 | or "this cell has just been swept, and is not yet in use". | |
202 | */ | |
203 | ||
204 | #define SCM_FREECELL_P this_macro_has_been_removed_see_gc_header_file | |
205 | ||
1fc8902f DH |
206 | #define SCM_FREE_CELL_CDR(x) \ |
207 | (SCM_GC_CELL_OBJECT ((x), 1)) | |
208 | #define SCM_SET_FREE_CELL_CDR(x, v) \ | |
209 | (SCM_GC_SET_CELL_OBJECT ((x), 1, (v))) | |
61045190 DH |
210 | |
211 | ||
141521ad | 212 | #define SCM_CELL_OBJECT_LOC(x, n) (SCM_VALIDATE_CELL((x), &SCM_GC_CELL_OBJECT ((x), (n)))) |
33c527ec MV |
213 | #define SCM_CARLOC(x) (SCM_CELL_OBJECT_LOC ((x), 0)) |
214 | #define SCM_CDRLOC(x) (SCM_CELL_OBJECT_LOC ((x), 1)) | |
2549a709 DH |
215 | |
216 | ||
2549a709 | 217 | |
79e3f9e2 | 218 | |
61045190 | 219 | #if (SCM_DEBUG_CELL_ACCESSES == 1) |
eab1b259 HWN |
220 | /* Set this to != 0 if every cell that is accessed shall be checked: |
221 | */ | |
222 | SCM_API int scm_debug_cell_accesses_p; | |
223 | SCM_API int scm_expensive_debug_cell_accesses_p; | |
224 | SCM_API int scm_debug_cells_gc_interval ; | |
1e71eafb | 225 | void scm_i_expensive_validation_check (SCM cell); |
61045190 DH |
226 | #endif |
227 | ||
9de87eea | 228 | SCM_API scm_i_pthread_mutex_t scm_i_gc_admin_mutex; |
eb01cb64 | 229 | |
33b001fd MV |
230 | SCM_API int scm_block_gc; |
231 | SCM_API int scm_gc_heap_lock; | |
232 | SCM_API unsigned int scm_gc_running_p; | |
9de87eea | 233 | SCM_API scm_i_pthread_mutex_t scm_i_sweep_mutex; |
0f2d19dd JB |
234 | \f |
235 | ||
c8a1bdc4 | 236 | #if (SCM_ENABLE_DEPRECATED == 1) |
33b001fd MV |
237 | SCM_API size_t scm_default_init_heap_size_1; |
238 | SCM_API int scm_default_min_yield_1; | |
239 | SCM_API size_t scm_default_init_heap_size_2; | |
240 | SCM_API int scm_default_min_yield_2; | |
241 | SCM_API size_t scm_default_max_segment_size; | |
c8a1bdc4 HWN |
242 | #else |
243 | #define scm_default_init_heap_size_1 deprecated | |
244 | #define scm_default_min_yield_1 deprecated | |
245 | #define scm_default_init_heap_size_2 deprecated | |
246 | #define scm_default_min_yield_2 deprecated | |
247 | #define scm_default_max_segment_size deprecated | |
248 | #endif | |
249 | ||
33b001fd MV |
250 | |
251 | SCM_API size_t scm_max_segment_size; | |
c8a1bdc4 | 252 | |
9de87eea MV |
253 | #define SCM_SET_FREELIST_LOC(key,ptr) scm_i_pthread_setspecific ((key), (ptr)) |
254 | #define SCM_FREELIST_LOC(key) ((SCM *) scm_i_pthread_getspecific (key)) | |
255 | SCM_API scm_i_pthread_key_t scm_i_freelist; | |
256 | SCM_API scm_i_pthread_key_t scm_i_freelist2; | |
2e945bcc SJ |
257 | SCM_API struct scm_t_cell_type_statistics scm_i_master_freelist; |
258 | SCM_API struct scm_t_cell_type_statistics scm_i_master_freelist2; | |
eab1b259 | 259 | |
c8a1bdc4 HWN |
260 | |
261 | SCM_API unsigned long scm_gc_cells_swept; | |
262 | SCM_API unsigned long scm_gc_cells_collected; | |
33b001fd MV |
263 | SCM_API unsigned long scm_gc_malloc_collected; |
264 | SCM_API unsigned long scm_gc_ports_collected; | |
f2893a25 | 265 | SCM_API unsigned long scm_cells_allocated; |
c2cbcc57 HWN |
266 | SCM_API int scm_gc_cell_yield_percentage; |
267 | SCM_API int scm_gc_malloc_yield_percentage; | |
33b001fd MV |
268 | SCM_API unsigned long scm_mallocated; |
269 | SCM_API unsigned long scm_mtrigger; | |
270 | ||
c8a1bdc4 HWN |
271 | |
272 | ||
33b001fd MV |
273 | SCM_API SCM scm_after_gc_hook; |
274 | ||
275 | SCM_API scm_t_c_hook scm_before_gc_c_hook; | |
276 | SCM_API scm_t_c_hook scm_before_mark_c_hook; | |
277 | SCM_API scm_t_c_hook scm_before_sweep_c_hook; | |
278 | SCM_API scm_t_c_hook scm_after_sweep_c_hook; | |
279 | SCM_API scm_t_c_hook scm_after_gc_c_hook; | |
9b3e180c | 280 | |
bb2c57fa | 281 | #if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST) |
2e945bcc SJ |
282 | #if (SCM_ENABLE_DEPRECATED == 1) |
283 | SCM scm_map_free_list (void); | |
284 | #else | |
c8a1bdc4 HWN |
285 | #define scm_map_free_list deprecated |
286 | #define scm_free_list_length deprecated | |
bb2c57fa | 287 | #endif |
2e945bcc | 288 | #endif |
c8a1bdc4 HWN |
289 | |
290 | #if (SCM_ENABLE_DEPRECATED == 1) && defined (GUILE_DEBUG_FREELIST) | |
33b001fd | 291 | SCM_API SCM scm_gc_set_debug_check_freelist_x (SCM flag); |
88256b2e | 292 | #endif |
0f2d19dd | 293 | \f |
0f2d19dd | 294 | |
61045190 | 295 | #if (SCM_DEBUG_CELL_ACCESSES == 1) |
33b001fd | 296 | SCM_API void scm_assert_cell_valid (SCM); |
61045190 | 297 | #endif |
c8a1bdc4 HWN |
298 | |
299 | SCM_API SCM scm_set_debug_cell_accesses_x (SCM flag); | |
300 | ||
301 | ||
33b001fd | 302 | SCM_API SCM scm_object_address (SCM obj); |
33b001fd | 303 | SCM_API SCM scm_gc_stats (void); |
1367aa5e | 304 | SCM_API SCM scm_gc_live_object_stats (void); |
33b001fd | 305 | SCM_API SCM scm_gc (void); |
c8a1bdc4 HWN |
306 | SCM_API void scm_gc_for_alloc (struct scm_t_cell_type_statistics *freelist); |
307 | SCM_API SCM scm_gc_for_newcell (struct scm_t_cell_type_statistics *master, SCM *freelist); | |
33b001fd MV |
308 | SCM_API void scm_igc (const char *what); |
309 | SCM_API void scm_gc_mark (SCM p); | |
310 | SCM_API void scm_gc_mark_dependencies (SCM p); | |
311 | SCM_API void scm_mark_locations (SCM_STACKITEM x[], unsigned long n); | |
c8a1bdc4 | 312 | SCM_API int scm_in_heap_p (SCM value); |
33b001fd | 313 | SCM_API void scm_gc_sweep (void); |
4c9419ac MV |
314 | |
315 | SCM_API void *scm_malloc (size_t size); | |
ba1b2226 | 316 | SCM_API void *scm_calloc (size_t size); |
4c9419ac MV |
317 | SCM_API void *scm_realloc (void *mem, size_t size); |
318 | SCM_API char *scm_strdup (const char *str); | |
319 | SCM_API char *scm_strndup (const char *str, size_t n); | |
320 | SCM_API void scm_gc_register_collectable_memory (void *mem, size_t size, | |
321 | const char *what); | |
322 | SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size, | |
323 | const char *what); | |
39e8f371 | 324 | SCM_API void *scm_gc_calloc (size_t size, const char *what); |
4c9419ac MV |
325 | SCM_API void *scm_gc_malloc (size_t size, const char *what); |
326 | SCM_API void *scm_gc_realloc (void *mem, size_t old_size, | |
327 | size_t new_size, const char *what); | |
328 | SCM_API void scm_gc_free (void *mem, size_t size, const char *what); | |
329 | SCM_API char *scm_gc_strdup (const char *str, const char *what); | |
330 | SCM_API char *scm_gc_strndup (const char *str, size_t n, const char *what); | |
331 | ||
33b001fd MV |
332 | SCM_API void scm_remember_upto_here_1 (SCM obj); |
333 | SCM_API void scm_remember_upto_here_2 (SCM obj1, SCM obj2); | |
334 | SCM_API void scm_remember_upto_here (SCM obj1, ...); | |
aca3618f | 335 | |
c1ffdc6a KR |
336 | /* In GCC we can force a reference to an SCM by making it an input to an |
337 | empty asm. This avoids the code size and slowdown of an actual function | |
338 | call. Unfortunately there doesn't seem to be any way to do the varargs | |
339 | scm_remember_upto_here like this. | |
340 | ||
341 | __volatile__ ensures nothing will be moved across the asm, and it won't | |
342 | be optimized away (or only if proved unreachable). Constraint "g" can be | |
343 | used on all processors and allows any memory or general register (or | |
344 | immediate) operand. The actual asm syntax doesn't matter, we don't want | |
345 | to use it, just ensure the operand is still alive. See "Extended Asm" in | |
346 | the GCC manual for more. */ | |
aca3618f KR |
347 | |
348 | #ifdef __GNUC__ | |
349 | #define scm_remember_upto_here_1(x) \ | |
350 | do { \ | |
351 | __asm__ __volatile__ ("" : : "g" (x)); \ | |
352 | } while (0) | |
353 | #define scm_remember_upto_here_2(x, y) \ | |
354 | do { \ | |
355 | scm_remember_upto_here_1 (x); \ | |
356 | scm_remember_upto_here_1 (y); \ | |
357 | } while (0) | |
358 | #endif | |
359 | ||
33b001fd MV |
360 | SCM_API SCM scm_return_first (SCM elt, ...); |
361 | SCM_API int scm_return_first_int (int x, ...); | |
362 | SCM_API SCM scm_permanent_object (SCM obj); | |
363 | SCM_API SCM scm_gc_protect_object (SCM obj); | |
364 | SCM_API SCM scm_gc_unprotect_object (SCM obj); | |
365 | SCM_API void scm_gc_register_root (SCM *p); | |
366 | SCM_API void scm_gc_unregister_root (SCM *p); | |
367 | SCM_API void scm_gc_register_roots (SCM *b, unsigned long n); | |
368 | SCM_API void scm_gc_unregister_roots (SCM *b, unsigned long n); | |
c35738c1 | 369 | SCM_API void scm_storage_prehistory (void); |
33b001fd MV |
370 | SCM_API int scm_init_storage (void); |
371 | SCM_API void *scm_get_stack_base (void); | |
372 | SCM_API void scm_init_gc (void); | |
d1ca2c64 | 373 | |
d678e25c MV |
374 | #if SCM_ENABLE_DEPRECATED == 1 |
375 | ||
376 | SCM_API SCM scm_deprecated_newcell (void); | |
377 | SCM_API SCM scm_deprecated_newcell2 (void); | |
378 | ||
379 | #define SCM_NEWCELL(_into) \ | |
380 | do { _into = scm_deprecated_newcell (); } while (0) | |
381 | #define SCM_NEWCELL2(_into) \ | |
382 | do { _into = scm_deprecated_newcell2 (); } while (0) | |
383 | ||
539b08a4 MV |
384 | SCM_API void * scm_must_malloc (size_t len, const char *what); |
385 | SCM_API void * scm_must_realloc (void *where, | |
386 | size_t olen, size_t len, | |
387 | const char *what); | |
388 | SCM_API char *scm_must_strdup (const char *str); | |
389 | SCM_API char *scm_must_strndup (const char *str, size_t n); | |
390 | SCM_API void scm_done_malloc (long size); | |
391 | SCM_API void scm_done_free (long size); | |
392 | SCM_API void scm_must_free (void *obj); | |
393 | ||
d678e25c MV |
394 | #endif |
395 | ||
61045190 | 396 | #endif /* SCM_GC_H */ |
89e00824 ML |
397 | |
398 | /* | |
399 | Local Variables: | |
400 | c-file-style: "gnu" | |
401 | End: | |
402 | */ |