Skip to content

Commit 30070dd

Browse files
authored
Merge pull request #5 from zig-java/zig-master
Changes in std.mem.Allocator interface
2 parents 1c69442 + 72539d9 commit 30070dd

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

src/descriptors.zig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const jui = @import("jui.zig");
23

34
pub const MethodDescriptor = struct {
45
const Self = @This();
@@ -169,7 +170,17 @@ fn parse_(allocator: std.mem.Allocator, reader: anytype) anyerror!?*Descriptor {
169170
var returnd = (try parse_(allocator, reader)).?;
170171

171172
var x = try allocator.create(Descriptor);
172-
x.* = .{ .method = .{ .parameters = params.toOwnedSlice(), .return_type = returnd } };
173+
x.* = if (jui.is_zig_master) .{
174+
.method = .{
175+
.parameters = try params.toOwnedSlice(),
176+
.return_type = returnd,
177+
},
178+
} else .{
179+
.method = .{
180+
.parameters = params.toOwnedSlice(),
181+
.return_type = returnd,
182+
},
183+
};
173184
return x;
174185
},
175186
')' => return null,

src/jui.zig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ pub const descriptors = @import("descriptors.zig");
55
pub const Reflector = @import("Reflector.zig");
66
const types = @import("types.zig");
77

8-
// Some break changes in zig 0.10.0-dev
9-
// This code must be removed once the 0.10 was released
10-
const is_zig_master = builtin.zig_version.major >= 0 and builtin.zig_version.minor >= 10;
8+
// We support Zig 0.9.1 (old stable), 0.10.0 (current stable) and 0.11.0-dev (latest master).
9+
// We also support both stage1 and stage2 compilers.
10+
// This can be simplified once we drop support for Zig 0.9.1 and stage1:
11+
pub const is_zig_9_1 = builtin.zig_version.major >= 0 and builtin.zig_version.minor == 9;
12+
pub const is_zig_master = builtin.zig_version.major >= 0 and builtin.zig_version.minor >= 11;
13+
pub const is_stage2 = @hasDecl(builtin, "zig_backend") and builtin.zig_backend != .stage1;
1114

1215
pub usingnamespace types;
1316

src/types.zig

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
const std = @import("std");
55
const builtin = @import("builtin");
6-
7-
// builtin.zig_backend decl exists
8-
// This code must be removed once the 0.9.1 support is not necessary.
9-
const is_stage2 = @hasDecl(builtin, "zig_backend") and builtin.zig_backend != .stage1;
6+
const jui = @import("jui.zig");
107

118
/// Stolen from https://github.com/ziglang/zig/pull/6272
129
/// [1]extern struct isn't allowed, see https://github.com/ziglang/zig/issues/6535
@@ -231,7 +228,7 @@ pub const JNINativeMethod = extern struct {
231228
// Instead of using std.meta.FnPtr for each declaration,
232229
// Just duplicating all structs here, with fn(..) and *const fn
233230
// This way it's easier to just delete when stage1 was removed
234-
const JNINativeInterface = if (is_stage2)
231+
const JNINativeInterface = if (jui.is_stage2)
235232
extern struct {
236233
reserved0: ?*anyopaque,
237234
reserved1: ?*anyopaque,
@@ -711,7 +708,7 @@ else
711708
// Instead of using std.meta.FnPtr for each declaration,
712709
// Just duplicating all structs here, with fn(..) and *const fn
713710
// This way it's easier to just delete when stage1 was removed
714-
const JNIInvokeInterface = if (is_stage2)
711+
const JNIInvokeInterface = if (jui.is_stage2)
715712
extern struct {
716713
reserved0: ?*anyopaque,
717714
reserved1: ?*anyopaque,

0 commit comments

Comments
 (0)