1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
const builtin = @import("builtin");
const std = @import("std");
pub const png = @import("png.zig");
pub const jpeg = @import("jpeg.zig");
pub const swizzle = @import("swizzle.zig");
pub const Error = @import("error.zig").Error;
/// The maximum image size, based on the 4G limit of Ghostty's
/// `image-storage-limit` config.
pub const maximum_image_size = 4 * 1024 * 1024 * 1024;
pub const ImageData = struct {
width: u32,
height: u32,
data: []u8,
};
// Wuffs' generated `wuffs_foo__bar__alloc()` convenience functions are the
// only code that references libc's calloc/free. We never call them
// and linker garbage collection strips them, but that isn't guaranteed.
// Freestanding consumers may have no allocator to resolve these symbols.
// Never export stubs for hosted targets: hidden weak symbols in a static
// archive can override the embedding executable's dynamically linked libc.
comptime {
if (!builtin.link_libc and builtin.os.tag == .freestanding) {
@export(&callocStub, .{
.name = "calloc",
.linkage = .weak,
.visibility = .hidden,
});
@export(&freeStub, .{
.name = "free",
.linkage = .weak,
.visibility = .hidden,
});
}
}
fn callocStub(count: usize, size: usize) callconv(.c) ?*anyopaque {
_ = count;
_ = size;
return null;
}
fn freeStub(ptr: ?*anyopaque) callconv(.c) void {
_ = ptr;
}
test {
refAllDeclsRecursive(@This());
}
/// Copied from 0.15.2 stdlib (MIT license).
fn refAllDeclsRecursive(comptime T: type) void {
if (!builtin.is_test) return;
inline for (comptime std.meta.declarations(T)) |decl| {
if (@TypeOf(@field(T, decl.name)) == type) {
switch (@typeInfo(@field(T, decl.name))) {
.@"struct", .@"enum", .@"union", .@"opaque" => refAllDeclsRecursive(@field(T, decl.name)),
else => {},
}
}
_ = &@field(T, decl.name);
}
}
|