Trying to fix build issues (SEGV)
Fix minor issues with new decomp types
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
// const use_zig_decomp = b.option(bool, "use_zig_decomp", "Use zig standard library for decompression.") orelse false;
|
||||
// const allow_lzo = b.option(bool, "allow_lzo", "Compile with lzo support") orelse false;
|
||||
const use_zig_decomp = b.option(bool, "use_zig_decomp", "Use zig standard library for decompression.") orelse false;
|
||||
const allow_lzo = b.option(bool, "allow_lzo", "Compile with lzo support") orelse false;
|
||||
var debug = b.option(bool, "debug", "Enable options to make debugging easier.");
|
||||
const version_string_option = b.option([]const u8, "version", "Version of the library/binary");
|
||||
|
||||
// const zig_squashfs_options = b.addOptions();
|
||||
// zig_squashfs_options.addOption(bool, "use_zig_decomp", use_zig_decomp);
|
||||
// zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo);
|
||||
const zig_squashfs_options = b.addOptions();
|
||||
zig_squashfs_options.addOption(bool, "use_zig_decomp", use_zig_decomp);
|
||||
zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo);
|
||||
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
if (optimize == .Debug) debug = true;
|
||||
|
||||
const c = b.addTranslateC(.{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
.root_source_file = b.path("src/c.h"),
|
||||
});
|
||||
|
||||
const lib = b.addLibrary(.{
|
||||
.name = "squashfs",
|
||||
.root_module = b.createModule(.{
|
||||
@@ -22,7 +28,11 @@ pub fn build(b: *std.Build) !void {
|
||||
.target = target,
|
||||
.valgrind = debug,
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.link_libc = true,
|
||||
// .link_libc = true,
|
||||
.imports = &.{
|
||||
.{ .name = "options", .module = zig_squashfs_options.createModule() },
|
||||
.{ .name = "c", .module = c.createModule() },
|
||||
},
|
||||
}),
|
||||
.use_llvm = debug,
|
||||
});
|
||||
@@ -30,12 +40,17 @@ pub fn build(b: *std.Build) !void {
|
||||
const zstd = b.dependency("zstd", .{ .optimize = optimize, .target = target });
|
||||
lib.root_module.linkLibrary(zstd.artifact("zstd"));
|
||||
|
||||
const c = b.addTranslateC(.{
|
||||
.optimize = optimize,
|
||||
.target = target,
|
||||
.root_source_file = b.path("src/c.h"),
|
||||
});
|
||||
lib.root_module.addImport("c", c.createModule());
|
||||
const zng = b.dependency("zlib_ng", .{ .optimize = optimize, .target = target });
|
||||
lib.root_module.linkLibrary(zng.artifact("zng"));
|
||||
|
||||
const xz = b.dependency("xz", .{ .optimize = optimize, .target = target });
|
||||
lib.root_module.linkLibrary(xz.artifact("lzma"));
|
||||
|
||||
const minilzo = b.dependency("minilzo", .{ .optimize = optimize, .target = target });
|
||||
lib.root_module.linkLibrary(minilzo.artifact("minilzo"));
|
||||
|
||||
const lz4 = b.dependency("lz4", .{ .optimize = optimize, .target = target });
|
||||
lib.root_module.linkLibrary(lz4.artifact("lz4"));
|
||||
|
||||
var version = version_string_option orelse "0.0.0-testing";
|
||||
if (version[0] == 'v') version = version[1..];
|
||||
|
||||
@@ -4,7 +4,7 @@ const Writer = Io.Writer;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const config = @import("config");
|
||||
const squashfs = @import("squashfs");
|
||||
const squashfs = @import("zig_squashfs");
|
||||
|
||||
//TODO: Add more options
|
||||
const help_mgs =
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include <zstd.h>
|
||||
#include <zlib-ng.h>
|
||||
#include <lzma.h>
|
||||
#ifdef ALLOW_LZO
|
||||
// #include <lzma.h>
|
||||
#include <lzo/minilzo.h>
|
||||
#endif
|
||||
#include <lz4.h>
|
||||
|
||||
+5
-5
@@ -2,12 +2,12 @@ const std = @import("std");
|
||||
|
||||
const options = @import("options");
|
||||
|
||||
const lzma = @import("decomp/zig_lzma.zig");
|
||||
const xz = @import("decomp/zig_xz.zig");
|
||||
const Decompressor = @import("util/decompressor.zig");
|
||||
|
||||
const zlib = if (options.use_zig_decomp) @import("decomp/zig_zlib.zig") else @import("decomp/c_zlib.zig");
|
||||
const lzma = if (options.use_zig_decomp) @import("decomp/zig_lzma.zig") else @import("decomp/c_lzma.zig");
|
||||
const lzo = if (options.use_zig_decomp or !options.allow_lzo) void else @import("decomp/c_lzo.zig");
|
||||
const xz = if (options.use_zig_decomp) @import("decomp/zig_xz.zig") else @import("decomp/c_xz.zig");
|
||||
const lz4 = if (options.use_zig_decomp) void else @import("decomp/c_lz4.zig");
|
||||
const zstd = if (options.use_zig_decomp) @import("decomp/zig_zstd.zig") else @import("decomp/c_zstd.zig");
|
||||
|
||||
@@ -45,14 +45,14 @@ pub const Decomp = union(enum) {
|
||||
lz4: lz4,
|
||||
zstd: zstd,
|
||||
|
||||
pub fn init(val: Enum, alloc: std.mem.Allocator) !Decomp {
|
||||
pub fn init(val: Enum, alloc: std.mem.Allocator, io: std.Io, block_size: u32) !Decomp {
|
||||
return switch (val) {
|
||||
.gzip => .{ .gzip = zlib.init(alloc) },
|
||||
.gzip => .{ .gzip = zlib.init(alloc, io, block_size) },
|
||||
.lzma => .{ .lzma = .{} },
|
||||
.lzo => .{ .lzo = .{} },
|
||||
.xz => .{ .xz = .{} },
|
||||
.lz4 => .{ .lz4 = .{} },
|
||||
.zstd => .{ .zstd = zstd.init(alloc) },
|
||||
.zstd => .{ .zstd = zstd.init(alloc, io, block_size) },
|
||||
};
|
||||
}
|
||||
pub fn deinit(self: *Decomp) void {
|
||||
|
||||
@@ -8,7 +8,7 @@ const Error = Decompressor.Error;
|
||||
pub const stateless_decompressor: Decompressor = .{ .decomp_fn = statelessDecomp };
|
||||
|
||||
fn statelessDecomp(_: ?*const Decompressor, _: std.mem.Allocator, in: []u8, out: []u8) Error!usize {
|
||||
const res = c.LZ4_decompress_fast(in.ptr, out.ptr, out.len);
|
||||
const res = c.LZ4_decompress_fast(in.ptr, out.ptr, @truncate(out.len));
|
||||
if (res < 0) return Error.ReadFailed;
|
||||
return @abs(res);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ fn decomp(d: ?*const Decompressor, alloc: std.mem.Allocator, in: []u8, out: []u8
|
||||
}
|
||||
var self: *Self = @fieldParentPtr("interface", @constCast(d.?));
|
||||
|
||||
const stream = self.ctx_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
var stream = self.ctx_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
defer self.ctx_queue.putOne(self.io, stream) catch {};
|
||||
|
||||
stream.@"opaque" = @constCast(&alloc);
|
||||
@@ -89,10 +89,10 @@ fn statelessDecomp(_: ?*const Decompressor, alloc: std.mem.Allocator, in: []u8,
|
||||
// zalloc
|
||||
|
||||
fn zalloc(ptr: ?*anyopaque, size: c_uint, len: c_uint) callconv(.c) ?*anyopaque {
|
||||
var alloc: *std.mem.Allocator = @ptrCast(ptr);
|
||||
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(ptr));
|
||||
return alloc.rawAlloc(size * len, .@"1", 0);
|
||||
}
|
||||
fn zfree(ptr: ?*anyopaque, mem_ptr: ?*anyopaque) callconv(.c) void {
|
||||
var alloc: *std.mem.Allocator = @ptrCast(ptr);
|
||||
var alloc: *std.mem.Allocator = @ptrCast(@alignCast(ptr));
|
||||
alloc.rawFree(@ptrCast(mem_ptr), .@"1", 0);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ const c = @import("c");
|
||||
const Decompressor = @import("../util/decompressor.zig");
|
||||
const Error = Decompressor.Error;
|
||||
|
||||
const Queue = std.Io.Queue([]u8);
|
||||
const Queue = std.Io.Queue(?*c.ZSTD_DCtx);
|
||||
|
||||
const Self = @This();
|
||||
|
||||
|
||||
@@ -53,15 +53,15 @@ fn decomp(d: ?*const Decompressor, alloc: std.mem.Allocator, in: []u8, out: []u8
|
||||
}
|
||||
var self: *Self = @fieldParentPtr("interface", @constCast(d.?));
|
||||
|
||||
const buf = self.buf_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
var buf = self.buf_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
defer self.buf_queue.putOne(self.io, buf) catch {};
|
||||
|
||||
return lzmaDecomp(self.alloc, &buf.buf, in, out) catch return Error.ReadFailed;
|
||||
return lzmaDecomp(self.alloc, &buf, in, out) catch return Error.ReadFailed;
|
||||
}
|
||||
|
||||
inline fn lzmaDecomp(alloc: std.mem.Allocator, buffer: *[]u8, in: []u8, out: []u8) !usize {
|
||||
var rdr: Reader = .fixed(in);
|
||||
var d = try lzma.Decompress.initOptions(&rdr, alloc, buffer.*, .{});
|
||||
var d = try lzma.Decompress.initOptions(&rdr, alloc, buffer.*, .{}, in.len * 2);
|
||||
defer {
|
||||
buffer.* = d.takeBuffer();
|
||||
d.deinit();
|
||||
|
||||
@@ -53,10 +53,10 @@ fn decomp(d: ?*const Decompressor, alloc: std.mem.Allocator, in: []u8, out: []u8
|
||||
}
|
||||
var self: *Self = @fieldParentPtr("interface", @constCast(d.?));
|
||||
|
||||
const buf = self.buf_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
var buf = self.buf_queue.getOne(self.io) catch return Error.ReadFailed;
|
||||
defer self.buf_queue.putOne(self.io, buf) catch {};
|
||||
|
||||
return xzDecomp(self.alloc, &buf.buf, in, out) catch return Error.ReadFailed;
|
||||
return xzDecomp(self.alloc, &buf, in, out) catch return Error.ReadFailed;
|
||||
}
|
||||
|
||||
inline fn xzDecomp(alloc: std.mem.Allocator, buffer: *[]u8, in: []u8, out: []u8) !usize {
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ pub fn extract(
|
||||
) !void {
|
||||
const path = std.mem.trimEnd(u8, filepath, "/");
|
||||
|
||||
var decomp_base: Decomp = .init(super.compression, alloc);
|
||||
var decomp_base: Decomp = try .init(super.compression, alloc, io, super.block_size);
|
||||
const decomp = decomp_base.decompressor();
|
||||
|
||||
var frag_mgr: FragManager = try .init(alloc, fil, decomp, super.frag_start, super.frag_count, super.block_size);
|
||||
|
||||
Reference in New Issue
Block a user