From: Ivan Maidanski Date: Wed, 19 Sep 2018 06:57:51 +0000 (+0300) Subject: Test marking of finalizer closure object in disclaim_test X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a34781d5374f7724a046bec3d7a05ae1b596e318;p=gc Test marking of finalizer closure object in disclaim_test * tests/disclaim_test.c (PTR_HASH): New macro. * tests/disclaim_test.c (pair_dct): Change assertion condition about cd (it should be equal to the hash value of p). * tests/disclaim_test.c (pair_new): Replace static fc variable to local pfc one which is assigned a pointer to atomic object; set pfc->cd to the hash value of p. --- diff --git a/tests/disclaim_test.c b/tests/disclaim_test.c index ca092522..4febf7f7 100644 --- a/tests/disclaim_test.c +++ b/tests/disclaim_test.c @@ -104,12 +104,14 @@ int is_pair(pair_t p) return memcmp(p->magic, pair_magic, sizeof(p->magic)) == 0; } +#define PTR_HASH(p) (GC_HIDE_POINTER(p) >> 4) + void GC_CALLBACK pair_dct(void *obj, void *cd) { pair_t p = (pair_t)obj; int checksum; - my_assert(cd == NULL); + my_assert(cd == (void *)PTR_HASH(p)); /* Check that obj and its car and cdr are not trashed. */ # ifdef DEBUG_DISCLAIM_DESTRUCT printf("Destruct %p = (%p, %p)\n", @@ -135,13 +137,20 @@ pair_t pair_new(pair_t car, pair_t cdr) { pair_t p; - static const struct GC_finalizer_closure fc = { pair_dct, NULL }; + struct GC_finalizer_closure *pfc = + GC_NEW_ATOMIC(struct GC_finalizer_closure); - p = (pair_t)GC_finalized_malloc(sizeof(struct pair_s), &fc); + if (NULL == pfc) { + fprintf(stderr, "Out of memory!\n"); + exit(3); + } + pfc->proc = pair_dct; + p = (pair_t)GC_finalized_malloc(sizeof(struct pair_s), pfc); if (p == NULL) { fprintf(stderr, "Out of memory!\n"); exit(3); } + pfc->cd = (void *)PTR_HASH(p); my_assert(!is_pair(p)); my_assert(memeq(p, 0, sizeof(struct pair_s))); memcpy(p->magic, pair_magic, sizeof(p->magic));