Skip to content

Commit 9c128dc

Browse files
committed
FEAT: added possibility to keep a track of a Rebol series in a handle's context (guarding this series from GC as long as the handle is referenced)
1 parent 931ddfb commit 9c128dc

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

make/rebol3.nest

+2-2
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.10.1
21+
version: 3.10.2
2222

2323
target-windows: [
2424
os: windows
@@ -691,7 +691,7 @@ include-view: [
691691
;- native tests:
692692
include-test-extension: [
693693
host-files: %os/host-ext-test.c
694-
config: TEST_EXTENSIONS ;@@TODO: rename!
694+
define: TEST_EXTENSIONS ;@@TODO: rename!
695695
]
696696

697697
;- native experimantal code:

src/core/c-handle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
hob = (REBHOB*)Make_Node(HOB_POOL);
9393
hob->data = MAKE_MEM(size);
9494
hob->index = idx;
95-
hob->flags = 0;
95+
hob->flags = HANDLE_CONTEXT;
9696
hob->sym = sym;
9797
CLEAR(hob->data, size);
9898
USE_HOB(hob);

src/core/m-gc.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181

8282
#include "sys-core.h"
8383
#include "reb-evtypes.h"
84+
//#include "stdio.h"
8485

8586
#ifdef REB_API
8687
extern REBOL_HOST_LIB *Host_Lib;
@@ -284,6 +285,7 @@ static void Mark_Series(REBSER *series, REBCNT depth);
284285
REBCNT len;
285286
REBSER *ser;
286287
REBVAL *val;
288+
REBHOB *hob;
287289

288290
ASSERT(series != 0, RP_NULL_MARK_SERIES);
289291

@@ -318,8 +320,13 @@ static void Mark_Series(REBSER *series, REBCNT depth);
318320
break;
319321
case REB_HANDLE:
320322
if (IS_CONTEXT_HANDLE(val)) {
321-
//printf("marked hob: %p %p\n", VAL_HANDLE_CTX(val), val);
323+
hob = VAL_HANDLE_CTX(val);
324+
//printf("marked hob: %p %p\n", hob, val);
322325
MARK_HANDLE_CONTEXT(val);
326+
if (hob->series) {
327+
//puts("marked hob's series");
328+
MARK_SERIES(hob->series);
329+
}
323330
}
324331
else if (IS_SERIES_HANDLE(val) && !HANDLE_GET_FLAG(val, HANDLE_RELEASABLE)) {
325332
//printf("markserhandle %0xh val: %0xh %s \n", (void*)val, VAL_HANDLE(val), VAL_HANDLE_NAME(val));

src/include/sys-value.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +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
6+
** Copyright 2012-2022 Rebol Open Source Contributors
77
** REBOL is a trademark of REBOL Technologies
88
**
99
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -1091,10 +1091,11 @@ typedef struct Reb_Handle_Spec {
10911091
} REBHSP;
10921092

10931093
typedef struct Reb_Handle_Context {
1094-
REBYTE *data;
1094+
REBYTE *data; // Pointer to raw data
10951095
REBCNT sym; // Index of the word's symbol. Used as a handle's type!
10961096
REBFLG flags:16; // Handle_Flags (HANDLE_CONTEXT_MARKED and HANDLE_CONTEXT_USED)
10971097
REBCNT index:16; // Index into Reb_Handle_Spec value
1098+
REBSER *series; // Optional pointer to Rebol series, which may be marked by GC
10981099
} REBHOB;
10991100

11001101
typedef struct Reb_Handle {

src/os/host-ext-test.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ char *RX_Spec =
8181
"vec0: command [{return vector size in bytes} v [vector!]]\n"
8282
"vec1: command [{return vector size in bytes (from object)} o [object!]]\n"
8383
"blk1: command [{print type ids of all values in a block} b [block!]]\n"
84-
"hob1: command [{creates XTEST handle}]"
84+
"hob1: command [{creates XTEST handle} bin [binary!]]"
8585
"hob2: command [{prints XTEST handle's data} hndl [handle!]]"
8686
"str0: command [{return a constructed string}]"
8787
"echo: command [{return the input value} value]"
@@ -90,7 +90,7 @@ char *RX_Spec =
9090
"i: make image! 2x2\n"
9191
"xtest: does [\n"
9292
"foreach blk [\n"
93-
"[x: hob1]"
93+
"[x: hob1 #{0102}]"
9494
"[hob2 x]"
9595
"[h: hndl1]\n"
9696
"[hndl2 h]\n"
@@ -266,7 +266,7 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
266266
case 11: //command [{creates a handle}]"
267267
{
268268
RXA_HANDLE(frm, 1) = (void*)42;
269-
RXA_HANDLE_TYPE(frm, 1) = AS_WORD("xtest");
269+
RXA_HANDLE_TYPE(frm, 1) = AS_WORD("xtest_plain");
270270
RXA_TYPE(frm, 1) = RXT_HANDLE;
271271
}
272272
break;
@@ -315,13 +315,20 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
315315
return RXR_UNSET;
316316
}
317317
break;
318-
case 16: //command [{creates XTEST handle}]"
318+
case 16: //command [{creates XTEST handle} bin [binary!]]"
319319
{
320320
REBHOB *hob = RL_MAKE_HANDLE_CONTEXT(Handle_XTest);
321+
REBSER *bin = RXA_SERIES(frm, 1);
321322
XTEST* data = (XTEST*)hob->data;
323+
324+
if (SERIES_REST(bin) < 1) {
325+
RL_EXPAND_SERIES(bin, SERIES_TAIL(bin), 1);
326+
}
327+
hob->series = bin;
328+
322329
printf("data=> id: %u num: %i\n", data->id, data->num);
323330
data->id = 1;
324-
data->num = -42;
331+
data->num = SERIES_TAIL(bin);
325332
printf("data=> id: %u num: %i\n", data->id, data->num);
326333

327334
RXA_HANDLE(frm, 1) = hob;
@@ -335,7 +342,9 @@ RXIEXT int RX_Call(int cmd, RXIFRM *frm, void *ctx) {
335342
REBHOB* hob = RXA_HANDLE(frm, 1);
336343
if (hob->sym == Handle_XTest) {
337344
XTEST* data = (XTEST*)hob->data;
338-
printf("data=> id: %u num: %i\n", data->id, data->num);
345+
REBSER *bin = hob->series;
346+
SERIES_DATA(bin)[0] = SERIES_DATA(bin)[0] + 1;
347+
printf("data=> id: %u num: %i b: %i\n", data->id, data->num, (u8)SERIES_DATA(bin)[0]);
339348
RXA_INT64(frm, 1) = data->num;
340349
RXA_TYPE(frm, 1) = RXT_INTEGER;
341350
}
@@ -374,6 +383,7 @@ void* releaseXTestContext(void* ctx) {
374383
printf("data=> id: %u num: %i\n", data->id, data->num);
375384
CLEARS(data);
376385
printf("data=> id: %u num: %i\n", data->id, data->num);
386+
return NULL;
377387
}
378388

379389
void Init_Ext_Test(void)

0 commit comments

Comments
 (0)