Fix infinite loop in expander
[bpt/guile.git] / libguile / fluids.c
CommitLineData
b8d8f8b9
MW
1/* Copyright (C) 1996,1997,2000,2001, 2004, 2006, 2007, 2008, 2009, 2010,
2 * 2011, 2012, 2013 Free Software Foundation, Inc.
9482a297 3 *
73be1d9e 4 * This library is free software; you can redistribute it and/or
53befeb7
NJ
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
9482a297 8 *
53befeb7
NJ
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
9482a297 13 *
73be1d9e
MV
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
53befeb7
NJ
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
73be1d9e 18 */
9482a297 19
dbb605f5
LC
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
9de87eea
MV
24#include <stdio.h>
25#include <string.h>
1bbd0b84 26
a0599745
MD
27#include "libguile/_scm.h"
28#include "libguile/print.h"
a0599745
MD
29#include "libguile/dynwind.h"
30#include "libguile/fluids.h"
31#include "libguile/alist.h"
32#include "libguile/eval.h"
33#include "libguile/ports.h"
143e0902 34#include "libguile/deprecation.h"
a0599745 35#include "libguile/validate.h"
bd5a75dc 36#include "libguile/bdw-gc.h"
9482a297 37
bd5a75dc
LC
38/* Number of additional slots to allocate when ALLOCATED_FLUIDS is full. */
39#define FLUID_GROW 128
9de87eea 40
bd5a75dc
LC
41/* Vector of allocated fluids indexed by fluid numbers. Access is protected by
42 FLUID_ADMIN_MUTEX. */
43static void **allocated_fluids = NULL;
44static size_t allocated_fluids_len = 0;
9482a297 45
9de87eea
MV
46static scm_i_pthread_mutex_t fluid_admin_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER;
47
6f8d7b12 48#define IS_FLUID(x) SCM_FLUID_P (x)
5ef71027 49#define FLUID_NUM(x) SCM_I_FLUID_NUM (x)
9de87eea 50
5ef71027
AW
51#define IS_DYNAMIC_STATE(x) SCM_I_DYNAMIC_STATE_P (x)
52#define DYNAMIC_STATE_FLUIDS(x) SCM_I_DYNAMIC_STATE_FLUIDS (x)
9ea31741 53#define SET_DYNAMIC_STATE_FLUIDS(x, y) SCM_SET_CELL_WORD_1 ((x), (SCM_UNPACK (y)))
9de87eea 54
9de87eea 55
8b039053 56\f
bd5a75dc
LC
57/* Grow STATE so that it can hold up to ALLOCATED_FLUIDS_LEN fluids. This may
58 be more than necessary since ALLOCATED_FLUIDS is sparse and the current
59 thread may not access all the fluids anyway. Memory usage could be improved
60 by using a 2-level array as is done in glibc for pthread keys (TODO). */
9482a297 61static void
8b039053 62grow_dynamic_state (SCM state)
9de87eea 63{
8b039053
LC
64 SCM new_fluids;
65 SCM old_fluids = DYNAMIC_STATE_FLUIDS (state);
bd5a75dc 66 size_t i, len, old_len = SCM_SIMPLE_VECTOR_LENGTH (old_fluids);
9de87eea 67
bd5a75dc
LC
68 /* Assume the assignment below is atomic. */
69 len = allocated_fluids_len;
9de87eea 70
aafb4ed7 71 new_fluids = scm_c_make_vector (len, SCM_UNDEFINED);
8b039053
LC
72
73 for (i = 0; i < old_len; i++)
74 SCM_SIMPLE_VECTOR_SET (new_fluids, i,
75 SCM_SIMPLE_VECTOR_REF (old_fluids, i));
76 SET_DYNAMIC_STATE_FLUIDS (state, new_fluids);
9482a297
MV
77}
78
9ea31741
AW
79void
80scm_i_fluid_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
9482a297 81{
0607ebbf 82 scm_puts_unlocked ("#<fluid ", port);
9de87eea 83 scm_intprint ((int) FLUID_NUM (exp), 10, port);
0607ebbf 84 scm_putc_unlocked ('>', port);
9482a297
MV
85}
86
45cf2428
AW
87void
88scm_i_dynamic_state_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
89{
0607ebbf 90 scm_puts_unlocked ("#<dynamic-state ", port);
45cf2428 91 scm_intprint (SCM_UNPACK (exp), 16, port);
0607ebbf 92 scm_putc_unlocked ('>', port);
45cf2428
AW
93}
94
bd5a75dc
LC
95\f
96/* Return a new fluid. */
97static SCM
aafb4ed7 98new_fluid (SCM init)
9482a297 99{
bd5a75dc
LC
100 SCM fluid;
101 size_t trial, n;
102
aafb4ed7
AW
103 /* Fluids hold the type tag and the fluid number in the first word,
104 and the default value in the second word. */
105 fluid = scm_cell (scm_tc7_fluid, SCM_UNPACK (init));
bd5a75dc 106 SCM_SET_CELL_TYPE (fluid, scm_tc7_fluid);
9de87eea 107
661ae7ab
MV
108 scm_dynwind_begin (0);
109 scm_i_dynwind_pthread_mutex_lock (&fluid_admin_mutex);
9de87eea 110
bd5a75dc 111 for (trial = 0; trial < 2; trial++)
9de87eea 112 {
bd5a75dc 113 /* Look for a free fluid number. */
9de87eea 114 for (n = 0; n < allocated_fluids_len; n++)
bd5a75dc
LC
115 /* TODO: Use `__sync_bool_compare_and_swap' where available. */
116 if (allocated_fluids[n] == NULL)
9de87eea 117 break;
bd5a75dc 118
064d2409 119 if (trial == 0 && n >= allocated_fluids_len && allocated_fluids_len)
bd5a75dc
LC
120 /* All fluid numbers are in use. Run a GC and retry. Explicitly
121 running the GC is costly and bad-style. We only do this because
122 dynamic state fluid vectors would grow unreasonably if fluid numbers
123 weren't reused. */
124 scm_i_gc ("fluids");
9de87eea 125 }
bd5a75dc
LC
126
127 if (n >= allocated_fluids_len)
9de87eea 128 {
8b039053 129 /* Grow the vector of allocated fluids. */
bd5a75dc
LC
130 void **new_allocated_fluids =
131 scm_gc_malloc_pointerless ((allocated_fluids_len + FLUID_GROW)
132 * sizeof (*allocated_fluids),
133 "allocated fluids");
9de87eea
MV
134
135 /* Copy over old values and initialize rest. GC can not run
136 during these two operations since there is no safe point in
bd5a75dc
LC
137 them. */
138 memcpy (new_allocated_fluids, allocated_fluids,
139 allocated_fluids_len * sizeof (*allocated_fluids));
140 memset (new_allocated_fluids + allocated_fluids_len, 0,
141 FLUID_GROW * sizeof (*allocated_fluids));
9de87eea 142 n = allocated_fluids_len;
d3075c52 143
8b039053
LC
144 /* Update the vector of allocated fluids. Dynamic states will
145 eventually be lazily grown to accomodate the new value of
146 ALLOCATED_FLUIDS_LEN in `fluid-ref' and `fluid-set!'. */
9de87eea
MV
147 allocated_fluids = new_allocated_fluids;
148 allocated_fluids_len += FLUID_GROW;
9de87eea 149 }
bd5a75dc 150
21041372 151 allocated_fluids[n] = SCM_UNPACK_POINTER (fluid);
aafb4ed7 152 SCM_SET_CELL_WORD_0 (fluid, (scm_tc7_fluid | (n << 8)));
bd5a75dc
LC
153
154 GC_GENERAL_REGISTER_DISAPPEARING_LINK (&allocated_fluids[n],
0aed71aa 155 SCM2PTR (fluid));
bd5a75dc 156
661ae7ab 157 scm_dynwind_end ();
0b77014f
AW
158
159 /* Now null out values. We could (and probably should) do this when
160 the fluid is collected instead of now. */
aafb4ed7 161 scm_i_reset_fluid (n);
0b77014f 162
bd5a75dc 163 return fluid;
9482a297
MV
164}
165
aafb4ed7
AW
166SCM
167scm_make_fluid (void)
168{
169 return new_fluid (SCM_BOOL_F);
170}
171
172SCM_DEFINE (scm_make_fluid_with_default, "make-fluid", 0, 1, 0,
173 (SCM dflt),
f43622a2
AW
174 "Return a newly created fluid, whose initial value is @var{dflt},\n"
175 "or @code{#f} if @var{dflt} is not given.\n"
9de87eea
MV
176 "Fluids are objects that can hold one\n"
177 "value per dynamic state. That is, modifications to this value are\n"
178 "only visible to code that executes with the same dynamic state as\n"
179 "the modifying code. When a new dynamic state is constructed, it\n"
180 "inherits the values from its parent. Because each thread normally executes\n"
181 "with its own dynamic state, you can use fluids for thread local storage.")
aafb4ed7 182#define FUNC_NAME s_scm_make_fluid_with_default
9482a297 183{
aafb4ed7 184 return new_fluid (SCM_UNBNDP (dflt) ? SCM_BOOL_F : dflt);
9482a297 185}
1bbd0b84 186#undef FUNC_NAME
9482a297 187
e01163b5 188SCM_DEFINE (scm_make_unbound_fluid, "make-unbound-fluid", 0, 0, 0,
ef94624e 189 (),
e01163b5
AW
190 "Make a fluid that is initially unbound.")
191#define FUNC_NAME s_scm_make_unbound_fluid
ef94624e 192{
aafb4ed7 193 return new_fluid (SCM_UNDEFINED);
ef94624e
BT
194}
195#undef FUNC_NAME
196
a1ec6916 197SCM_DEFINE (scm_fluid_p, "fluid?", 1, 0, 0,
ed4d7cee 198 (SCM obj),
1e6808ea
MG
199 "Return @code{#t} iff @var{obj} is a fluid; otherwise, return\n"
200 "@code{#f}.")
1bbd0b84 201#define FUNC_NAME s_scm_fluid_p
b3460a50 202{
9de87eea 203 return scm_from_bool (IS_FLUID (obj));
b3460a50 204}
1bbd0b84 205#undef FUNC_NAME
b3460a50 206
9de87eea
MV
207int
208scm_is_fluid (SCM obj)
209{
210 return IS_FLUID (obj);
211}
212
ef94624e
BT
213/* Does not check type of `fluid'! */
214static SCM
215fluid_ref (SCM fluid)
9482a297 216{
aafb4ed7 217 SCM ret;
9de87eea 218 SCM fluids = DYNAMIC_STATE_FLUIDS (SCM_I_CURRENT_THREAD->dynamic_state);
9482a297 219
8b039053
LC
220 if (SCM_UNLIKELY (FLUID_NUM (fluid) >= SCM_SIMPLE_VECTOR_LENGTH (fluids)))
221 {
8b039053
LC
222 /* Lazily grow the current thread's dynamic state. */
223 grow_dynamic_state (SCM_I_CURRENT_THREAD->dynamic_state);
224
225 fluids = DYNAMIC_STATE_FLUIDS (SCM_I_CURRENT_THREAD->dynamic_state);
226 }
227
aafb4ed7
AW
228 ret = SCM_SIMPLE_VECTOR_REF (fluids, FLUID_NUM (fluid));
229 if (SCM_UNBNDP (ret))
230 return SCM_I_FLUID_DEFAULT (fluid);
231 else
232 return ret;
9482a297 233}
ef94624e
BT
234
235SCM_DEFINE (scm_fluid_ref, "fluid-ref", 1, 0, 0,
236 (SCM fluid),
237 "Return the value associated with @var{fluid} in the current\n"
238 "dynamic root. If @var{fluid} has not been set, then return\n"
239 "@code{#f}.")
240#define FUNC_NAME s_scm_fluid_ref
241{
242 SCM val;
243 SCM_VALIDATE_FLUID (1, fluid);
244 val = fluid_ref (fluid);
245 if (SCM_UNBNDP (val))
246 SCM_MISC_ERROR ("unbound fluid: ~S",
247 scm_list_1 (fluid));
248 return val;
249}
1bbd0b84 250#undef FUNC_NAME
9482a297 251
a1ec6916 252SCM_DEFINE (scm_fluid_set_x, "fluid-set!", 2, 0, 0,
ed4d7cee
GB
253 (SCM fluid, SCM value),
254 "Set the value associated with @var{fluid} in the current dynamic root.")
1bbd0b84 255#define FUNC_NAME s_scm_fluid_set_x
9482a297 256{
9de87eea 257 SCM fluids = DYNAMIC_STATE_FLUIDS (SCM_I_CURRENT_THREAD->dynamic_state);
9482a297 258
ed4d7cee 259 SCM_VALIDATE_FLUID (1, fluid);
8b039053
LC
260
261 if (SCM_UNLIKELY (FLUID_NUM (fluid) >= SCM_SIMPLE_VECTOR_LENGTH (fluids)))
262 {
8b039053
LC
263 /* Lazily grow the current thread's dynamic state. */
264 grow_dynamic_state (SCM_I_CURRENT_THREAD->dynamic_state);
265
266 fluids = DYNAMIC_STATE_FLUIDS (SCM_I_CURRENT_THREAD->dynamic_state);
267 }
268
9de87eea 269 SCM_SIMPLE_VECTOR_SET (fluids, FLUID_NUM (fluid), value);
86f9f9ae 270 return SCM_UNSPECIFIED;
9482a297 271}
1bbd0b84 272#undef FUNC_NAME
9482a297 273
ef94624e
BT
274SCM_DEFINE (scm_fluid_unset_x, "fluid-unset!", 1, 0, 0,
275 (SCM fluid),
276 "Unset the value associated with @var{fluid}.")
277#define FUNC_NAME s_scm_fluid_unset_x
278{
aafb4ed7
AW
279 /* FIXME: really unset the default value, too? The current test
280 suite demands it, but I would prefer not to. */
281 SCM_SET_CELL_OBJECT_1 (fluid, SCM_UNDEFINED);
ef94624e
BT
282 return scm_fluid_set_x (fluid, SCM_UNDEFINED);
283}
284#undef FUNC_NAME
285
286SCM_DEFINE (scm_fluid_bound_p, "fluid-bound?", 1, 0, 0,
287 (SCM fluid),
288 "Return @code{#t} iff @var{fluid} is bound to a value.\n"
289 "Throw an error if @var{fluid} is not a fluid.")
290#define FUNC_NAME s_scm_fluid_bound_p
291{
292 SCM val;
293 SCM_VALIDATE_FLUID (1, fluid);
294 val = fluid_ref (fluid);
295 return scm_from_bool (! (SCM_UNBNDP (val)));
296}
297#undef FUNC_NAME
298
bb0229b5
AW
299static SCM
300apply_thunk (void *thunk)
b3460a50 301{
bb0229b5
AW
302 return scm_call_0 (SCM_PACK (thunk));
303}
304
bb0229b5 305void
98eaef1b 306scm_swap_fluid (SCM fluid, SCM value_box, SCM dynstate)
bb0229b5 307{
98eaef1b
AW
308 SCM fluid_vector, tmp;
309 size_t fluid_num;
b3460a50 310
98eaef1b 311 fluid_num = FLUID_NUM (fluid);
b3460a50 312
98eaef1b 313 fluid_vector = DYNAMIC_STATE_FLUIDS (dynstate);
b3460a50 314
98eaef1b 315 if (SCM_UNLIKELY (fluid_num >= SCM_SIMPLE_VECTOR_LENGTH (fluid_vector)))
bb0229b5 316 {
bb0229b5
AW
317 /* Lazily grow the current thread's dynamic state. */
318 grow_dynamic_state (dynstate);
319
9ede013f 320 fluid_vector = DYNAMIC_STATE_FLUIDS (dynstate);
bb0229b5 321 }
1bbd0b84 322
98eaef1b
AW
323 tmp = SCM_SIMPLE_VECTOR_REF (fluid_vector, fluid_num);
324 SCM_SIMPLE_VECTOR_SET (fluid_vector, fluid_num, SCM_VARIABLE_REF (value_box));
325 SCM_VARIABLE_SET (value_box, tmp);
bb0229b5
AW
326}
327
a1ec6916 328SCM_DEFINE (scm_with_fluids, "with-fluids*", 3, 0, 0,
ed4d7cee
GB
329 (SCM fluids, SCM values, SCM thunk),
330 "Set @var{fluids} to @var{values} temporary, and call @var{thunk}.\n"
331 "@var{fluids} must be a list of fluids and @var{values} must be the same\n"
332 "number of their values to be applied. Each substitution is done\n"
333 "one after another. @var{thunk} must be a procedure with no argument.")
1bbd0b84
GB
334#define FUNC_NAME s_scm_with_fluids
335{
bebd3fba
MV
336 return scm_c_with_fluids (fluids, values,
337 apply_thunk, (void *) SCM_UNPACK (thunk));
1bbd0b84
GB
338}
339#undef FUNC_NAME
b3460a50
MV
340
341SCM
143e0902
MV
342scm_c_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
343#define FUNC_NAME "scm_c_with_fluids"
b3460a50 344{
9ede013f 345 SCM ans;
bb0229b5 346 long flen, vlen, i;
9ede013f 347 scm_i_thread *thread = SCM_I_CURRENT_THREAD;
b3460a50 348
c1bfcf60 349 SCM_VALIDATE_LIST_COPYLEN (1, fluids, flen);
ed4d7cee 350 SCM_VALIDATE_LIST_COPYLEN (2, values, vlen);
b3460a50 351 if (flen != vlen)
ed4d7cee 352 scm_out_of_range (s_scm_with_fluids, values);
b3460a50 353
bb0229b5
AW
354 for (i = 0; i < flen; i++)
355 {
98eaef1b
AW
356 scm_dynstack_push_fluid (&thread->dynstack,
357 SCM_CAR (fluids), SCM_CAR (values),
358 thread->dynamic_state);
bb0229b5 359 fluids = SCM_CDR (fluids);
bb0229b5
AW
360 values = SCM_CDR (values);
361 }
362
b3460a50 363 ans = cproc (cdata);
98eaef1b
AW
364
365 for (i = 0; i < flen; i++)
366 scm_dynstack_unwind_fluid (&thread->dynstack, thread->dynamic_state);
bb0229b5 367
b3460a50
MV
368 return ans;
369}
c1bfcf60 370#undef FUNC_NAME
b3460a50 371
c32b7c4c
AW
372SCM
373scm_with_fluid (SCM fluid, SCM value, SCM thunk)
bebd3fba
MV
374{
375 return scm_c_with_fluid (fluid, value,
376 apply_thunk, (void *) SCM_UNPACK (thunk));
377}
bebd3fba 378
143e0902
MV
379SCM
380scm_c_with_fluid (SCM fluid, SCM value, SCM (*cproc) (), void *cdata)
381#define FUNC_NAME "scm_c_with_fluid"
382{
9ede013f
AW
383 SCM ans;
384 scm_i_thread *thread = SCM_I_CURRENT_THREAD;
bebd3fba 385
98eaef1b
AW
386 scm_dynstack_push_fluid (&thread->dynstack, fluid, value,
387 thread->dynamic_state);
bebd3fba 388 ans = cproc (cdata);
98eaef1b 389 scm_dynstack_unwind_fluid (&thread->dynstack, thread->dynamic_state);
bb0229b5 390
bebd3fba 391 return ans;
143e0902
MV
392}
393#undef FUNC_NAME
b3460a50 394
ef20bf70
MV
395static void
396swap_fluid (SCM data)
397{
398 SCM f = SCM_CAR (data);
ef94624e 399 SCM t = fluid_ref (f);
ef20bf70
MV
400 scm_fluid_set_x (f, SCM_CDR (data));
401 SCM_SETCDR (data, t);
402}
403
404void
661ae7ab 405scm_dynwind_fluid (SCM fluid, SCM value)
ef20bf70
MV
406{
407 SCM data = scm_cons (fluid, value);
661ae7ab
MV
408 scm_dynwind_rewind_handler_with_scm (swap_fluid, data, SCM_F_WIND_EXPLICITLY);
409 scm_dynwind_unwind_handler_with_scm (swap_fluid, data, SCM_F_WIND_EXPLICITLY);
ef20bf70
MV
410}
411
9de87eea
MV
412SCM
413scm_i_make_initial_dynamic_state ()
414{
415 SCM fluids = scm_c_make_vector (allocated_fluids_len, SCM_BOOL_F);
9ea31741 416 return scm_cell (scm_tc7_dynamic_state, SCM_UNPACK (fluids));
9de87eea
MV
417}
418
419SCM_DEFINE (scm_make_dynamic_state, "make-dynamic-state", 0, 1, 0,
420 (SCM parent),
421 "Return a copy of the dynamic state object @var{parent}\n"
422 "or of the current dynamic state when @var{parent} is omitted.")
423#define FUNC_NAME s_scm_make_dynamic_state
424{
9ea31741 425 SCM fluids;
9de87eea
MV
426
427 if (SCM_UNBNDP (parent))
428 parent = scm_current_dynamic_state ();
429
9ea31741 430 SCM_ASSERT (IS_DYNAMIC_STATE (parent), parent, SCM_ARG1, FUNC_NAME);
9de87eea 431 fluids = scm_vector_copy (DYNAMIC_STATE_FLUIDS (parent));
9ea31741 432 return scm_cell (scm_tc7_dynamic_state, SCM_UNPACK (fluids));
9de87eea
MV
433}
434#undef FUNC_NAME
435
436SCM_DEFINE (scm_dynamic_state_p, "dynamic-state?", 1, 0, 0,
437 (SCM obj),
438 "Return @code{#t} if @var{obj} is a dynamic state object;\n"
439 "return @code{#f} otherwise")
440#define FUNC_NAME s_scm_dynamic_state_p
441{
442 return scm_from_bool (IS_DYNAMIC_STATE (obj));
443}
444#undef FUNC_NAME
445
446int
447scm_is_dynamic_state (SCM obj)
448{
449 return IS_DYNAMIC_STATE (obj);
450}
451
452SCM_DEFINE (scm_current_dynamic_state, "current-dynamic-state", 0, 0, 0,
453 (),
454 "Return the current dynamic state object.")
455#define FUNC_NAME s_scm_current_dynamic_state
456{
457 return SCM_I_CURRENT_THREAD->dynamic_state;
458}
459#undef FUNC_NAME
460
461SCM_DEFINE (scm_set_current_dynamic_state, "set-current-dynamic-state", 1,0,0,
462 (SCM state),
463 "Set the current dynamic state object to @var{state}\n"
464 "and return the previous current dynamic state object.")
465#define FUNC_NAME s_scm_set_current_dynamic_state
466{
467 scm_i_thread *t = SCM_I_CURRENT_THREAD;
468 SCM old = t->dynamic_state;
9ea31741 469 SCM_ASSERT (IS_DYNAMIC_STATE (state), state, SCM_ARG1, FUNC_NAME);
9de87eea
MV
470 t->dynamic_state = state;
471 return old;
472}
473#undef FUNC_NAME
474
475static void
476swap_dynamic_state (SCM loc)
477{
478 SCM_SETCAR (loc, scm_set_current_dynamic_state (SCM_CAR (loc)));
479}
480
481void
661ae7ab 482scm_dynwind_current_dynamic_state (SCM state)
9de87eea
MV
483{
484 SCM loc = scm_cons (state, SCM_EOL);
9ea31741 485 SCM_ASSERT (IS_DYNAMIC_STATE (state), state, SCM_ARG1, NULL);
661ae7ab 486 scm_dynwind_rewind_handler_with_scm (swap_dynamic_state, loc,
9de87eea 487 SCM_F_WIND_EXPLICITLY);
661ae7ab 488 scm_dynwind_unwind_handler_with_scm (swap_dynamic_state, loc,
9de87eea
MV
489 SCM_F_WIND_EXPLICITLY);
490}
491
492void *
493scm_c_with_dynamic_state (SCM state, void *(*func)(void *), void *data)
494{
495 void *result;
661ae7ab
MV
496 scm_dynwind_begin (SCM_F_DYNWIND_REWINDABLE);
497 scm_dynwind_current_dynamic_state (state);
9de87eea 498 result = func (data);
661ae7ab 499 scm_dynwind_end ();
9de87eea
MV
500 return result;
501}
502
503SCM_DEFINE (scm_with_dynamic_state, "with-dynamic-state", 2, 0, 0,
504 (SCM state, SCM proc),
505 "Call @var{proc} while @var{state} is the current dynamic\n"
506 "state object.")
507#define FUNC_NAME s_scm_with_dynamic_state
508{
509 SCM result;
661ae7ab
MV
510 scm_dynwind_begin (SCM_F_DYNWIND_REWINDABLE);
511 scm_dynwind_current_dynamic_state (state);
9de87eea 512 result = scm_call_0 (proc);
661ae7ab 513 scm_dynwind_end ();
9de87eea
MV
514 return result;
515}
516#undef FUNC_NAME
517
9de87eea 518
9482a297
MV
519void
520scm_init_fluids ()
521{
a0599745 522#include "libguile/fluids.x"
9482a297 523}
89e00824
ML
524
525/*
526 Local Variables:
527 c-file-style: "gnu"
528 End:
529*/