test-smob-mark-race.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright 2016
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #if HAVE_CONFIG_H
  16. #include <config.h>
  17. #endif
  18. #undef NDEBUG
  19. #include <libguile.h>
  20. #include <assert.h>
  21. static SCM
  22. mark_smob (SCM smob)
  23. {
  24. assert (SCM_SMOB_DATA (smob) == 1);
  25. return SCM_BOOL_F;
  26. }
  27. static size_t
  28. finalize_smob (SCM smob)
  29. {
  30. assert (SCM_SMOB_DATA (smob) == 1);
  31. SCM_SET_SMOB_DATA (smob, 0);
  32. /* Allocate a bit in the hopes of triggering a new GC, making the
  33. marker race with the finalizer. */
  34. scm_cons (SCM_BOOL_F, SCM_BOOL_F);
  35. return 0;
  36. }
  37. static void
  38. tests (void *data, int argc, char **argv)
  39. {
  40. scm_t_bits tc16;
  41. int i;
  42. tc16 = scm_make_smob_type ("smob with finalizer", 0);
  43. scm_set_smob_mark (tc16, mark_smob);
  44. scm_set_smob_free (tc16, finalize_smob);
  45. for (i = 0; i < 1000 * 1000; i++)
  46. scm_new_smob (tc16, 1);
  47. }
  48. int
  49. main (int argc, char *argv[])
  50. {
  51. scm_boot_guile (argc, argv, tests, NULL);
  52. return 0;
  53. }