test-smob-mark-race.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2016 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. #if HAVE_CONFIG_H
  19. #include <config.h>
  20. #endif
  21. #undef NDEBUG
  22. #include <libguile.h>
  23. #include <assert.h>
  24. static SCM
  25. mark_smob (SCM smob)
  26. {
  27. assert (SCM_SMOB_DATA (smob) == 1);
  28. return SCM_BOOL_F;
  29. }
  30. static size_t
  31. finalize_smob (SCM smob)
  32. {
  33. assert (SCM_SMOB_DATA (smob) == 1);
  34. SCM_SET_SMOB_DATA (smob, 0);
  35. /* Allocate a bit in the hopes of triggering a new GC, making the
  36. marker race with the finalizer. */
  37. scm_cons (SCM_BOOL_F, SCM_BOOL_F);
  38. return 0;
  39. }
  40. static void
  41. tests (void *data, int argc, char **argv)
  42. {
  43. scm_t_bits tc16;
  44. int i;
  45. tc16 = scm_make_smob_type ("smob with finalizer", 0);
  46. scm_set_smob_mark (tc16, mark_smob);
  47. scm_set_smob_free (tc16, finalize_smob);
  48. for (i = 0; i < 1000 * 1000; i++)
  49. scm_new_smob (tc16, 1);
  50. }
  51. int
  52. main (int argc, char *argv[])
  53. {
  54. scm_boot_guile (argc, argv, tests, NULL);
  55. return 0;
  56. }