clickingbuttons / flatbuffers-zig Goto Github PK
View Code? Open in Web Editor NEWFlatbuffers zig implementation
License: MIT No Attribution
Flatbuffers zig implementation
License: MIT No Attribution
Use Zig error handling instead of runtime-dependent behavior everywhere there's an @intCast
According to a Flatbuffers maintainer (and the reference C++ impl) cyclical referencing tables are possible.
This means for the object API this:
const Foo = struct {
foo: ?Foo,
};
should change to this:
const Foo = struct {
foo: ?*Foo,
};
and the init
allocations should change too.
The flatc-zig
compiler has issues when handling any table containing a union (possibly works with other types) and does not allocate memory. For instance, this snippet reproduces the error:
struct Foo {
foo: ubyte;
}
union Bar { Foo }
table Baz {
bar: Bar;
}
But this one does not:
struct Foo {
foo: ubyte;
}
union Bar { Foo }
table Baz {
bar: Bar;
fix: string;
}
The error message is as follows (including the invocation and shell output stating that this is, in fact, a core dump):
[enderger] ( impure (nix-shell-env)) ✘!+? master
…/kings-court/proto λ > ../client/flatc-zig -i tmp -o tmp
debug(flatbuffers): file_ident=//ice.fbs n_enums=1 n_objs=2
thread 3204581 panic: index out of bounds: index 1, len 1
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/codegen/writer.zig:759:39: 0x255272 in writeObjectInitFn (flatc-zig)
args.items[1].name,
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/codegen/writer.zig:981:43: 0x2599dd in writeObject__anon_9174 (flatc-zig)
try self.writeObjectInitFn(object, has_allocations, packed_name);
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/codegen/writer.zig:1203:55: 0x25c702 in write__anon_9113 (flatc-zig)
const unpacked_name = try self.writeObject(obj_or_enum, false);
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/codegen/codegen.zig:91:30: 0x266e05 in writeFiles__anon_9880 (flatc-zig)
try code_writer.write(obj);
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/codegen/codegen.zig:178:23: 0x268039 in codegen (flatc-zig)
try writeFiles(allocator, opts, prelude, schema, .object);
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/main.zig:36:28: 0x269495 in walk (flatc-zig)
try codegen.codegen(allocator, fbs_path, genned_bytes, opts);
^
/home/enderger/.cache/zig/p/122052b2f5bbffae771464571e74e9750d584aa0f15b4af411ad94fa7fc935967781/src/main.zig:72:13: 0x269eb0 in main (flatc-zig)
try walk(codegen.Options{
^
/nix/store/5j4g5igs5ral691mfrhnmpar5br1xxrs-zig-0.11.0-dev.4002+7dd1cf26f/lib/std/start.zig:608:37: 0x237814 in posixCallMainAndExit (flatc-zig)
const result = root.main() catch |err| {
^
/nix/store/5j4g5igs5ral691mfrhnmpar5br1xxrs-zig-0.11.0-dev.4002+7dd1cf26f/lib/std/start.zig:367:5: 0x237301 in _start (flatc-zig)
@call(.never_inline, posixCallMainAndExit, .{});
^
Aborted: oops, process '../client/flatc-zig' core dumped
Error: nu::shell::external_command
× External command failed
╭─[entry #17:1:1]
1 │ ../client/flatc-zig -i tmp -o tmp
· ─────────┬─────────
· ╰── core dumped
╰────
help: Aborted: child process '../client/flatc-zig' core dumped
The error is caused by the unchecked access of the allocator argument in the code generator for the initializer of the union
type.
Move Table to AdvancedTable(comptime mutable: bool) type
with flatbuffer: if (mutable) []u8 else []const u8
. Make pub const Table = AdvancedTable(false);
and pub const MutableTable = AdvancedTable(true);
(with mixed in setter methods).
Then codegen setters for the following types:
Cache vtable duplicates. Truncate trailing default fields.
Preferably ignore them as much as possible. Not sure if naming collisions are possible.
The URL provided in the README for instalation:
"https://github.com/clickingbuttons/flatbuffers-zig/archive/refs/tags/latest-release.tar.gz"
returns 404 code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.