Skip to content

Commit baceb67

Browse files
Rexicon226dnut
andauthored
update to 0.15 (#20)
* update to 0.15 * update CI * update bindings to 0.15 --------- Co-authored-by: Drew Nutter <dnut@users.noreply.github.com>
1 parent c36d983 commit baceb67

File tree

6 files changed

+37
-38
lines changed

6 files changed

+37
-38
lines changed

.github/workflows/check.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
name: check
2-
3-
on: push
4-
1+
on:
2+
pull_request:
3+
push:
4+
branches:
5+
- master
56
jobs:
67
lint:
78
runs-on: ubuntu-latest
@@ -12,7 +13,7 @@ jobs:
1213
- name: setup-zig
1314
uses: mlugg/setup-zig@v2
1415
with:
15-
version: 0.14.1
16+
version: 0.15.2
1617

1718
- name: lint
1819
run: |
@@ -27,13 +28,11 @@ jobs:
2728
steps:
2829
- name: checkout
2930
uses: actions/checkout@v2
30-
with:
31-
submodules: recursive
3231

3332
- name: setup-zig
3433
uses: mlugg/setup-zig@v2
3534
with:
36-
version: 0.14.1
35+
version: 0.15.2
3736

3837
- name: test
3938
run: |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Build and use RocksDB in zig.
22

33
# Build Dependencies
44

5-
`rocksdb-zig` is pinned to [Zig `0.14.1`](https://ziglang.org/download/), so you will need to have it installed.
5+
`rocksdb-zig` is pinned to [Zig `0.15`](https://ziglang.org/download/), so you will need to have it installed.
66

77
# Usage
88

build.zig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ pub fn build(b: *Build) !void {
2222
});
2323
bindings_mod.addImport("rocksdb", rocksdb_mod);
2424

25-
const tests = b.addTest(.{
26-
.target = target,
27-
.optimize = optimize,
28-
.root_source_file = b.path("src/lib.zig"),
29-
});
25+
const tests = b.addTest(.{ .root_module = bindings_mod });
3026
const test_step = b.step("test", "Run bindings tests");
3127
tests.root_module.addImport("rocksdb", rocksdb_mod);
3228
test_step.dependOn(&b.addRunArtifact(tests).step);

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
.name = .rocksdb,
33
.fingerprint = 0xd916a6b24e94f0cf,
44
.version = "9.7.4",
5-
.minimum_zig_version = "0.14.1",
65
.dependencies = .{
76
.rocksdb = .{
87
.url = "git+https://github.com/Syndica/rocksdb#3793e721c7795b338d9d7808544b75db6bde3548",
@@ -14,6 +13,7 @@
1413
.lazy = true,
1514
},
1615
},
16+
.minimum_zig_version = "0.15.0",
1717
.paths = .{
1818
"build.zig",
1919
"build.zig.zon",

src/data.zig

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ const Allocator = std.mem.Allocator;
66
/// data that was allocated by rocksdb and must be freed by rocksdb
77
pub const Data = struct {
88
data: []const u8,
9-
free: *const fn (?*anyopaque) callconv(.C) void,
9+
free: *const fn (?*anyopaque) callconv(.c) void,
1010

11-
pub fn deinit(self: @This()) void {
11+
pub fn deinit(self: Data) void {
1212
self.free(@ptrCast(@constCast(self.data.ptr)));
1313
}
1414

15-
pub fn format(
16-
self: @This(),
17-
comptime _: []const u8,
18-
options: std.fmt.FormatOptions,
19-
writer: anytype,
20-
) !void {
21-
try std.fmt.formatBuf(self.data, options, writer);
15+
pub fn format(self: Data, writer: *std.io.Writer) !void {
16+
try writer.print("{any}", .{self});
2217
}
2318
};
2419

src/database.zig

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,18 @@ pub const DB = struct {
263263
return ri;
264264
}
265265

266-
pub fn liveFiles(self: *const Self, allocator: Allocator) Allocator.Error!std.ArrayList(LiveFile) {
266+
pub fn liveFiles(self: *const Self, allocator: Allocator) Allocator.Error![]const LiveFile {
267267
const files = rdb.rocksdb_livefiles(self.db).?;
268+
defer rdb.rocksdb_livefiles_destroy(files);
268269
const num_files: usize = @intCast(rdb.rocksdb_livefiles_count(files));
269-
var livefiles = std.ArrayList(LiveFile).init(allocator);
270+
271+
var livefiles: std.ArrayList(LiveFile) = .empty;
272+
defer livefiles.deinit(allocator);
273+
270274
var key_size: usize = 0;
271275
for (0..num_files) |i| {
272276
const file_num: c_int = @intCast(i);
273-
try livefiles.append(.{
277+
try livefiles.append(allocator, .{
274278
.allocator = allocator,
275279
.column_family_name = try copy(allocator, rdb.rocksdb_livefiles_column_family_name(files, file_num)),
276280
.name = try copy(allocator, rdb.rocksdb_livefiles_name(files, file_num)),
@@ -282,8 +286,8 @@ pub const DB = struct {
282286
.num_deletions = rdb.rocksdb_livefiles_deletions(files, file_num),
283287
});
284288
}
285-
rdb.rocksdb_livefiles_destroy(files);
286-
return livefiles;
289+
290+
return try livefiles.toOwnedSlice(allocator);
287291
}
288292

289293
pub fn propertyValueCf(
@@ -553,15 +557,17 @@ test DB {
553557
var err_str: ?Data = null;
554558
defer if (err_str) |e| e.deinit();
555559
runTest(&err_str) catch |e| {
556-
std.debug.print("{}: {?}\n", .{ e, err_str });
560+
std.debug.print("{}: {?f}\n", .{ e, err_str });
557561
return e;
558562
};
559563
}
560564

561565
fn runTest(err_str: *?Data) !void {
566+
const allocator = std.testing.allocator;
567+
562568
{
563569
var db, const families = try DB.open(
564-
std.testing.allocator,
570+
allocator,
565571
"test-state",
566572
.{
567573
.create_if_missing = true,
@@ -575,7 +581,7 @@ fn runTest(err_str: *?Data) !void {
575581
err_str,
576582
);
577583
defer db.deinit();
578-
defer std.testing.allocator.free(families);
584+
defer allocator.free(families);
579585
const a_family = families[1].handle;
580586

581587
_ = try db.put(a_family, "hello", "world", err_str);
@@ -601,7 +607,7 @@ fn runTest(err_str: *?Data) !void {
601607
}
602608

603609
var db, const families = try DB.open(
604-
std.testing.allocator,
610+
allocator,
605611
"test-state",
606612
.{
607613
.create_if_missing = true,
@@ -615,9 +621,12 @@ fn runTest(err_str: *?Data) !void {
615621
err_str,
616622
);
617623
defer db.deinit();
618-
defer std.testing.allocator.free(families);
619-
const lfs = try db.liveFiles(std.testing.allocator);
620-
defer lfs.deinit();
621-
defer for (lfs.items) |lf| lf.deinit();
622-
try std.testing.expect(std.mem.eql(u8, "another", lfs.items[0].column_family_name));
624+
defer allocator.free(families);
625+
626+
const lfs = try db.liveFiles(allocator);
627+
defer {
628+
for (lfs) |lf| lf.deinit();
629+
allocator.free(lfs);
630+
}
631+
try std.testing.expect(std.mem.eql(u8, "another", lfs[0].column_family_name));
623632
}

0 commit comments

Comments
 (0)