test-scm-with-guile.c 2.0 KB

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