Skip to content

Commit

Permalink
Test marking of finalizer closure object in disclaim_test
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ivmai committed Sep 19, 2018
1 parent 21312a0 commit a34781d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/disclaim_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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));
Expand Down

0 comments on commit a34781d

Please sign in to comment.