]> git.donarmstrong.com Git - lilypond.git/blob - guile18/libguile/stackchk.c
New upstream version 2.19.65
[lilypond.git] / guile18 / libguile / stackchk.c
1 /*      Copyright (C) 1995,1996,1997, 2000, 2001, 2006, 2008 Free Software Foundation, Inc.
2  * 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
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
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17
18
19 \f
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include "libguile/_scm.h"
25 #include "libguile/ports.h"
26 #include "libguile/root.h"
27 #include "libguile/threads.h"
28
29 #include "libguile/stackchk.h"
30 \f
31
32 /* {Stack Checking}
33  */
34
35 #ifdef STACK_CHECKING
36 int scm_stack_checking_enabled_p;
37
38 SCM_SYMBOL (scm_stack_overflow_key, "stack-overflow");
39
40 void
41 scm_report_stack_overflow ()
42 {
43   scm_stack_checking_enabled_p = 0;
44   scm_error (scm_stack_overflow_key,
45              NULL,
46              "Stack overflow",
47              SCM_BOOL_F,
48              SCM_BOOL_F);
49 }
50
51 #endif
52
53 long
54 scm_stack_size (SCM_STACKITEM *start)
55 {
56   SCM_STACKITEM stack;
57 #if SCM_STACK_GROWS_UP
58   return &stack - start;
59 #else
60   return start - &stack;
61 #endif /* SCM_STACK_GROWS_UP */
62 }
63
64
65 void 
66 scm_stack_report ()
67 {
68   SCM port = scm_current_error_port ();
69   SCM_STACKITEM stack;
70   scm_i_thread *thread = SCM_I_CURRENT_THREAD;
71
72   scm_uintprint ((scm_stack_size (thread->continuation_base) 
73                   * sizeof (SCM_STACKITEM)),
74                  16, port);
75   scm_puts (" of stack: 0x", port);
76   scm_uintprint ((scm_t_bits) thread->continuation_base, 16, port);
77   scm_puts (" - 0x", port);
78   scm_uintprint ((scm_t_bits) &stack, 16, port);
79   scm_puts ("\n", port);
80 }
81
82
83 SCM_DEFINE (scm_sys_get_stack_size, "%get-stack-size", 0, 0, 0,
84             (),
85             "Return the current thread's C stack size (in Scheme objects).")
86 #define FUNC_NAME s_scm_sys_get_stack_size
87 {
88   return scm_from_long (scm_stack_size (SCM_I_CURRENT_THREAD->base));
89 }
90 #undef FUNC_NAME
91
92
93 void
94 scm_init_stackchk ()
95 {
96 #include "libguile/stackchk.x"
97 }
98
99 /*
100   Local Variables:
101   c-file-style: "gnu"
102   End:
103 */