test-scm-with-guile.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 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. /* Test whether `scm_with_guile ()' can be called several times from a given
  18. thread, but from a different stack depth. Up to 1.8.5, `scm_with_guile
  19. ()' would not update the thread's `base' field, which would then confuse
  20. the GC.
  21. See http://lists.gnu.org/archive/html/guile-devel/2008-11/msg00037.html
  22. for a detailed report. */
  23. #ifdef HAVE_CONFIG_H
  24. # include <config.h>
  25. #endif
  26. #include <libguile.h>
  27. static void *
  28. entry_point (void *arg)
  29. {
  30. /* Invoke the GC. If `THREAD->base' is incorrect, then Guile will just
  31. segfault somewhere in `scm_mark_locations ()'. */
  32. scm_gc ();
  33. return NULL;
  34. }
  35. static void
  36. go_deeper_into_the_stack (unsigned level)
  37. {
  38. /* The assumption is that the compiler is not smart enough to optimize this
  39. out. */
  40. if (level > 0)
  41. go_deeper_into_the_stack (level - 1);
  42. else
  43. scm_with_guile (entry_point, NULL);
  44. }
  45. int
  46. main (int argc, char *argv[])
  47. {
  48. /* Invoke `scm_with_guile ()' from someplace deep into the stack. */
  49. go_deeper_into_the_stack (100);
  50. /* Invoke it from much higher into the stack. This time, Guile is expected
  51. to update the `base' field of the current thread. */
  52. scm_with_guile (entry_point, NULL);
  53. return 0;
  54. }