terminal: shuffle some C APIs to make it more long term maintainable
parent
e4e8a61e0c
commit
8a1dc5bd97
|
|
@ -0,0 +1,12 @@
|
|||
pub const osc = @import("osc.zig");
|
||||
|
||||
// The full C API, unexported.
|
||||
pub const osc_new = osc.new;
|
||||
pub const osc_free = osc.free;
|
||||
|
||||
test {
|
||||
_ = osc;
|
||||
|
||||
// We want to make sure we run the tests for the C allocator interface.
|
||||
_ = @import("../../lib/allocator.zig");
|
||||
}
|
||||
|
|
@ -1,22 +1,17 @@
|
|||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const builtin = @import("builtin");
|
||||
const lib_alloc = @import("../lib/allocator.zig");
|
||||
const lib_alloc = @import("../../lib/allocator.zig");
|
||||
const CAllocator = lib_alloc.Allocator;
|
||||
const osc = @import("osc.zig");
|
||||
const osc = @import("../osc.zig");
|
||||
const Result = @import("result.zig").Result;
|
||||
|
||||
/// C: GhosttyOscParser
|
||||
pub const OscParser = ?*osc.Parser;
|
||||
pub const Parser = ?*osc.Parser;
|
||||
|
||||
/// C: GhosttyResult
|
||||
pub const Result = enum(c_int) {
|
||||
success = 0,
|
||||
out_of_memory = -1,
|
||||
};
|
||||
|
||||
pub fn osc_new(
|
||||
pub fn new(
|
||||
alloc_: ?*const CAllocator,
|
||||
result: *OscParser,
|
||||
result: *Parser,
|
||||
) callconv(.c) Result {
|
||||
const alloc = lib_alloc.default(alloc_);
|
||||
const ptr = alloc.create(osc.Parser) catch
|
||||
|
|
@ -26,7 +21,7 @@ pub fn osc_new(
|
|||
return .success;
|
||||
}
|
||||
|
||||
pub fn osc_free(parser_: OscParser) callconv(.c) void {
|
||||
pub fn free(parser_: Parser) callconv(.c) void {
|
||||
// C-built parsers always have an associated allocator.
|
||||
const parser = parser_ orelse return;
|
||||
const alloc = parser.alloc.?;
|
||||
|
|
@ -34,16 +29,12 @@ pub fn osc_free(parser_: OscParser) callconv(.c) void {
|
|||
alloc.destroy(parser);
|
||||
}
|
||||
|
||||
test {
|
||||
_ = lib_alloc;
|
||||
}
|
||||
|
||||
test "osc" {
|
||||
const testing = std.testing;
|
||||
var p: OscParser = undefined;
|
||||
try testing.expectEqual(Result.success, osc_new(
|
||||
var p: Parser = undefined;
|
||||
try testing.expectEqual(Result.success, new(
|
||||
&lib_alloc.test_allocator,
|
||||
&p,
|
||||
));
|
||||
osc_free(p);
|
||||
free(p);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/// C: GhosttyResult
|
||||
pub const Result = enum(c_int) {
|
||||
success = 0,
|
||||
out_of_memory = -1,
|
||||
};
|
||||
|
|
@ -64,7 +64,7 @@ pub const isSafePaste = sanitize.isSafePaste;
|
|||
|
||||
/// This is set to true when we're building the C library.
|
||||
pub const is_c_lib = @import("root") == @import("../lib_vt.zig");
|
||||
pub const c_api = @import("c_api.zig");
|
||||
pub const c_api = @import("c/main.zig");
|
||||
|
||||
test {
|
||||
@import("std").testing.refAllDecls(@This());
|
||||
|
|
|
|||
Loading…
Reference in New Issue