std: return Elf object from constructors instead of filling in pointer

This commit is contained in:
daurnimator 2019-08-03 15:56:25 +10:00
parent 57830e43ee
commit 521aaf3501
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A
2 changed files with 7 additions and 6 deletions

View File

@ -1024,8 +1024,7 @@ pub fn openElfDebugInfo(
elf_seekable_stream: *DwarfSeekableStream,
elf_in_stream: *DwarfInStream,
) !DwarfInfo {
var efile: elf.Elf = undefined;
try efile.openStream(allocator, elf_seekable_stream, elf_in_stream);
var efile = try elf.Elf.openStream(allocator, elf_seekable_stream, elf_in_stream);
errdefer efile.close();
var di = DwarfInfo{

View File

@ -371,21 +371,21 @@ pub const Elf = struct {
prealloc_file: File,
/// Call close when done.
pub fn openPath(elf: *Elf, allocator: *mem.Allocator, path: []const u8) !void {
pub fn openPath(allocator: *mem.Allocator, path: []const u8) !Elf {
@compileError("TODO implement");
}
/// Call close when done.
pub fn openFile(elf: *Elf, allocator: *mem.Allocator, file: File) !void {
pub fn openFile(allocator: *mem.Allocator, file: File) !Elf {
@compileError("TODO implement");
}
pub fn openStream(
elf: *Elf,
allocator: *mem.Allocator,
seekable_stream: *io.SeekableStream(anyerror, anyerror),
in: *io.InStream(anyerror),
) !void {
) !Elf {
var elf: Elf = undefined;
elf.auto_close_stream = false;
elf.allocator = allocator;
elf.seekable_stream = seekable_stream;
@ -523,6 +523,8 @@ pub const Elf = struct {
// not a string table
return error.InvalidFormat;
}
return elf;
}
pub fn close(elf: *Elf) void {