summaryrefslogtreecommitdiff
path: root/test-suite/standalone/test-scm-with-guile.c
blob: a78458e6cc854b8831c4f587329b3a8e968c4935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (C) 2008 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */


/* Test whether `scm_with_guile ()' can be called several times from a given
   thread, but from a different stack depth.  Up to 1.8.5, `scm_with_guile
   ()' would not update the thread's `base' field, which would then confuse
   the GC.

   See http://lists.gnu.org/archive/html/guile-devel/2008-11/msg00037.html
   for a detailed report.  */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <libguile.h>

static void *
entry_point (void *arg)
{
  /* Invoke the GC.  If `THREAD->base' is incorrect, then Guile will just
     segfault somewhere in `scm_mark_locations ()'.  */
  scm_gc ();

  return NULL;
}

static void
go_deeper_into_the_stack (unsigned level)
{
  /* The assumption is that the compiler is not smart enough to optimize this
     out.  */
  if (level > 0)
    go_deeper_into_the_stack (level - 1);
  else
    scm_with_guile (entry_point, NULL);
}


int
main (int argc, char *argv[])
{
  /* Invoke `scm_with_guile ()' from someplace deep into the stack.  */
  go_deeper_into_the_stack (100);

  /* Invoke it from much higher into the stack.  This time, Guile is expected
     to update the `base' field of the current thread.  */
  scm_with_guile (entry_point, NULL);

  return 0;
}