1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-17 15:57:12 +00:00

Add JANET_MARSH_UNSAFE flag.

This allows unmarshal to optional marshal raw
pointers and cfunctions and send them across threads.
This flag is only exposed in the C API as it is very easy
to misuse and cause segfaults.
This commit is contained in:
Calvin Rose
2020-04-19 10:55:00 -05:00
parent 122c77dbf6
commit 5054eb4276
3 changed files with 60 additions and 4 deletions

View File

@@ -329,7 +329,7 @@ int janet_thread_send(JanetThread *thread, Janet msg, double timeout) {
msgbuf->count = 0;
/* Start panic zone */
janet_marshal(msgbuf, msg, thread->encode, 0);
janet_marshal(msgbuf, msg, thread->encode, JANET_MARSHAL_UNSAFE);
/* End panic zone */
mailbox->messageNext = (mailbox->messageNext + 1) % mailbox->messageCapacity;
@@ -379,7 +379,7 @@ int janet_thread_receive(Janet *msg_out, double timeout) {
const uint8_t *nextItem = NULL;
Janet item = janet_unmarshal(
msgbuf->data, msgbuf->count,
0, janet_thread_get_decode(), &nextItem);
JANET_MARSHAL_UNSAFE, janet_thread_get_decode(), &nextItem);
*msg_out = item;
/* Cleanup */