Skip to content

Commit b048bd7

Browse files
committed
FEAT: allow to pass handle objects to external handle's free function and dispose handle objects before freeing any series
1 parent 2f79983 commit b048bd7

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12.1
1+
3.12.2

make/rebol3.nest

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ temp: %make/tmp/
1818
stack-size: 4194304 ;= 4MB (4 * 1024 * 1024)
1919
optimize: 2
2020

21-
version: 3.12.1
21+
version: 3.12.2
2222

2323
#if Linux? [ defines: TO_LINUX ]
2424
#if macOS? [ defines: TO_MACOS ]

src/core/m-gc.c

+2
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,8 @@ static void Mark_Series(REBSER *series, REBCNT depth);
814814
{
815815
REBCNT n;
816816
GC_Disabled = 0;
817+
// Dispose context handles first, because they may depend on other series!
818+
Dispose_Hobs();
817819
/* remove everything from GC_Infants (GC protection) */
818820
for (n = 0; n < MAX_SAFE_SERIES; n++) {
819821
GC_Infants[n] = NULL;

src/core/m-pools.c

+25-9
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,11 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
616616
if( !IS_USED_HOB(hob) || hob->data == NULL ) return;
617617

618618
spec = PG_Handles[idx];
619-
//printf("HOB free mem: %p\n", hob->data);
619+
//printf("HOB %p free mem: %p\n", hob, hob->data);
620620

621-
if (spec.free)
622-
spec.free(hob->data);
621+
if (spec.free) {
622+
spec.free(GET_FLAG(spec.flags, HANDLE_REQUIRES_HOB_ON_FREE) ? hob : hob->data);
623+
}
623624

624625
CLEAR(hob->data, spec.size);
625626
FREE_MEM(hob->data);
@@ -1008,19 +1009,17 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
10081009

10091010
/***********************************************************************
10101011
**
1011-
*/ void Dispose_Pools(void)
1012+
*/ void Dispose_Hobs(void)
10121013
/*
1013-
** Free memory pool array when application quits.
1014+
** Free all HOB pool segments
10141015
**
10151016
***********************************************************************/
10161017
{
10171018
REBSEG *seg, *next;
10181019
REBHOB *hob;
10191020
REBCNT n;
10201021

1021-
//Dump_Pools();
1022-
//Dump_Series_In_Pool(-1);
1023-
1022+
//puts("===== Dispose_Hobs ======");
10241023
// HOB at this moment does not use system series, so handle it separately
10251024
for (seg = Mem_Pools[HOB_POOL].segs; seg; seg = seg->next) {
10261025
hob = (REBHOB *) (seg + 1);
@@ -1031,8 +1030,25 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
10311030
SKIP_WALL_TYPE(hob, REBHOB);
10321031
}
10331032
}
1033+
}
1034+
1035+
/***********************************************************************
1036+
**
1037+
*/ void Dispose_Pools(void)
1038+
/*
1039+
** Free memory pool array when application quits.
1040+
**
1041+
***********************************************************************/
1042+
{
1043+
REBSEG *seg, *next;
1044+
REBHOB *hob;
1045+
REBCNT n;
1046+
1047+
//Dump_Pools();
1048+
//Dump_Series_In_Pool(-1);
1049+
//puts("===== Dispose_Pools ======");
10341050

1035-
// than release all series from all system pools
1051+
// Release all series from all system pools
10361052
FOREACH(n, SYSTEM_POOL) {
10371053
//printf(cs_cast("*** Dispose_Pools[%u] Has: %u free: %u\n"), n, Mem_Pools[n].has, Mem_Pools[n].free);
10381054
if (Mem_Pools[n].has == Mem_Pools[n].free) {

src/include/sys-value.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,13 @@ enum Handle_Flags {
10911091
HANDLE_CONTEXT_LOCKED = 1 << 5, // so Rebol will not GC the handle if C side still depends on it
10921092
};
10931093

1094+
enum Handle_Spec_Flags {
1095+
HANDLE_REQUIRES_HOB_ON_FREE = 1 << 0
1096+
}
1097+
10941098
typedef struct Reb_Handle_Spec {
10951099
REBCNT size;
1096-
REBFLG flags; // reserved for future
1100+
REBFLG flags;
10971101
REB_HANDLE_FREE_FUNC free;
10981102
REB_HANDLE_EVAL_PATH get_path;
10991103
REB_HANDLE_EVAL_PATH set_path;

0 commit comments

Comments
 (0)