From d4878d9a45e50351670337d14506a68db8134fe4 Mon Sep 17 00:00:00 2001 From: Oldes Date: Wed, 6 Sep 2023 11:47:19 +0200 Subject: [PATCH] FEAT: allow custom `mold` callback for context handles to provide additional handle's info, if wanted --- src/core/s-mold.c | 12 ++++++++++++ src/include/sys-value.h | 3 ++- src/os/host-ext-test.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/core/s-mold.c b/src/core/s-mold.c index 4b15879a93..8bd1839126 100644 --- a/src/core/s-mold.c +++ b/src/core/s-mold.c @@ -558,6 +558,18 @@ STOID Mold_Handle(REBVAL *value, REB_MOLD *mold) if (IS_CONTEXT_HANDLE(value)) { if (!IS_USED_HOB(VAL_HANDLE_CTX(value))) Append_Bytes(mold->series, " unset!"); + else { + REBCNT idx = VAL_HANDLE_CTX(value)->index; + REBHSP spec = PG_Handles[idx]; + REBINT len; + if (spec.mold) { + len = spec.mold(VAL_HANDLE_CTX(value), BUF_PRINT); + if (len > 0) { + Append_Byte(mold->series, ' '); + Append_Bytes_Len(mold->series, STR_HEAD(BUF_PRINT), len); + } + } + } } Append_Byte(mold->series, ']'); } diff --git a/src/include/sys-value.h b/src/include/sys-value.h index f955f898ff..95d45a8f2a 100644 --- a/src/include/sys-value.h +++ b/src/include/sys-value.h @@ -997,8 +997,8 @@ typedef void (*REBDOF)(REBVAL *ds); // DO evaltype dispatch function typedef int (*REBPAF)(REBVAL *ds, REBVAL *p, REBCNT a); // Port action func typedef int (*REB_HANDLE_FREE_FUNC)(void *hnd); +typedef int (*REB_HANDLE_MOLD_FUNC)(void *hnd, REBSER *ser); typedef int (*REB_HANDLE_EVAL_PATH)(REBHOB *hob, REBCNT word, REBCNT *type, RXIARG *arg); -typedef REBSER* (*REB_HANDLE_MOLD_FUNC)(REBSER *mold, void *hnd); //TODO: not used yet! typedef void (*ANYFUNC)(void *); typedef void (*TRYFUNC)(void *); @@ -1101,6 +1101,7 @@ typedef struct Reb_Handle_Spec { REB_HANDLE_FREE_FUNC free; REB_HANDLE_EVAL_PATH get_path; REB_HANDLE_EVAL_PATH set_path; + REB_HANDLE_MOLD_FUNC mold; } REBHSP; typedef struct Reb_Handle_Context { diff --git a/src/os/host-ext-test.c b/src/os/host-ext-test.c index 520f96e2bc..7992e9c995 100644 --- a/src/os/host-ext-test.c +++ b/src/os/host-ext-test.c @@ -499,6 +499,21 @@ int XTestContext_set_path(REBHOB *hob, REBCNT word, REBCNT *type, RXIARG *arg) { return PE_OK; } +int XTestContext_mold(REBHOB *hob, REBSER *str) { + int len; + XTEST* xtest = (XTEST*)hob->data; + + if (!str || !xtest) return 0; + + len = snprintf( + SERIES_DATA(str), + SERIES_REST(str), + "0#%lx id: %u", (unsigned long)hob->data, xtest->id + ); + if (len > 0) SERIES_TAIL(str) += len; + return len; +} + void Init_Ext_Test(void) @@ -510,6 +525,7 @@ void Init_Ext_Test(void) spec.free = XTestContext_release; spec.get_path = XTestContext_get_path; spec.set_path = XTestContext_set_path; + spec.mold = XTestContext_mold; Handle_XTest = RL_REGISTER_HANDLE_SPEC("XTEST", &spec); } #endif //TEST_EXTENSIONS \ No newline at end of file