mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 09:00:26 +00:00
Make some fixes to marshalling.
This commit is contained in:
parent
60fba585e3
commit
edf263bcb5
@ -154,7 +154,7 @@ static void pushbytes(MarshalState *st, const uint8_t *bytes, int32_t len) {
|
|||||||
janet_buffer_push_bytes(st->buf, bytes, len);
|
janet_buffer_push_bytes(st->buf, bytes, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pushpointer(MarshalState *st, void *ptr) {
|
static void pushpointer(MarshalState *st, const void *ptr) {
|
||||||
janet_buffer_push_bytes(st->buf, (const uint8_t *) &ptr, sizeof(ptr));
|
janet_buffer_push_bytes(st->buf, (const uint8_t *) &ptr, sizeof(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,12 +364,11 @@ void janet_marshal_int(JanetMarshalContext *ctx, int32_t value) {
|
|||||||
|
|
||||||
/* Only use in unsafe - don't marshal pointers otherwise */
|
/* Only use in unsafe - don't marshal pointers otherwise */
|
||||||
void janet_marshal_ptr(JanetMarshalContext *ctx, const void *ptr) {
|
void janet_marshal_ptr(JanetMarshalContext *ctx, const void *ptr) {
|
||||||
union {
|
if (!(ctx->flags & JANET_MARSHAL_UNSAFE)) {
|
||||||
const void *ptr;
|
janet_panic("can only marshal pointers in unsafe mode");
|
||||||
uint8_t bytes[sizeof(void *)];
|
}
|
||||||
} u;
|
MarshalState *st = (MarshalState *)(ctx->m_state);
|
||||||
u.ptr = ptr;
|
pushpointer(st, ptr);
|
||||||
pushbytes(ctx->m_state, u.bytes, sizeof(void *));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void janet_marshal_byte(JanetMarshalContext *ctx, uint8_t value) {
|
void janet_marshal_byte(JanetMarshalContext *ctx, uint8_t value) {
|
||||||
@ -413,6 +412,7 @@ static void marshal_one_abstract(MarshalState *st, Janet x, int flags) {
|
|||||||
janet_abstract_incref(abstract);
|
janet_abstract_incref(abstract);
|
||||||
pushbyte(st, LB_THREADED_ABSTRACT);
|
pushbyte(st, LB_THREADED_ABSTRACT);
|
||||||
pushbytes(st, (uint8_t *) &abstract, sizeof(abstract));
|
pushbytes(st, (uint8_t *) &abstract, sizeof(abstract));
|
||||||
|
MARK_SEEN();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -422,7 +422,7 @@ static void marshal_one_abstract(MarshalState *st, Janet x, int flags) {
|
|||||||
marshal_one(st, janet_csymbolv(at->name), flags + 1);
|
marshal_one(st, janet_csymbolv(at->name), flags + 1);
|
||||||
JanetMarshalContext context = {st, NULL, flags, NULL, at};
|
JanetMarshalContext context = {st, NULL, flags, NULL, at};
|
||||||
at->marshal(abstract, &context);
|
at->marshal(abstract, &context);
|
||||||
MARK_SEEN();
|
//MARK_SEEN();
|
||||||
} else {
|
} else {
|
||||||
janet_panicf("cannot marshal %p", x);
|
janet_panicf("cannot marshal %p", x);
|
||||||
}
|
}
|
||||||
@ -1176,15 +1176,15 @@ int64_t janet_unmarshal_int64(JanetMarshalContext *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *janet_unmarshal_ptr(JanetMarshalContext *ctx) {
|
void *janet_unmarshal_ptr(JanetMarshalContext *ctx) {
|
||||||
|
if (!(ctx->flags & JANET_MARSHAL_UNSAFE)) {
|
||||||
|
janet_panic("can only unmarshal pointers in unsafe mode");
|
||||||
|
}
|
||||||
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
|
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
|
||||||
union {
|
void *ptr;
|
||||||
void *ptr;
|
|
||||||
uint8_t bytes[sizeof(void *)];
|
|
||||||
} u;
|
|
||||||
MARSH_EOS(st, ctx->data + sizeof(void *) - 1);
|
MARSH_EOS(st, ctx->data + sizeof(void *) - 1);
|
||||||
memcpy(u.bytes, ctx->data, sizeof(void *));
|
memcpy((char *) &ptr, ctx->data, sizeof(void *));
|
||||||
ctx->data += sizeof(void *);
|
ctx->data += sizeof(void *);
|
||||||
return u.ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t janet_unmarshal_byte(JanetMarshalContext *ctx) {
|
uint8_t janet_unmarshal_byte(JanetMarshalContext *ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user