From 81b5904188a060f5637e5021fc413f454e29e305 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 15 Aug 2021 16:12:40 -0500 Subject: [PATCH] Add marshal/unmarshal to items pushed to threaded channel. --- src/core/ev.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/core/ev.c b/src/core/ev.c index 2514e1e9..6e690351 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -579,8 +579,16 @@ static inline int janet_chan_is_threaded(JanetChannel *chan) { static int janet_chan_pack(JanetChannel *chan, Janet *x) { if (chan->ref_count < 0) return 0; switch (janet_type(*x)) { - default: - return 1; + default: { + JanetBuffer *buf = janet_malloc(sizeof(JanetBuffer)); + if (NULL == buf) { + JANET_OUT_OF_MEMORY; + } + janet_buffer_init(buf, 10); + janet_marshal(buf, *x, NULL, JANET_MARSHAL_UNSAFE); + *x = janet_wrap_buffer(buf); + return 0; + } case JANET_NIL: case JANET_NUMBER: case JANET_POINTER: @@ -595,6 +603,13 @@ static int janet_chan_unpack(JanetChannel *chan, Janet *x) { switch (janet_type(*x)) { default: return 1; + case JANET_BUFFER: { + JanetBuffer *buf = janet_unwrap_buffer(*x); + *x = janet_unmarshal(buf->data, buf->count, JANET_MARSHAL_UNSAFE, NULL, NULL); + janet_buffer_deinit(buf); + janet_free(buf); + return 0; + } case JANET_NIL: case JANET_NUMBER: case JANET_POINTER: @@ -1812,7 +1827,7 @@ void janet_ev_post_event(JanetVM *vm, JanetCallback cb, JanetEVGenericMessage ms sleep(0); tries--; } - //janet_assert(tries > 0, "failed to write event to self-pipe"); + janet_assert(tries > 0, "failed to write event to self-pipe"); #endif }