aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-06-04 19:45:21 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-06-04 19:45:21 +0200
commit6c82924d0a56ca6868e89ba2559a0bf9ca07c16b (patch)
tree7263c9c3912978f68898fa85be6786436965c7b1 /src
parentef77d6ab12be2c6d47ff33c3e7a04884c915e97d (diff)
Start fixing memory leaks on tests.
Diffstat (limited to 'src')
-rw-r--r--src/common/util_windows.odin36
-rw-r--r--src/server/build.odin7
-rw-r--r--src/server/collector.odin5
-rw-r--r--src/server/documents.odin3
-rw-r--r--src/server/symbol.odin3
-rw-r--r--src/testing/testing.odin83
6 files changed, 76 insertions, 61 deletions
diff --git a/src/common/util_windows.odin b/src/common/util_windows.odin
index 1626529..71fe3e2 100644
--- a/src/common/util_windows.odin
+++ b/src/common/util_windows.odin
@@ -1,9 +1,9 @@
package common
-import "core:strings"
-import "core:mem"
import "core:fmt"
import "core:log"
+import "core:mem"
+import "core:strings"
import win32 "core:sys/windows"
@@ -36,8 +36,14 @@ get_case_sensitive_path :: proc(
)
if (file == win32.INVALID_HANDLE) {
- log.errorf("Failed on get_case_sensitive_path(%v) at %v", path, location)
- log_last_error()
+ when !ODIN_TEST {
+ log.errorf(
+ "Failed on get_case_sensitive_path(%v) at %v",
+ path,
+ location,
+ )
+ log_last_error()
+ }
return path
}
@@ -113,17 +119,17 @@ run_executable :: proc(
startup_info.dwFlags |= win32.STARTF_USESTDHANDLES
if !win32.CreateProcessW(
- nil,
- &win32.utf8_to_utf16(command)[0],
- nil,
- nil,
- true,
- 0,
- nil,
- nil,
- &startup_info,
- &process_info,
- ) {
+ nil,
+ &win32.utf8_to_utf16(command)[0],
+ nil,
+ nil,
+ true,
+ 0,
+ nil,
+ nil,
+ &startup_info,
+ &process_info,
+ ) {
return 0, false, stdout[0:]
}
diff --git a/src/server/build.odin b/src/server/build.odin
index aca1796..d9e052a 100644
--- a/src/server/build.odin
+++ b/src/server/build.odin
@@ -160,7 +160,10 @@ setup_index :: proc() {
)
indexer.index = make_memory_index(symbol_collection)
- dir_exe, ok := filepath.abs(path.dir(os.args[0], context.temp_allocator))
+ dir_exe, ok := filepath.abs(
+ path.dir(os.args[0], context.temp_allocator),
+ context.temp_allocator,
+ )
if !ok {
log.error(
@@ -169,7 +172,7 @@ setup_index :: proc() {
return
}
- try_build_package(path.join({dir_exe, "builtin"}))
+ try_build_package(path.join({dir_exe, "builtin"}, context.temp_allocator))
}
free_index :: proc() {
diff --git a/src/server/collector.odin b/src/server/collector.odin
index e86fa92..eecf2ed 100644
--- a/src/server/collector.odin
+++ b/src/server/collector.odin
@@ -94,6 +94,11 @@ delete_symbol_collection :: proc(collection: SymbolCollection) {
}
for k, v in collection.packages {
+ for k2, v2 in v.methods {
+ delete(v2)
+ }
+ delete(v.methods)
+ delete(v.objc_structs)
delete(v.symbols)
}
diff --git a/src/server/documents.odin b/src/server/documents.odin
index d78a0d2..b874082 100644
--- a/src/server/documents.odin
+++ b/src/server/documents.odin
@@ -318,6 +318,7 @@ document_close :: proc(uri_string: string) -> common.Error {
common.delete_uri(document.uri)
delete(document.text)
+ delete(document.package_name)
document.used_text = 0
@@ -500,7 +501,7 @@ parse_imports :: proc(document: ^Document, config: ^common.Config) {
import_: Package
import_.original = imp.fullpath
import_.name = path.join(
- elems = {
+ elems = {
document.package_name,
imp.fullpath[1:len(imp.fullpath) - 1],
},
diff --git a/src/server/symbol.odin b/src/server/symbol.odin
index 39708d9..d46cf99 100644
--- a/src/server/symbol.odin
+++ b/src/server/symbol.odin
@@ -176,7 +176,7 @@ SymbolType :: enum {
Struct = 22,
Type_Function = 23,
Union = 7,
- Type = 8, //For maps, arrays, slices, dyn arrays, matrixes, etc
+ Type = 8, //For maps, arrays, slices, dyn arrays, matrixes, etc
Unresolved = 1, //Use text if not being able to resolve it.
}
@@ -223,6 +223,7 @@ free_symbol :: proc(symbol: Symbol, allocator: mem.Allocator) {
common.free_ast(v.group, allocator)
case SymbolEnumValue:
delete(v.names, allocator)
+ delete(v.ranges, allocator)
case SymbolUnionValue:
common.free_ast(v.types, allocator)
case SymbolBitSetValue:
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 9f67ff0..fb8c034 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -1,6 +1,7 @@
package ols_testing
import "core:fmt"
+import "core:log"
import "core:mem"
import "core:odin/ast"
import "core:odin/parser"
@@ -27,7 +28,7 @@ Source :: struct {
@(private)
setup :: proc(src: ^Source) {
- src.main = strings.clone(src.main)
+ src.main = strings.clone(src.main, context.temp_allocator)
src.document = new(server.Document, context.temp_allocator)
src.document.uri = common.create_uri(
"test/test.odin",
@@ -36,7 +37,10 @@ setup :: proc(src: ^Source) {
src.document.client_owned = true
src.document.text = transmute([]u8)src.main
src.document.used_text = len(src.document.text)
- src.document.allocator = new(common.Scratch_Allocator)
+ src.document.allocator = new(
+ common.Scratch_Allocator,
+ context.temp_allocator,
+ )
src.document.package_name = "test"
common.scratch_allocator_init(
@@ -78,12 +82,9 @@ setup :: proc(src: ^Source) {
server.document_refresh(src.document, &src.config, nil)
- /*
- There is a lot code here that is used in the real code, then i'd like to see.
- */
-
-
for src_pkg in src.packages {
+ context.allocator = common.scratch_allocator(src.document.allocator)
+
uri := common.create_uri(
fmt.aprintf("test/%v/package.odin", src_pkg.pkg),
context.temp_allocator,
@@ -99,7 +100,7 @@ setup :: proc(src: ^Source) {
dir := filepath.base(filepath.dir(fullpath, context.temp_allocator))
- pkg := new(ast.Package)
+ pkg := new(ast.Package, context.temp_allocator)
pkg.kind = .Normal
pkg.fullpath = fullpath
pkg.name = dir
@@ -133,8 +134,20 @@ setup :: proc(src: ^Source) {
@(private)
teardown :: proc(src: ^Source) {
+ //A lot of these deletes are managed by other systems in ols, but to simplify it, we just delete them here in tests.
+
server.free_index()
server.indexer.index = {}
+
+ delete(src.document.package_name)
+
+ for k, v in server.build_cache.loaded_pkgs {
+ delete(k)
+ }
+
+ delete(server.build_cache.loaded_pkgs)
+
+ common.scratch_allocator_destroy(src.document.allocator)
}
expect_signature_labels :: proc(
@@ -148,18 +161,17 @@ expect_signature_labels :: proc(
help, ok := server.get_signature_information(src.document, src.position)
if !ok {
- testing.error(t, "Failed get_signature_information")
+ log.error("Failed get_signature_information")
}
if len(expect_labels) == 0 && len(help.signatures) > 0 {
- testing.errorf(
- t,
+ log.errorf(
"Expected empty signature label, but received %v",
help.signatures,
)
}
- flags := make([]int, len(expect_labels))
+ flags := make([]int, len(expect_labels), context.temp_allocator)
for expect_label, i in expect_labels {
for signature, j in help.signatures {
@@ -171,8 +183,7 @@ expect_signature_labels :: proc(
for flag, i in flags {
if flag != 1 {
- testing.errorf(
- t,
+ log.errorf(
"Expected signature label %v, but received %v",
expect_labels[i],
help.signatures,
@@ -193,8 +204,7 @@ expect_signature_parameter_position :: proc(
help, ok := server.get_signature_information(src.document, src.position)
if help.activeParameter != position {
- testing.errorf(
- t,
+ log.errorf(
"expected parameter position %v, but received %v",
position,
help.activeParameter,
@@ -222,18 +232,17 @@ expect_completion_labels :: proc(
)
if !ok {
- testing.error(t, "Failed get_completion_list")
+ log.error("Failed get_completion_list")
}
if len(expect_labels) == 0 && len(completion_list.items) > 0 {
- testing.errorf(
- t,
+ log.errorf(
"Expected empty completion label, but received %v",
completion_list.items,
)
}
- flags := make([]int, len(expect_labels))
+ flags := make([]int, len(expect_labels), context.temp_allocator)
for expect_label, i in expect_labels {
for completion, j in completion_list.items {
@@ -245,8 +254,7 @@ expect_completion_labels :: proc(
for flag, i in flags {
if flag != 1 {
- testing.errorf(
- t,
+ log.errorf(
"Expected completion detail %v, but received %v",
expect_labels[i],
completion_list.items,
@@ -275,18 +283,17 @@ expect_completion_details :: proc(
)
if !ok {
- testing.error(t, "Failed get_completion_list")
+ log.error("Failed get_completion_list")
}
if len(expect_details) == 0 && len(completion_list.items) > 0 {
- testing.errorf(
- t,
+ log.errorf(
"Expected empty completion label, but received %v",
completion_list.items,
)
}
- flags := make([]int, len(expect_details))
+ flags := make([]int, len(expect_details), context.temp_allocator)
for expect_detail, i in expect_details {
for completion, j in completion_list.items {
@@ -298,8 +305,7 @@ expect_completion_details :: proc(
for flag, i in flags {
if flag != 1 {
- testing.errorf(
- t,
+ log.errorf(
"Expected completion label %v, but received %v",
expect_details[i],
completion_list.items,
@@ -319,20 +325,18 @@ expect_hover :: proc(
hover, _, ok := server.get_hover_information(src.document, src.position)
if !ok {
- testing.error(t, "Failed get_hover_information")
+ log.error(t, "Failed get_hover_information")
}
if expect_hover_string == "" && hover.contents.value != "" {
- testing.errorf(
- t,
+ log.errorf(
"Expected empty hover string, but received %v",
hover.contents.value,
)
}
if !strings.contains(hover.contents.value, expect_hover_string) {
- testing.errorf(
- t,
+ log.errorf(
"Expected hover string %v, but received %v",
expect_hover_string,
hover.contents.value,
@@ -351,18 +355,14 @@ expect_definition_locations :: proc(
locations, ok := server.get_definition_location(src.document, src.position)
if !ok {
- testing.error(t, "Failed get_definition_location")
+ log.error("Failed get_definition_location")
}
if len(expect_locations) == 0 && len(locations) > 0 {
- testing.errorf(
- t,
- "Expected empty locations, but received %v",
- locations,
- )
+ log.errorf("Expected empty locations, but received %v", locations)
}
- flags := make([]int, len(expect_locations))
+ flags := make([]int, len(expect_locations), context.temp_allocator)
for expect_location, i in expect_locations {
for location, j in locations {
@@ -374,8 +374,7 @@ expect_definition_locations :: proc(
for flag, i in flags {
if flag != 1 {
- testing.errorf(
- t,
+ log.errorf(
"Expected location %v, but received %v",
expect_locations[i].range,
locations,