added: allocator parameter to `core.encoding.osad.deserialize`
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 17 Apr 2023 18:18:14 +0000 (13:18 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 17 Apr 2023 18:18:14 +0000 (13:18 -0500)
core/alloc/logging.onyx
core/encoding/osad.onyx
interpreter/src/debug/debug_thread.c

index 937a2561dbd24aa240bcc266693fe6d16dd095a2..2b62d4171f6676c016da0560275dc95d33473c5a 100644 (file)
@@ -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);
 
index ca4d84a95e9361d88e289a77615e6d159e3af22d..e311571453b21511335f5aa055997c3c76dd7032 100644 (file)
@@ -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));
             }
         }
     }
index fc0f1aa2171142d2057d48051384af205cbafa1e..78aa4e738c74d045eb7264c1d085c107f1ce114f 100644 (file)
@@ -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);