فهرست منبع

Use regular allocator from png+gzip's `load_from_file`.

I would've used `os.stream_from_handle`, but:
- Parts of it seem to be implemented for Windows only at the moment.
- PNG's `peek_data` using that stream didn't manage to rewind and thus tried to parse the data after the header as the header.

Two things must happen:
- The `os.stream_from_handle` implementation needs to be fixed.
- PNG and GZIP's parsers need to be able to handle streams that can't rewind or seek (backward).

Those fixes are on my TODO list but are exceed the scope of this patch.
Jeroen van Rijn 4 سال پیش
والد
کامیت
06f1eaa153
2فایلهای تغییر یافته به همراه5 افزوده شده و 5 حذف شده
  1. 3 1
      core/compress/gzip/gzip.odin
  2. 2 4
      core/image/png/png.odin

+ 3 - 1
core/compress/gzip/gzip.odin

@@ -108,7 +108,9 @@ load_from_slice :: proc(slice: ^[]u8, buf: ^bytes.Buffer, allocator := context.a
 }
 
 load_from_file :: proc(filename: string, buf: ^bytes.Buffer, allocator := context.allocator) -> (err: Error) {
-	data, ok := os.read_entire_file(filename, context.temp_allocator);
+	data, ok := os.read_entire_file(filename, allocator);
+	defer delete(data);
+
 	if ok {
 		err = load_from_slice(&data, buf, allocator);
 		return;

+ 2 - 4
core/image/png/png.odin

@@ -366,11 +366,9 @@ load_from_slice :: proc(slice: ^[]u8, options: Options = {}, allocator := contex
 }
 
 load_from_file :: proc(filename: string, options: Options = {}, allocator := context.allocator) -> (img: ^Image, err: Error) {
-	load_file :: proc(filename: string) -> (res: []u8, ok: bool) {
-		return os.read_entire_file(filename, context.temp_allocator);
-	}
+	data, ok := os.read_entire_file(filename, allocator);
+	defer delete(data);
 
-	data, ok := load_file(filename);
 	if ok {
 		img, err = load_from_slice(&data, options, allocator);
 		return;