mirror of
https://github.com/janet-lang/janet
synced 2024-11-05 16:26:17 +00:00
Change code for marshalling abstract types.
This commit is contained in:
parent
db902c90c4
commit
58d297364a
@ -364,11 +364,12 @@ 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) {
|
||||||
#ifdef JANET_32
|
union {
|
||||||
janet_marshal_int(ctx, (intptr_t) ptr);
|
const void *ptr;
|
||||||
#else
|
uint8_t bytes[sizeof(void *)];
|
||||||
janet_marshal_int64(ctx, (intptr_t) ptr);
|
} u;
|
||||||
#endif
|
u.ptr = 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) {
|
||||||
@ -422,6 +423,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();
|
||||||
} else {
|
} else {
|
||||||
janet_panicf("cannot marshal %p", x);
|
janet_panicf("cannot marshal %p", x);
|
||||||
}
|
}
|
||||||
@ -926,7 +928,7 @@ static const uint8_t *unmarshal_one_def(
|
|||||||
Janet value;
|
Janet value;
|
||||||
data = unmarshal_one(st, data, &value, flags + 1);
|
data = unmarshal_one(st, data, &value, flags + 1);
|
||||||
if (!janet_checktype(value, JANET_SYMBOL))
|
if (!janet_checktype(value, JANET_SYMBOL))
|
||||||
janet_panic("expected symbol in symbol map");
|
janet_panicf("expected symbol in unmarshal, got %v", value);
|
||||||
def->symbolmap[i].symbol = janet_unwrap_symbol(value);
|
def->symbolmap[i].symbol = janet_unwrap_symbol(value);
|
||||||
}
|
}
|
||||||
def->symbolmap_length = (uint32_t) symbolmap_length;
|
def->symbolmap_length = (uint32_t) symbolmap_length;
|
||||||
@ -1176,11 +1178,14 @@ int64_t janet_unmarshal_int64(JanetMarshalContext *ctx) {
|
|||||||
|
|
||||||
void *janet_unmarshal_ptr(JanetMarshalContext *ctx) {
|
void *janet_unmarshal_ptr(JanetMarshalContext *ctx) {
|
||||||
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
|
UnmarshalState *st = (UnmarshalState *)(ctx->u_state);
|
||||||
#ifdef JANET_32
|
union {
|
||||||
return (void *) ((intptr_t) readint(st, &(ctx->data)));
|
void *ptr;
|
||||||
#else
|
uint8_t bytes[sizeof(void *)];
|
||||||
return (void *) ((intptr_t) read64(st, &(ctx->data)));
|
} u;
|
||||||
#endif
|
MARSH_EOS(st, ctx->data + sizeof(void *) - 1);
|
||||||
|
memcpy(u.bytes, ctx->data, sizeof(void *));
|
||||||
|
ctx->data += sizeof(void *);
|
||||||
|
return u.ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t janet_unmarshal_byte(JanetMarshalContext *ctx) {
|
uint8_t janet_unmarshal_byte(JanetMarshalContext *ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user