Skip to content

Commit

Permalink
FEAT: allow extension to mark handle's context on free call and so pr…
Browse files Browse the repository at this point in the history
…event it from releasing
  • Loading branch information
Oldes committed Sep 10, 2023
1 parent 2c45651 commit ca45cf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/core/m-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,7 @@ static void Mark_Series(REBSER *series, REBCNT depth);
if (IS_MARK_HOB(hob))
UNMARK_HOB(hob);
else {
Free_Hob(hob);
count++;
count += Free_Hob(hob);
}
}
hob++;
Expand Down
15 changes: 12 additions & 3 deletions src/core/m-pools.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =

/***********************************************************************
**
*/ void Free_Hob(REBHOB *hob)
*/ int Free_Hob(REBHOB *hob)
/*
** Free a hob, returning its memory for reuse.
**
Expand All @@ -613,19 +613,28 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
REBHSP spec;
REBCNT idx = hob->index;

if( !IS_USED_HOB(hob) || hob->data == NULL ) return;
if( !IS_USED_HOB(hob) || hob->data == NULL ) return 0;

spec = PG_Handles[idx];
//printf("HOB %p free mem: %p %i\n", hob, hob->data, spec.flags);

if (spec.free) {
spec.free(spec.flags & HANDLE_REQUIRES_HOB_ON_FREE ? (void*)hob : (void*)hob->data);
if (spec.flags & HANDLE_REQUIRES_HOB_ON_FREE) {
spec.free((void*)hob);
// Although there are no references, the extension may still need the handle.
// If extension marks the hob, do not free it now.
if (IS_MARK_HOB(hob)) return 0;
}
else {
spec.free(hob->data);
}
}

CLEAR(hob->data, spec.size);
FREE_MEM(hob->data);
UNUSE_HOB(hob);
Free_Node(HOB_POOL, (REBNOD *)hob);
return 1;
}


Expand Down

0 comments on commit ca45cf2

Please sign in to comment.