mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Make sure to delete on the right allocator.
This commit is contained in:
@@ -104,12 +104,14 @@ GZIP_MAX_PAYLOAD_SIZE :: int(max(u32le))
|
|||||||
load :: proc{load_from_slice, load_from_file, load_from_context}
|
load :: proc{load_from_slice, load_from_file, load_from_context}
|
||||||
|
|
||||||
load_from_file :: proc(filename: string, buf: ^bytes.Buffer, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
|
load_from_file :: proc(filename: string, buf: ^bytes.Buffer, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
|
||||||
data, ok := os.read_entire_file(filename, allocator)
|
context.allocator = allocator
|
||||||
|
|
||||||
|
data, ok := os.read_entire_file(filename)
|
||||||
defer delete(data)
|
defer delete(data)
|
||||||
|
|
||||||
err = E_General.File_Not_Found
|
err = E_General.File_Not_Found
|
||||||
if ok {
|
if ok {
|
||||||
err = load_from_slice(data, buf, len(data), expected_output_size, allocator)
|
err = load_from_slice(data, buf, len(data), expected_output_size)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -125,6 +127,7 @@ load_from_slice :: proc(slice: []u8, buf: ^bytes.Buffer, known_gzip_size := -1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
load_from_context :: proc(z: ^$C, buf: ^bytes.Buffer, known_gzip_size := -1, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
|
load_from_context :: proc(z: ^$C, buf: ^bytes.Buffer, known_gzip_size := -1, expected_output_size := -1, allocator := context.allocator) -> (err: Error) {
|
||||||
|
context.allocator = allocator
|
||||||
buf := buf
|
buf := buf
|
||||||
expected_output_size := expected_output_size
|
expected_output_size := expected_output_size
|
||||||
|
|
||||||
|
|||||||
@@ -495,6 +495,7 @@ inflate_from_context :: proc(using ctx: ^compress.Context_Memory_Input, raw := f
|
|||||||
|
|
||||||
@(optimization_mode="speed")
|
@(optimization_mode="speed")
|
||||||
inflate_raw :: proc(z: ^$C, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
|
inflate_raw :: proc(z: ^$C, expected_output_size := -1, allocator := context.allocator) -> (err: Error) #no_bounds_check {
|
||||||
|
context.allocator = allocator
|
||||||
expected_output_size := expected_output_size
|
expected_output_size := expected_output_size
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -526,9 +527,9 @@ inflate_raw :: proc(z: ^$C, expected_output_size := -1, allocator := context.all
|
|||||||
defer free(z_offset)
|
defer free(z_offset)
|
||||||
defer free(codelength_ht)
|
defer free(codelength_ht)
|
||||||
|
|
||||||
z_repeat = allocate_huffman_table(allocator=context.allocator) or_return
|
z_repeat = allocate_huffman_table() or_return
|
||||||
z_offset = allocate_huffman_table(allocator=context.allocator) or_return
|
z_offset = allocate_huffman_table() or_return
|
||||||
codelength_ht = allocate_huffman_table(allocator=context.allocator) or_return
|
codelength_ht = allocate_huffman_table() or_return
|
||||||
|
|
||||||
final := u32(0)
|
final := u32(0)
|
||||||
type := u32(0)
|
type := u32(0)
|
||||||
|
|||||||
@@ -368,11 +368,13 @@ load_from_slice :: proc(slice: []u8, options := Options{}, allocator := context.
|
|||||||
}
|
}
|
||||||
|
|
||||||
load_from_file :: proc(filename: string, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
load_from_file :: proc(filename: string, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
||||||
data, ok := os.read_entire_file(filename, allocator)
|
context.allocator = allocator
|
||||||
|
|
||||||
|
data, ok := os.read_entire_file(filename)
|
||||||
defer delete(data)
|
defer delete(data)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
return load_from_slice(data, options, allocator)
|
return load_from_slice(data, options)
|
||||||
} else {
|
} else {
|
||||||
img = new(Image)
|
img = new(Image)
|
||||||
return img, E_General.File_Not_Found
|
return img, E_General.File_Not_Found
|
||||||
@@ -380,7 +382,9 @@ load_from_file :: proc(filename: string, options := Options{}, allocator := cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.allocator) -> (img: ^Image, err: Error) {
|
||||||
|
context.allocator = allocator
|
||||||
options := options
|
options := options
|
||||||
|
|
||||||
if .info in options {
|
if .info in options {
|
||||||
options |= {.return_metadata, .do_not_decompress_image}
|
options |= {.return_metadata, .do_not_decompress_image}
|
||||||
options -= {.info}
|
options -= {.info}
|
||||||
@@ -398,7 +402,7 @@ load_from_context :: proc(ctx: ^$C, options := Options{}, allocator := context.a
|
|||||||
img = new(Image)
|
img = new(Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
info := new(Info, context.allocator)
|
info := new(Info)
|
||||||
img.metadata_ptr = info
|
img.metadata_ptr = info
|
||||||
img.metadata_type = typeid_of(Info)
|
img.metadata_type = typeid_of(Info)
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -71,6 +71,8 @@ file_size_from_path :: proc(path: string) -> i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
read_entire_file :: proc(name: string, allocator := context.allocator) -> (data: []byte, success: bool) {
|
read_entire_file :: proc(name: string, allocator := context.allocator) -> (data: []byte, success: bool) {
|
||||||
|
context.allocator = allocator
|
||||||
|
|
||||||
fd, err := open(name, O_RDONLY, 0)
|
fd, err := open(name, O_RDONLY, 0)
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -86,7 +88,7 @@ read_entire_file :: proc(name: string, allocator := context.allocator) -> (data:
|
|||||||
return nil, true
|
return nil, true
|
||||||
}
|
}
|
||||||
|
|
||||||
data = make([]byte, int(length), allocator)
|
data = make([]byte, int(length))
|
||||||
if data == nil {
|
if data == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user