staticrootslib.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* This test file is intended to be compiled into a DLL. */
  2. #ifndef GC_DEBUG
  3. # define GC_DEBUG
  4. #endif
  5. #include "gc.h"
  6. #ifndef GC_TEST_EXPORT_API
  7. # if defined(GC_VISIBILITY_HIDDEN_SET) \
  8. && !defined(__CEGCC__) && !defined(__CYGWIN__) && !defined(__MINGW32__)
  9. # define GC_TEST_EXPORT_API \
  10. extern __attribute__((__visibility__("default")))
  11. # else
  12. # define GC_TEST_EXPORT_API extern
  13. # endif
  14. #endif
  15. struct treenode {
  16. struct treenode *x;
  17. struct treenode *y;
  18. };
  19. static struct treenode *root[10] = { 0 };
  20. static struct treenode *root_nz[10] = { (struct treenode *)(GC_word)2 };
  21. #ifdef STATICROOTSLIB2
  22. # define libsrl_getpelem libsrl_getpelem2
  23. #else
  24. GC_TEST_EXPORT_API struct treenode * libsrl_mktree(int i)
  25. {
  26. struct treenode * r = GC_NEW(struct treenode);
  27. if (0 == i)
  28. return 0;
  29. if (1 == i)
  30. r = (struct treenode *)GC_MALLOC_ATOMIC(sizeof(struct treenode));
  31. if (r) {
  32. r -> x = libsrl_mktree(i-1);
  33. r -> y = libsrl_mktree(i-1);
  34. }
  35. return r;
  36. }
  37. GC_TEST_EXPORT_API void * libsrl_init(void)
  38. {
  39. # ifndef STATICROOTSLIB_INIT_IN_MAIN
  40. GC_INIT();
  41. # endif
  42. return GC_MALLOC(sizeof(struct treenode));
  43. }
  44. #endif /* !STATICROOTSLIB2 */
  45. GC_TEST_EXPORT_API struct treenode ** libsrl_getpelem(int i, int j)
  46. {
  47. return &((j & 1) != 0 ? root_nz : root)[i];
  48. }