Skip to content

Commit 88086a5

Browse files
committed
FEAT: preliminary support for system managed handles
1 parent d316cfc commit 88086a5

File tree

10 files changed

+273
-185
lines changed

10 files changed

+273
-185
lines changed

src/boot/sysobj.reb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ REBOL [
33
Title: "System object"
44
Rights: {
55
Copyright 2012 REBOL Technologies
6+
Copyright 2012-2021 Rebol Open Source Contributors
67
REBOL is a trademark of REBOL Technologies
78
}
89
License: {
@@ -29,6 +30,7 @@ catalog: object [
2930
datatypes: []
3031
actions: none
3132
natives: none
33+
handles: none
3234
errors: none
3335
; Reflectors are used on boot to create *-of functions
3436
reflectors: [

src/core/b-init.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2021 Rebol Open Source Contributors
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -611,10 +612,14 @@ extern const REBYTE Str_Banner[];
611612
value = Get_System(SYS_CATALOG, CAT_ACTIONS);
612613
Set_Block(value, Collect_Set_Words(VAL_BLK(&Boot_Block->actions)));
613614

614-
// Create system/catalog/nativess block:
615+
// Create system/catalog/natives block:
615616
value = Get_System(SYS_CATALOG, CAT_NATIVES);
616617
Set_Block(value, Collect_Set_Words(VAL_BLK(&Boot_Block->natives)));
617618

619+
// Create system/catalog/handles block
620+
// and register core handle types
621+
Init_Handles();
622+
618623
// Create system/codecs object:
619624
value = Get_System(SYS_CODECS, 0);
620625
frame = Make_Frame(10);

src/core/m-gc.c

+46-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2021 Rebol Open Source Contributors
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -252,7 +253,10 @@ static void Mark_Series(REBSER *series, REBCNT depth);
252253
case REB_TYPESET:
253254
break;
254255
case REB_HANDLE:
255-
if (IS_SERIES_HANDLE(val) && !HANDLE_GET_FLAG(val, HANDLE_RELEASABLE)) {
256+
if (IS_CONTEXT_HANDLE(val)) {
257+
MARK_HANDLE_CONTEXT(val);
258+
}
259+
else if (IS_SERIES_HANDLE(val) && !HANDLE_GET_FLAG(val, HANDLE_RELEASABLE)) {
256260
//printf("markserhandle %0xh val: %0xh %s \n", (void*)val, VAL_HANDLE(val), VAL_HANDLE_NAME(val));
257261
MARK_SERIES(VAL_HANDLE_DATA(val));
258262
}
@@ -503,10 +507,8 @@ static void Mark_Series(REBSER *series, REBCNT depth);
503507
for (seg = Mem_Pools[GOB_POOL].segs; seg; seg = seg->next) {
504508
gob = (REBGOB *) (seg + 1);
505509
for (n = Mem_Pools[GOB_POOL].units; n > 0; n--) {
506-
#ifdef MUNGWALL
507-
gob = (gob *) (((REBYTE *)s)+MUNG_SIZE);
510+
SKIP_WALL_TYPE(gob, REBGOB);
508511
MUNG_CHECK(GOB_POOL, gob, sizeof(*gob));
509-
#endif
510512
if (IS_GOB_USED(gob)) {
511513
if (IS_GOB_MARK(gob))
512514
UNMARK_GOB(gob);
@@ -516,9 +518,45 @@ static void Mark_Series(REBSER *series, REBCNT depth);
516518
}
517519
}
518520
gob++;
519-
#ifdef MUNGWALL
520-
gob = (gob *) (((REBYTE *)s)+MUNG_SIZE);
521-
#endif
521+
SKIP_WALL_TYPE(gob, REBGOB);
522+
}
523+
}
524+
525+
return count;
526+
}
527+
528+
529+
/***********************************************************************
530+
**
531+
*/ static REBCNT Sweep_Handles(void)
532+
/*
533+
** Free all unmarked handles.
534+
**
535+
** Scans all hobs in all segments that are part of the
536+
** HOB_POOL. Free hobs that have not been marked.
537+
**
538+
***********************************************************************/
539+
{
540+
REBSEG *seg;
541+
REBHOB *hob;
542+
REBCNT n;
543+
REBCNT count = 0;
544+
545+
for (seg = Mem_Pools[HOB_POOL].segs; seg; seg = seg->next) {
546+
hob = (REBHOB *) (seg + 1);
547+
for (n = Mem_Pools[HOB_POOL].units; n > 0; n--) {
548+
SKIP_WALL_TYPE(hob, REBHOB);
549+
MUNG_CHECK(HOB_POOL, hob, sizeof(*hob));
550+
if (IS_USED_HOB(hob)) {
551+
if (IS_MARK_HOB(hob))
552+
UNMARK_HOB(hob);
553+
else {
554+
Free_Hob(hob);
555+
count++;
556+
}
557+
}
558+
hob++;
559+
SKIP_WALL_TYPE(hob, REBHOB);
522560
}
523561
}
524562

@@ -597,6 +635,7 @@ static void Mark_Series(REBSER *series, REBCNT depth);
597635

598636
count = Sweep_Series();
599637
count += Sweep_Gobs();
638+
count += Sweep_Handles();
600639

601640
CHECK_MEMORY(4);
602641

src/core/m-pools.c

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2021 Rebol Open Source Contributors
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -104,6 +105,7 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
104105

105106
DEF_POOL(sizeof(REBSER), 4096), // Series headers
106107
DEF_POOL(sizeof(REBGOB), 128), // Gobs
108+
DEF_POOL(sizeof(REBHOB), 16), // Handle objects
107109
DEF_POOL(1, 1), // Just used for tracking main memory
108110
};
109111

@@ -597,6 +599,32 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
597599
}
598600

599601

602+
/***********************************************************************
603+
**
604+
*/ void Free_Hob(REBHOB *hob)
605+
/*
606+
** Free a hob, returning its memory for reuse.
607+
**
608+
***********************************************************************/
609+
{
610+
REBHSP spec;
611+
REBCNT idx = hob->index;
612+
613+
if( idx == 0 || !IS_USED_HOB(hob) || hob->data == NULL) return;
614+
615+
spec = PG_Handles[idx-1];
616+
//printf("HOB free mem: %0x\n", hob->data);
617+
618+
if (spec.free)
619+
spec.free(hob->data);
620+
621+
CLEAR(hob->data, spec.size);
622+
FREE_MEM(hob->data);
623+
UNUSE_HOB(hob);
624+
Free_Node(HOB_POOL, (REBNOD *)hob);
625+
}
626+
627+
600628
/***********************************************************************
601629
**
602630
*/ void Prop_Series(REBSER *newser, REBSER *oldser)

0 commit comments

Comments
 (0)