Remove incorrect comment in read.c
[bpt/guile.git] / libguile / stackchk.c
CommitLineData
138bf22d 1/* Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008, 2010 Free Software Foundation, Inc.
0f2d19dd 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
0f2d19dd 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
0f2d19dd 12 *
73be1d9e
MV
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
6e8d25a6 18
6e8d25a6 19
0f2d19dd 20\f
dbb605f5
LC
21#ifdef HAVE_CONFIG_H
22# include <config.h>
23#endif
0f2d19dd 24
a0599745
MD
25#include "libguile/_scm.h"
26#include "libguile/ports.h"
27#include "libguile/root.h"
d8b6e191 28#include "libguile/threads.h"
138bf22d 29#include "libguile/dynwind.h"
0f2d19dd 30
a0599745 31#include "libguile/stackchk.h"
0f2d19dd
JB
32\f
33
34/* {Stack Checking}
35 */
36
39f1ef51
MD
37#ifdef STACK_CHECKING
38int scm_stack_checking_enabled_p;
0f2d19dd 39
523f5266
GH
40SCM_SYMBOL (scm_stack_overflow_key, "stack-overflow");
41
138bf22d
AW
42static void
43reset_scm_stack_checking_enabled_p (void *arg)
44{
45 scm_stack_checking_enabled_p = (int)(scm_t_bits)arg;
46}
47
0f2d19dd
JB
48void
49scm_report_stack_overflow ()
50{
138bf22d
AW
51 scm_dynwind_begin (0); /* non-rewindable frame */
52 scm_dynwind_unwind_handler (reset_scm_stack_checking_enabled_p,
53 (void*)(scm_t_bits)scm_stack_checking_enabled_p,
54 SCM_F_WIND_EXPLICITLY);
55
39f1ef51 56 scm_stack_checking_enabled_p = 0;
138bf22d 57
01f61221 58 scm_error (scm_stack_overflow_key,
f5bf2977
GH
59 NULL,
60 "Stack overflow",
61 SCM_BOOL_F,
62 SCM_BOOL_F);
138bf22d
AW
63
64 /* not reached */
65 scm_dynwind_end ();
0f2d19dd
JB
66}
67
68#endif
1cc91f1b 69
1be6b49c 70long
6e8d25a6 71scm_stack_size (SCM_STACKITEM *start)
0f2d19dd
JB
72{
73 SCM_STACKITEM stack;
8dda3eea 74#if SCM_STACK_GROWS_UP
0f2d19dd
JB
75 return &stack - start;
76#else
77 return start - &stack;
8dda3eea 78#endif /* SCM_STACK_GROWS_UP */
0f2d19dd
JB
79}
80
1cc91f1b 81
0f2d19dd
JB
82void
83scm_stack_report ()
0f2d19dd 84{
9de87eea 85 SCM port = scm_current_error_port ();
0f2d19dd 86 SCM_STACKITEM stack;
9de87eea
MV
87 scm_i_thread *thread = SCM_I_CURRENT_THREAD;
88
89 scm_uintprint ((scm_stack_size (thread->continuation_base)
90 * sizeof (SCM_STACKITEM)),
91 16, port);
92 scm_puts (" of stack: 0x", port);
93 scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
94 scm_puts (" - 0x", port);
95 scm_uintprint ((scm_t_bits) &stack, 16, port);
96 scm_puts ("\n", port);
0f2d19dd
JB
97}
98
d8b6e191
NJ
99
100SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
101 (),
102 "Return the current thread's C stack size (in Scheme objects).")
103#define FUNC_NAME s_scm_sys_get_stack_size
104{
105 return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
106}
107#undef FUNC_NAME
108
109
0f2d19dd
JB
110void
111scm_init_stackchk ()
0f2d19dd 112{
a0599745 113#include "libguile/stackchk.x"
0f2d19dd 114}
89e00824
ML
115
116/*
117 Local Variables:
118 c-file-style: "gnu"
119 End:
120*/