1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 04:40:29 +02:00
guile/test-suite/standalone/test-scm-with-guile.c
Ludovic Courtès ccf1ca4adf Update the thread stack base when `scm_with_guile' is invoked multiple times.
* NEWS: Update.

* libguile/threads.c (scm_i_init_thread_for_guile): When the thread is
  already guilified, update `t->base' so that it corresponds to the new
  stack base.  Bug report and patch by Linas Vepstas <linasvepstas@gmail.com>.

* test-suite/standalone/Makefile.am (test_scm_with_guile_CFLAGS,
  test_scm_with_guile_LDADD): New.
  (check_PROGRAMS, TESTS): Add `test-scm-with-guile'.
2008-11-14 00:36:58 +01:00

66 lines
2 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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 2.1 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;
}