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");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
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 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 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.");
|
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 version_string_option = b.option([]const u8, "version", "Version of the library/binary");
|
||||||
|
|
||||||
// const zig_squashfs_options = b.addOptions();
|
const zig_squashfs_options = b.addOptions();
|
||||||
// zig_squashfs_options.addOption(bool, "use_zig_decomp", use_zig_decomp);
|
zig_squashfs_options.addOption(bool, "use_zig_decomp", use_zig_decomp);
|
||||||
// zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo);
|
zig_squashfs_options.addOption(bool, "allow_lzo", allow_lzo);
|
||||||
|
|
||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
if (optimize == .Debug) debug = true;
|
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(.{
|
const lib = b.addLibrary(.{
|
||||||
.name = "squashfs",
|
.name = "squashfs",
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
@@ -22,7 +28,11 @@ pub fn build(b: *std.Build) !void {
|
|||||||
.target = target,
|
.target = target,
|
||||||
.valgrind = debug,
|
.valgrind = debug,
|
||||||
.root_source_file = b.path("src/root.zig"),
|
.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,
|
.use_llvm = debug,
|
||||||
});
|
});
|
||||||
@@ -30,12 +40,17 @@ pub fn build(b: *std.Build) !void {
|
|||||||
const zstd = b.dependency("zstd", .{ .optimize = optimize, .target = target });
|
const zstd = b.dependency("zstd", .{ .optimize = optimize, .target = target });
|
||||||
lib.root_module.linkLibrary(zstd.artifact("zstd"));
|
lib.root_module.linkLibrary(zstd.artifact("zstd"));
|
||||||
|
|
||||||
const c = b.addTranslateC(.{
|
const zng = b.dependency("zlib_ng", .{ .optimize = optimize, .target = target });
|
||||||
.optimize = optimize,
|
lib.root_module.linkLibrary(zng.artifact("zng"));
|
||||||
.target = target,
|
|
||||||
.root_source_file = b.path("src/c.h"),
|
const xz = b.dependency("xz", .{ .optimize = optimize, .target = target });
|
||||||
});
|
lib.root_module.linkLibrary(xz.artifact("lzma"));
|
||||||
lib.root_module.addImport("c", c.createModule());
|
|
||||||
|
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";
|
var version = version_string_option orelse "0.0.0-testing";
|
||||||
if (version[0] == 'v') version = version[1..];
|
if (version[0] == 'v') version = version[1..];
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const Writer = Io.Writer;
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
const config = @import("config");
|
const config = @import("config");
|
||||||
const squashfs = @import("squashfs");
|
const squashfs = @import("zig_squashfs");
|
||||||
|
|
||||||
//TODO: Add more options
|
//TODO: Add more options
|
||||||
const help_mgs =
|
const help_mgs =
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <zstd.h>
|
#include <zstd.h>
|
||||||
#include <zlib-ng.h>
|
#include <zlib-ng.h>
|
||||||
#include <lzma.h>
|
// #include <lzma.h>
|
||||||
#ifdef ALLOW_LZO
|
|
||||||
#include <lzo/minilzo.h>
|
#include <lzo/minilzo.h>
|
||||||
#endif
|
|
||||||
#include <lz4.h>
|
#include <lz4.h>
|
||||||
|
|||||||
+5
-5
@@ -2,12 +2,12 @@ const std = @import("std");
|
|||||||
|
|
||||||
const options = @import("options");
|
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 Decompressor = @import("util/decompressor.zig");
|
||||||
|
|
||||||
const zlib = if (options.use_zig_decomp) @import("decomp/zig_zlib.zig") else @import("decomp/c_zlib.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 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 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");
|
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,
|
lz4: lz4,
|
||||||
zstd: zstd,
|
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) {
|
return switch (val) {
|
||||||
.gzip => .{ .gzip = zlib.init(alloc) },
|
.gzip => .{ .gzip = zlib.init(alloc, io, block_size) },
|
||||||
.lzma => .{ .lzma = .{} },
|
.lzma => .{ .lzma = .{} },
|
||||||
.lzo => .{ .lzo = .{} },
|
.lzo => .{ .lzo = .{} },
|
||||||
.xz => .{ .xz = .{} },
|
.xz => .{ .xz = .{} },
|
||||||
.lz4 => .{ .lz4 = .{} },
|
.lz4 => .{ .lz4 = .{} },
|
||||||
.zstd => .{ .zstd = zstd.init(alloc) },
|
.zstd => .{ .zstd = zstd.init(alloc, io, block_size) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn deinit(self: *Decomp) void {
|
pub fn deinit(self: *Decomp) void {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const Error = Decompressor.Error;
|
|||||||
pub const stateless_decompressor: Decompressor = .{ .decomp_fn = statelessDecomp };
|
pub const stateless_decompressor: Decompressor = .{ .decomp_fn = statelessDecomp };
|
||||||
|
|
||||||
fn statelessDecomp(_: ?*const Decompressor, _: std.mem.Allocator, in: []u8, out: []u8) Error!usize {
|
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;
|
if (res < 0) return Error.ReadFailed;
|
||||||
return @abs(res);
|
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.?));
|
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 {};
|
defer self.ctx_queue.putOne(self.io, stream) catch {};
|
||||||
|
|
||||||
stream.@"opaque" = @constCast(&alloc);
|
stream.@"opaque" = @constCast(&alloc);
|
||||||
@@ -89,10 +89,10 @@ fn statelessDecomp(_: ?*const Decompressor, alloc: std.mem.Allocator, in: []u8,
|
|||||||
// zalloc
|
// zalloc
|
||||||
|
|
||||||
fn zalloc(ptr: ?*anyopaque, size: c_uint, len: c_uint) callconv(.c) ?*anyopaque {
|
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);
|
return alloc.rawAlloc(size * len, .@"1", 0);
|
||||||
}
|
}
|
||||||
fn zfree(ptr: ?*anyopaque, mem_ptr: ?*anyopaque) callconv(.c) void {
|
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);
|
alloc.rawFree(@ptrCast(mem_ptr), .@"1", 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const c = @import("c");
|
|||||||
const Decompressor = @import("../util/decompressor.zig");
|
const Decompressor = @import("../util/decompressor.zig");
|
||||||
const Error = Decompressor.Error;
|
const Error = Decompressor.Error;
|
||||||
|
|
||||||
const Queue = std.Io.Queue([]u8);
|
const Queue = std.Io.Queue(?*c.ZSTD_DCtx);
|
||||||
|
|
||||||
const Self = @This();
|
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.?));
|
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 {};
|
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 {
|
inline fn lzmaDecomp(alloc: std.mem.Allocator, buffer: *[]u8, in: []u8, out: []u8) !usize {
|
||||||
var rdr: Reader = .fixed(in);
|
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 {
|
defer {
|
||||||
buffer.* = d.takeBuffer();
|
buffer.* = d.takeBuffer();
|
||||||
d.deinit();
|
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.?));
|
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 {};
|
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 {
|
inline fn xzDecomp(alloc: std.mem.Allocator, buffer: *[]u8, in: []u8, out: []u8) !usize {
|
||||||
|
|||||||
+1
-1
@@ -275,7 +275,7 @@ pub fn extract(
|
|||||||
) !void {
|
) !void {
|
||||||
const path = std.mem.trimEnd(u8, filepath, "/");
|
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();
|
const decomp = decomp_base.decompressor();
|
||||||
|
|
||||||
var frag_mgr: FragManager = try .init(alloc, fil, decomp, super.frag_start, super.frag_count, super.block_size);
|
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