aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2020-12-03 00:30:16 +0100
committerDanielGavin <danielgavin5@hotmail.com>2020-12-03 00:30:16 +0100
commit35570e8b2b093e3da582d04c17c321f1c608edbd (patch)
tree7f18bf909391429ad653e7ac185d475351d8842c /src
parent69d1949780a923780efd640876f288480dc9bbf2 (diff)
formatting
Diffstat (limited to 'src')
-rw-r--r--src/common/track_allocator.odin238
-rw-r--r--src/common/types.odin26
-rw-r--r--src/server/log.odin48
3 files changed, 156 insertions, 156 deletions
diff --git a/src/common/track_allocator.odin b/src/common/track_allocator.odin
index c5d4452..d2c6d24 100644
--- a/src/common/track_allocator.odin
+++ b/src/common/track_allocator.odin
@@ -13,184 +13,184 @@ import "core:log"
// ----------------------------------------------------------------------------------------------------
ThreadSafe_Allocator_Data :: struct {
- actual_allocator : mem.Allocator,
- mutex : sync.Mutex,
+ actual_allocator : mem.Allocator,
+ mutex : sync.Mutex,
}
// ----------------------------------------------------------------------------------------------------
threadsafe_allocator :: proc (allocator: mem.Allocator) -> mem.Allocator {
- data := new(ThreadSafe_Allocator_Data);
- data.actual_allocator = allocator;
- sync.mutex_init(&data.mutex);
+ data := new(ThreadSafe_Allocator_Data);
+ data.actual_allocator = allocator;
+ sync.mutex_init(&data.mutex);
- return mem.Allocator { procedure = threadsafe_allocator_proc, data = data};
+ return mem.Allocator { procedure = threadsafe_allocator_proc, data = data};
}
// ----------------------------------------------------------------------------------------------------
threadsafe_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, size, alignment: int,
- old_memory: rawptr, old_size: int, flags : u64 = 0, loc := #caller_location) -> rawptr {
+ old_memory: rawptr, old_size: int, flags : u64 = 0, loc := #caller_location) -> rawptr {
- data := cast(^ThreadSafe_Allocator_Data)allocator_data;
+ data := cast(^ThreadSafe_Allocator_Data)allocator_data;
- sync.mutex_lock(&data.mutex);
- defer sync.mutex_unlock(&data.mutex);
+ sync.mutex_lock(&data.mutex);
+ defer sync.mutex_unlock(&data.mutex);
- return data.actual_allocator.procedure(data.actual_allocator.data, mode, size, alignment, old_memory, old_size, flags, loc);
+ return data.actual_allocator.procedure(data.actual_allocator.data, mode, size, alignment, old_memory, old_size, flags, loc);
}
// ----------------------------------------------------------------------------------------------------
Memleak_Allocator_Data :: struct {
- actual_allocator : mem.Allocator,
- allocations : map[rawptr] Memleak_Entry,
- frees : map[rawptr] Memleak_Entry,
- allocation_count : u32,
- unexpected_frees : u32,
- mutex : sync.Mutex,
- track_frees : bool,
+ actual_allocator : mem.Allocator,
+ allocations : map[rawptr] Memleak_Entry,
+ frees : map[rawptr] Memleak_Entry,
+ allocation_count : u32,
+ unexpected_frees : u32,
+ mutex : sync.Mutex,
+ track_frees : bool,
}
// ----------------------------------------------------------------------------------------------------
Memleak_Entry :: struct {
- location : runtime.Source_Code_Location,
- size : int,
- index : u32,
+ location : runtime.Source_Code_Location,
+ size : int,
+ index : u32,
}
// ----------------------------------------------------------------------------------------------------
memleak_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, size, alignment: int,
- old_memory: rawptr, old_size: int, flags : u64 = 0, loc := #caller_location) -> rawptr {
-
- memleak := cast(^Memleak_Allocator_Data)allocator_data;
-
- sync.mutex_lock(&memleak.mutex);
- defer sync.mutex_unlock(&memleak.mutex);
-
- if mode == .Free {
- if old_memory not_in memleak.allocations {
- if memleak.track_frees {
- if old_memory in memleak.frees {
- fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory already freed by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
- free_loc := memleak.frees[old_memory].location;
- fmt.println(fmt.tprintf("{0}({1}:{2}) {3} <<< freed here", loc.file_path, loc.line, loc.column, loc.procedure));
- }
- else {
- fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory not allocated or previously freed by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
- }
- }
- else {
- fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory not allocated by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
- }
- memleak.unexpected_frees += 1;
- return nil;
- }
- else {
- //entry := &memleak.allocations[old_memory];
- delete_key(&memleak.allocations, old_memory);
-
- if memleak.track_frees {
- memleak.frees[old_memory] = Memleak_Entry {
- location = loc,
- size = size,
- index = 0,
- };
- }
- }
- }
-
- result := memleak.actual_allocator.procedure(memleak.actual_allocator.data, mode, size, alignment, old_memory, old_size, flags, loc);
-
- if mode == .Resize && result != old_memory {
- delete_key(&memleak.allocations, old_memory);
- }
-
- if mode != .Free {
- // using a conditional breakpoint with memleak.allocation_count in the condition
- // can be very useful for inspecting the stack trace of a particular allocation
-
- memleak.allocations[result] = Memleak_Entry {
- location = loc,
- size = size,
- index = memleak.allocation_count,
- };
-
- memleak.allocation_count += 1;
-
- if memleak.track_frees {
- if result in memleak.frees {
- delete_key(&memleak.frees, result);
- }
- }
- }
-
- return result;
+ old_memory: rawptr, old_size: int, flags : u64 = 0, loc := #caller_location) -> rawptr {
+
+ memleak := cast(^Memleak_Allocator_Data)allocator_data;
+
+ sync.mutex_lock(&memleak.mutex);
+ defer sync.mutex_unlock(&memleak.mutex);
+
+ if mode == .Free {
+ if old_memory not_in memleak.allocations {
+ if memleak.track_frees {
+ if old_memory in memleak.frees {
+ fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory already freed by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
+ free_loc := memleak.frees[old_memory].location;
+ fmt.println(fmt.tprintf("{0}({1}:{2}) {3} <<< freed here", loc.file_path, loc.line, loc.column, loc.procedure));
+ }
+ else {
+ fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory not allocated or previously freed by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
+ }
+ }
+ else {
+ fmt.println(fmt.tprintf("{0}({1}:{2}) {3} freed memory not allocated by this memleak allocator", loc.file_path, loc.line, loc.column, loc.procedure));
+ }
+ memleak.unexpected_frees += 1;
+ return nil;
+ }
+ else {
+ //entry := &memleak.allocations[old_memory];
+ delete_key(&memleak.allocations, old_memory);
+
+ if memleak.track_frees {
+ memleak.frees[old_memory] = Memleak_Entry {
+ location = loc,
+ size = size,
+ index = 0,
+ };
+ }
+ }
+ }
+
+ result := memleak.actual_allocator.procedure(memleak.actual_allocator.data, mode, size, alignment, old_memory, old_size, flags, loc);
+
+ if mode == .Resize && result != old_memory {
+ delete_key(&memleak.allocations, old_memory);
+ }
+
+ if mode != .Free {
+ // using a conditional breakpoint with memleak.allocation_count in the condition
+ // can be very useful for inspecting the stack trace of a particular allocation
+
+ memleak.allocations[result] = Memleak_Entry {
+ location = loc,
+ size = size,
+ index = memleak.allocation_count,
+ };
+
+ memleak.allocation_count += 1;
+
+ if memleak.track_frees {
+ if result in memleak.frees {
+ delete_key(&memleak.frees, result);
+ }
+ }
+ }
+
+ return result;
}
// ----------------------------------------------------------------------------------------------------
memleak_allocator :: proc (track_frees: bool) -> mem.Allocator {
- make([]byte, 1, context.temp_allocator); // so the temp allocation doesn't clutter our results
+ make([]byte, 1, context.temp_allocator); // so the temp allocation doesn't clutter our results
- data := new(Memleak_Allocator_Data);
- data.actual_allocator = context.allocator;
- data.allocations = make(map[rawptr]Memleak_Entry);
+ data := new(Memleak_Allocator_Data);
+ data.actual_allocator = context.allocator;
+ data.allocations = make(map[rawptr]Memleak_Entry);
- if track_frees {
- data.track_frees = true;
- data.frees = make(map[rawptr]Memleak_Entry);
- }
+ if track_frees {
+ data.track_frees = true;
+ data.frees = make(map[rawptr]Memleak_Entry);
+ }
- sync.mutex_init(&data.mutex);
+ sync.mutex_init(&data.mutex);
- return mem.Allocator { procedure = memleak_allocator_proc, data = data};
+ return mem.Allocator { procedure = memleak_allocator_proc, data = data};
}
// ----------------------------------------------------------------------------------------------------
memleak_detected_leaks :: proc() -> bool {
- if context.allocator.procedure == memleak_allocator_proc {
- memleak := cast(^Memleak_Allocator_Data)context.allocator.data;
- return len(memleak.allocations) > 0;
- }
+ if context.allocator.procedure == memleak_allocator_proc {
+ memleak := cast(^Memleak_Allocator_Data)context.allocator.data;
+ return len(memleak.allocations) > 0;
+ }
- return false;
+ return false;
}
// ----------------------------------------------------------------------------------------------------
memleak_dump :: proc( memleak_alloc : mem.Allocator, dump_proc : proc(message:string, user_data:rawptr), user_data : rawptr) {
- memleak := cast(^Memleak_Allocator_Data)memleak_alloc.data;
+ memleak := cast(^Memleak_Allocator_Data)memleak_alloc.data;
- context.allocator = memleak.actual_allocator;
+ context.allocator = memleak.actual_allocator;
- // check for an ignore default_temp_allocator_proc allocations
- tmp_check := 0;
- for _, leak in &memleak.allocations {
- if leak.location.procedure == "default_temp_allocator_proc" {
- tmp_check += 1;
- }
- }
+ // check for an ignore default_temp_allocator_proc allocations
+ tmp_check := 0;
+ for _, leak in &memleak.allocations {
+ if leak.location.procedure == "default_temp_allocator_proc" {
+ tmp_check += 1;
+ }
+ }
- dump_proc(fmt.tprintf("{0} memory leaks detected!", len(memleak.allocations) - tmp_check), user_data);
- dump_proc(fmt.tprintf("{0} unexpected frees", memleak.unexpected_frees), user_data);
+ dump_proc(fmt.tprintf("{0} memory leaks detected!", len(memleak.allocations) - tmp_check), user_data);
+ dump_proc(fmt.tprintf("{0} unexpected frees", memleak.unexpected_frees), user_data);
- for _, leak in &memleak.allocations {
- if leak.location.procedure != "default_temp_allocator_proc" {
- dump_proc(fmt.tprintf("{0}({1}:{2}) {3} allocated {4} bytes [{5}]", leak.location.file_path, leak.location.line, leak.location.column, leak.location.procedure, leak.size, leak.index), user_data);
- }
- }
+ for _, leak in &memleak.allocations {
+ if leak.location.procedure != "default_temp_allocator_proc" {
+ dump_proc(fmt.tprintf("{0}({1}:{2}) {3} allocated {4} bytes [{5}]", leak.location.file_path, leak.location.line, leak.location.column, leak.location.procedure, leak.size, leak.index), user_data);
+ }
+ }
- context.allocator = mem.Allocator {procedure = memleak_allocator_proc, data = memleak};
+ context.allocator = mem.Allocator {procedure = memleak_allocator_proc, data = memleak};
}
// ----------------------------------------------------------------------------------------------------
log_dump :: proc(message:string, user_data:rawptr) {
- log.info(message);
+ log.info(message);
} \ No newline at end of file
diff --git a/src/common/types.odin b/src/common/types.odin
index 08bd8c2..73b3f3a 100644
--- a/src/common/types.odin
+++ b/src/common/types.odin
@@ -4,20 +4,20 @@ package common
Error :: enum {
None = 0,
- // Defined by JSON RPC
- ParseError = -32700,
- InvalidRequest = -32600,
- MethodNotFound = -32601,
- InvalidParams = -32602,
- InternalError = -32603,
- serverErrorStart = -32099,
- serverErrorEnd = -32000,
- ServerNotInitialized = -32002,
- UnknownErrorCode = -32001,
+ // Defined by JSON RPC
+ ParseError = -32700,
+ InvalidRequest = -32600,
+ MethodNotFound = -32601,
+ InvalidParams = -32602,
+ InternalError = -32603,
+ serverErrorStart = -32099,
+ serverErrorEnd = -32000,
+ ServerNotInitialized = -32002,
+ UnknownErrorCode = -32001,
- // Defined by the protocol.
- RequestCancelled = -32800,
- ContentModified = -32801,
+ // Defined by the protocol.
+ RequestCancelled = -32800,
+ ContentModified = -32801,
};
WorkspaceFolder :: struct {
diff --git a/src/server/log.odin b/src/server/log.odin
index 5ed007e..59a98c7 100644
--- a/src/server/log.odin
+++ b/src/server/log.odin
@@ -8,45 +8,45 @@ import "core:log";
Default_Console_Logger_Opts :: log.Options{
- .Level,
- .Terminal_Color,
- .Short_File_Path,
- .Line,
- .Procedure,
+ .Level,
+ .Terminal_Color,
+ .Short_File_Path,
+ .Line,
+ .Procedure,
} | log.Full_Timestamp_Opts;
Lsp_Logger_Data :: struct {
- writer: ^Writer,
+ writer: ^Writer,
}
create_lsp_logger :: proc(writer: ^Writer, lowest := log.Level.Debug, opt := Default_Console_Logger_Opts) -> log.Logger {
- data := new(Lsp_Logger_Data);
- data.writer = writer;
- return log.Logger{lsp_logger_proc, data, lowest, opt};
+ data := new(Lsp_Logger_Data);
+ data.writer = writer;
+ return log.Logger{lsp_logger_proc, data, lowest, opt};
}
destroy_lsp_logger :: proc(log: ^log.Logger) {
- free(log.data);
+ free(log.data);
}
lsp_logger_proc :: proc(logger_data: rawptr, level: log.Level, text: string, options: log.Options, location := #caller_location) {
- data := cast(^Lsp_Logger_Data)logger_data;
+ data := cast(^Lsp_Logger_Data)logger_data;
- backing: [1024]byte; //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
- buf := strings.builder_from_slice(backing[:]);
+ backing: [1024]byte; //NOTE(Hoej): 1024 might be too much for a header backing, unless somebody has really long paths.
+ buf := strings.builder_from_slice(backing[:]);
- when time.IS_SUPPORTED {
- if log.Full_Timestamp_Opts & options != nil {
- fmt.sbprint(&buf, "[");
- t := time.now();
- y, m, d := time.date(t);
- h, min, s := time.clock(t);
- if .Date in options { fmt.sbprintf(&buf, "%d-%02d-%02d ", y, m, d); }
- if .Time in options { fmt.sbprintf(&buf, "%02d:%02d:%02d", h, min, s); }
- fmt.sbprint(&buf, "] ");
- }
- }
+ when time.IS_SUPPORTED {
+ if log.Full_Timestamp_Opts & options != nil {
+ fmt.sbprint(&buf, "[");
+ t := time.now();
+ y, m, d := time.date(t);
+ h, min, s := time.clock(t);
+ if .Date in options { fmt.sbprintf(&buf, "%d-%02d-%02d ", y, m, d); }
+ if .Time in options { fmt.sbprintf(&buf, "%02d:%02d:%02d", h, min, s); }
+ fmt.sbprint(&buf, "] ");
+ }
+ }
message := fmt.tprintf("%s", text);