From ab13a590e2fc6e51db2a4e15c61f1f6dc7e75386 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 17 Apr 2023 13:18:14 -0500 Subject: [PATCH] added: allocator parameter to `core.encoding.osad.deserialize` --- core/alloc/logging.onyx | 8 ++++---- core/encoding/osad.onyx | 20 ++++++++++---------- interpreter/src/debug/debug_thread.c | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core/alloc/logging.onyx b/core/alloc/logging.onyx index 937a2561..2b62d417 100644 --- a/core/alloc/logging.onyx +++ b/core/alloc/logging.onyx @@ -8,8 +8,8 @@ use core #local Allocation_Action_Strings := str.[ - " alloc", - " free", + "alloc", + "free", "resize", ]; @@ -19,8 +19,8 @@ logging_allocator_proc :: (data: rawptr, aa: AllocationAction, size: u32, align: res := allocator.func(allocator.data, aa, size, align, oldptr); use core { tprintf } - msg := tprintf("{} with size {}, align {}, oldptr {} returns {}\n", - Allocation_Action_Strings[cast(u32) aa], size, align, oldptr, res); + msg := tprintf("{} = {}(size={}, align={}, oldptr={})", + res, Allocation_Action_Strings[cast(u32) aa], size, align, oldptr); log(.Info, "Core", msg); diff --git a/core/encoding/osad.onyx b/core/encoding/osad.onyx index ca4d84a9..e3115714 100644 --- a/core/encoding/osad.onyx +++ b/core/encoding/osad.onyx @@ -125,12 +125,12 @@ serialize :: (v: any, w: &io.Writer) -> bool { deserialize :: #match #local {} #overload -deserialize :: ($T: type_expr, s: str) -> ?T { +deserialize :: ($T: type_expr, s: str, allocator := context.allocator) -> ?T { reader, stream := io.reader_from_string(s); defer cfree(stream); target: T; - if !deserialize(&target, T, &reader) { + if !deserialize(&target, T, &reader, allocator) { // This could leak memory if we partially deserialized something. return .{}; } @@ -139,7 +139,7 @@ deserialize :: ($T: type_expr, s: str) -> ?T { } #overload -deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { +deserialize :: (target: rawptr, type: type_expr, r: &io.Reader, allocator := context.allocator) -> bool { info := type_info.get_type_info(type); switch info.kind { @@ -160,12 +160,12 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { case .Enum { e_info := cast(&type_info.Type_Info_Enum, info); - try(deserialize(target, e_info.backing_type, r)); + try(deserialize(target, e_info.backing_type, r, allocator)); } case .Distinct { d_info := cast(&type_info.Type_Info_Distinct, info); - try(deserialize(target, d_info.base_type, r)); + try(deserialize(target, d_info.base_type, r, allocator)); } case .Array { @@ -175,7 +175,7 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { elem_size := type_info.size_of(a_info.of); for a_info.count { - try(deserialize(base + it * elem_size, a_info.of, r)); + try(deserialize(base + it * elem_size, a_info.of, r, allocator)); } } @@ -187,18 +187,18 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { untyped_slice := cast(&array.Untyped_Array, target); untyped_slice.count = count; - untyped_slice.data = raw_alloc(context.allocator, elem_size * count); + untyped_slice.data = raw_alloc(allocator, elem_size * count); memory.set(untyped_slice.data, 0, elem_size * count); if info.kind == .Dynamic_Array { untyped_slice.capacity = count; - untyped_slice.allocator = context.allocator; + untyped_slice.allocator = allocator; } base: [&] u8 = untyped_slice.data; for count { - try(deserialize(base + it * elem_size, s_info.of, r)); + try(deserialize(base + it * elem_size, s_info.of, r, allocator)); } } @@ -208,7 +208,7 @@ deserialize :: (target: rawptr, type: type_expr, r: &io.Reader) -> bool { base: [&] u8 = target; for& member: s_info.members { - try(deserialize(base + member.offset, member.type, r)); + try(deserialize(base + member.offset, member.type, r, allocator)); } } } diff --git a/interpreter/src/debug/debug_thread.c b/interpreter/src/debug/debug_thread.c index fc0f1aa2..78aa4e73 100644 --- a/interpreter/src/debug/debug_thread.c +++ b/interpreter/src/debug/debug_thread.c @@ -543,6 +543,7 @@ static void process_command(debug_state_t *debug, struct msg_parse_ctx_t *ctx) { u32 command_id = parse_int(debug, ctx); if (command_id >= sizeof(command_handlers) / sizeof(command_handlers[0])) { + printf("[ERROR] Unrecognized command id %x\n", command_id); send_response_header(debug, msg_id); return; } @@ -579,7 +580,7 @@ void *__debug_thread_entry(void * data) { unlink(local_addr.sun_path); // TODO: Remove this line for the same reason. int len = strlen(local_addr.sun_path) + sizeof(local_addr.sun_family); bind(debug->listen_socket_fd, (struct sockaddr *)&local_addr, len); - + // // Currently, there can only be 1 connected debugger instance at a time. listen(debug->listen_socket_fd, 1); -- 2.25.1