authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-04 00:21:38-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-08-04 00:21:38-07:00
logf01cb8cc16bd048adefdec5a426d5ef33dff9168
tree61c62a9f732fcf0a0ec1c01dc9ae4d807b3a1aa2
parent5687323cd2a759dfdf9533e46e3de8cddb1b55b7
parent887eac0219345763f1ae9c8d9efad6950f6bbfe6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2998 from daurnimator/return-elf

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

2 files changed, 7 insertions(+), 11 deletions(-)

std/debug.zig+1-2
......@@ -1024,8 +1024,7 @@ pub fn openElfDebugInfo(
10241024 elf_seekable_stream: *DwarfSeekableStream,
10251025 elf_in_stream: *DwarfInStream,
10261026) !DwarfInfo {
1027 var efile: elf.Elf = undefined;
1028 try efile.openStream(allocator, elf_seekable_stream, elf_in_stream);
1027 var efile = try elf.Elf.openStream(allocator, elf_seekable_stream, elf_in_stream);
10291028 errdefer efile.close();
10301029
10311030 var di = DwarfInfo{
std/elf.zig+6-9
......@@ -356,7 +356,6 @@ pub const SectionHeader = struct {
356356pub const Elf = struct {
357357 seekable_stream: *io.SeekableStream(anyerror, anyerror),
358358 in_stream: *io.InStream(anyerror),
359 auto_close_stream: bool,
360359 is_64: bool,
361360 endian: builtin.Endian,
362361 file_type: FileType,
......@@ -368,25 +367,23 @@ pub const Elf = struct {
368367 string_section: *SectionHeader,
369368 section_headers: []SectionHeader,
370369 allocator: *mem.Allocator,
371 prealloc_file: File,
372370
373371 /// 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 {
375373 @compileError("TODO implement");
376374 }
377375
378376 /// 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 {
380378 @compileError("TODO implement");
381379 }
382380
383381 pub fn openStream(
384 elf: *Elf,
385382 allocator: *mem.Allocator,
386383 seekable_stream: *io.SeekableStream(anyerror, anyerror),
387384 in: *io.InStream(anyerror),
388 ) !void {
389 elf.auto_close_stream = false;
385 ) !Elf {
386 var elf: Elf = undefined;
390387 elf.allocator = allocator;
391388 elf.seekable_stream = seekable_stream;
392389 elf.in_stream = in;
......@@ -523,12 +520,12 @@ pub const Elf = struct {
523520 // not a string table
524521 return error.InvalidFormat;
525522 }
523
524 return elf;
526525 }
527526
528527 pub fn close(elf: *Elf) void {
529528 elf.allocator.free(elf.section_headers);
530
531 if (elf.auto_close_stream) elf.prealloc_file.close();
532529 }
533530
534531 pub fn findSection(elf: *Elf, name: []const u8) !?*SectionHeader {