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