diff options
Diffstat (limited to 'src/sf.zig')
-rw-r--r-- | src/sf.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/sf.zig b/src/sf.zig index d38446c..a95999c 100644 --- a/src/sf.zig +++ b/src/sf.zig @@ -16,7 +16,9 @@ // You should have received a copy of the GNU Lesser General Public License // along with zeal. If not, see <https://www.gnu.org/licenses/>. -const Allocator = @import("std").mem.Allocator; +const Allocator = std.mem.Allocator; +const assert = std.debug.assert; +const std = @import("std"); usingnamespace @cImport(@cInclude("sndfile.h")); @@ -26,7 +28,7 @@ pub const Mode = enum { read_write, }; -pub const Error = error { +pub const Error = Allocator.Error || error { UnrecognizedFormat, SystemError, MalformedFile, @@ -72,7 +74,7 @@ pub const SndFile = struct { /// Read the requested number of frames. /// The returned memory is managed by the caller. pub fn read(self: SndFile, allocator: *Allocator, - frames: usize) Allocator.Error![]const i16 { + frames: usize) Error![]const i16 { const items = frames * @intCast(usize, self.channels); const memory = try allocator.alloc(i16, items); const n = sf_read_short(self.pimpl, memory.ptr, @intCast(i64, items)); @@ -80,8 +82,7 @@ pub const SndFile = struct { } /// Read the entire file. The returned memory is managed by the caller. - pub fn readAll(self: SndFile, - allocator: *Allocator) Allocator.Error![]const i16 { + pub fn readAll(self: SndFile, allocator: *Allocator) Error![]const i16 { return self.read(allocator, self.frames); } @@ -89,6 +90,6 @@ pub const SndFile = struct { /// Like std.os.close, this function does not return /// any indication of failure. pub fn close(self: SndFile) void { - _ = sf_close(self.pimpl); + assert(sf_close(self.pimpl) == 0); } }; |