| ... | @@ -356,7 +356,6 @@ pub const SectionHeader = struct { | ... | @@ -356,7 +356,6 @@ pub const SectionHeader = struct { |
| 356 | pub const Elf = struct { | 356 | pub const Elf = struct { |
| 357 | seekable_stream: *io.SeekableStream(anyerror, anyerror), | 357 | seekable_stream: *io.SeekableStream(anyerror, anyerror), |
| 358 | in_stream: *io.InStream(anyerror), | 358 | in_stream: *io.InStream(anyerror), |
| 359 | auto_close_stream: bool, | | |
| 360 | is_64: bool, | 359 | is_64: bool, |
| 361 | endian: builtin.Endian, | 360 | endian: builtin.Endian, |
| 362 | file_type: FileType, | 361 | file_type: FileType, |
| ... | @@ -368,25 +367,23 @@ pub const Elf = struct { | ... | @@ -368,25 +367,23 @@ pub const Elf = struct { |
| 368 | string_section: *SectionHeader, | 367 | string_section: *SectionHeader, |
| 369 | section_headers: []SectionHeader, | 368 | section_headers: []SectionHeader, |
| 370 | allocator: *mem.Allocator, | 369 | allocator: *mem.Allocator, |
| 371 | prealloc_file: File, | | |
| 372 | | 370 | |
| 373 | /// Call close when done. | 371 | /// Call close when done. |
| 374 | pub fn openPath(elf: *Elf, allocator: *mem.Allocator, path: []const u8) !void { | 372 | pub fn openPath(allocator: *mem.Allocator, path: []const u8) !Elf { |
| 375 | @compileError("TODO implement"); | 373 | @compileError("TODO implement"); |
| 376 | } | 374 | } |
| 377 | | 375 | |
| 378 | /// Call close when done. | 376 | /// Call close when done. |
| 379 | pub fn openFile(elf: *Elf, allocator: *mem.Allocator, file: File) !void { | 377 | pub fn openFile(allocator: *mem.Allocator, file: File) !Elf { |
| 380 | @compileError("TODO implement"); | 378 | @compileError("TODO implement"); |
| 381 | } | 379 | } |
| 382 | | 380 | |
| 383 | pub fn openStream( | 381 | pub fn openStream( |
| 384 | elf: *Elf, | | |
| 385 | allocator: *mem.Allocator, | 382 | allocator: *mem.Allocator, |
| 386 | seekable_stream: *io.SeekableStream(anyerror, anyerror), | 383 | seekable_stream: *io.SeekableStream(anyerror, anyerror), |
| 387 | in: *io.InStream(anyerror), | 384 | in: *io.InStream(anyerror), |
| 388 | ) !void { | 385 | ) !Elf { |
| 389 | elf.auto_close_stream = false; | 386 | var elf: Elf = undefined; |
| 390 | elf.allocator = allocator; | 387 | elf.allocator = allocator; |
| 391 | elf.seekable_stream = seekable_stream; | 388 | elf.seekable_stream = seekable_stream; |
| 392 | elf.in_stream = in; | 389 | elf.in_stream = in; |
| ... | @@ -523,12 +520,12 @@ pub const Elf = struct { | ... | @@ -523,12 +520,12 @@ pub const Elf = struct { |
| 523 | // not a string table | 520 | // not a string table |
| 524 | return error.InvalidFormat; | 521 | return error.InvalidFormat; |
| 525 | } | 522 | } |
| | 523 | |
| | 524 | return elf; |
| 526 | } | 525 | } |
| 527 | | 526 | |
| 528 | pub fn close(elf: *Elf) void { | 527 | pub fn close(elf: *Elf) void { |
| 529 | elf.allocator.free(elf.section_headers); | 528 | elf.allocator.free(elf.section_headers); |
| 530 | | | |
| 531 | if (elf.auto_close_stream) elf.prealloc_file.close(); | | |
| 532 | } | 529 | } |
| 533 | | 530 | |
| 534 | pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader { | 531 | pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader { |