Skip to content

Commit bf4e791

Browse files
committed
G2(partial): instantiate panel-clades Zig FFI {{project}}->panel_clades
Consistency fix (the exact thing Axiom got wrong): build.zig + integration_test.zig now use panel_clades_* matching main.zig exports and Foreign.idr (C:panel_clades_*, libpanel_clades). Remaining: same mechanical Zig-0.15 drift class as Axiom (addSharedLibrary->addLibrary, callconv(.C)->.c, opaque-with-fields) — tracked, not yet applied.
1 parent 092fe00 commit bf4e791

2 files changed

Lines changed: 48 additions & 48 deletions

File tree

panel-clades/ffi/zig/build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void {
99

1010
// Shared library (.so, .dylib, .dll)
1111
const lib = b.addSharedLibrary(.{
12-
.name = "{{project}}",
12+
.name = "panel_clades",
1313
.root_source_file = b.path("src/main.zig"),
1414
.target = target,
1515
.optimize = optimize,
@@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void {
2020

2121
// Static library (.a)
2222
const lib_static = b.addStaticLibrary(.{
23-
.name = "{{project}}",
23+
.name = "panel_clades",
2424
.root_source_file = b.path("src/main.zig"),
2525
.target = target,
2626
.optimize = optimize,
@@ -32,8 +32,8 @@ pub fn build(b: *std.Build) void {
3232

3333
// Generate header file for C compatibility
3434
const header = b.addInstallHeader(
35-
b.path("include/{{project}}.h"),
36-
"{{project}}.h",
35+
b.path("include/panel_clades.h"),
36+
"panel_clades.h",
3737
);
3838
b.getInstallStep().dependOn(&header.step);
3939

@@ -79,7 +79,7 @@ pub fn build(b: *std.Build) void {
7979

8080
// Benchmark (if needed)
8181
const bench = b.addExecutable(.{
82-
.name = "{{project}}-bench",
82+
.name = "panel_clades-bench",
8383
.root_source_file = b.path("bench/bench.zig"),
8484
.target = target,
8585
.optimize = .ReleaseFast,

panel-clades/ffi/zig/test/integration_test.zig

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ const std = @import("std");
77
const testing = std.testing;
88

99
// Import FFI functions
10-
extern fn {{project}}_init() ?*opaque {};
11-
extern fn {{project}}_free(?*opaque {}) void;
12-
extern fn {{project}}_process(?*opaque {}, u32) c_int;
13-
extern fn {{project}}_get_string(?*opaque {}) ?[*:0]const u8;
14-
extern fn {{project}}_free_string(?[*:0]const u8) void;
15-
extern fn {{project}}_last_error() ?[*:0]const u8;
16-
extern fn {{project}}_version() [*:0]const u8;
17-
extern fn {{project}}_is_initialized(?*opaque {}) u32;
10+
extern fn panel_clades_init() ?*opaque {};
11+
extern fn panel_clades_free(?*opaque {}) void;
12+
extern fn panel_clades_process(?*opaque {}, u32) c_int;
13+
extern fn panel_clades_get_string(?*opaque {}) ?[*:0]const u8;
14+
extern fn panel_clades_free_string(?[*:0]const u8) void;
15+
extern fn panel_clades_last_error() ?[*:0]const u8;
16+
extern fn panel_clades_version() [*:0]const u8;
17+
extern fn panel_clades_is_initialized(?*opaque {}) u32;
1818

1919
//==============================================================================
2020
// Lifecycle Tests
2121
//==============================================================================
2222

2323
test "create and destroy handle" {
24-
const handle = {{project}}_init() orelse return error.InitFailed;
25-
defer {{project}}_free(handle);
24+
const handle = panel_clades_init() orelse return error.InitFailed;
25+
defer panel_clades_free(handle);
2626

2727
try testing.expect(handle != null);
2828
}
2929

3030
test "handle is initialized" {
31-
const handle = {{project}}_init() orelse return error.InitFailed;
32-
defer {{project}}_free(handle);
31+
const handle = panel_clades_init() orelse return error.InitFailed;
32+
defer panel_clades_free(handle);
3333

34-
const initialized = {{project}}_is_initialized(handle);
34+
const initialized = panel_clades_is_initialized(handle);
3535
try testing.expectEqual(@as(u32, 1), initialized);
3636
}
3737

3838
test "null handle is not initialized" {
39-
const initialized = {{project}}_is_initialized(null);
39+
const initialized = panel_clades_is_initialized(null);
4040
try testing.expectEqual(@as(u32, 0), initialized);
4141
}
4242

@@ -45,15 +45,15 @@ test "null handle is not initialized" {
4545
//==============================================================================
4646

4747
test "process with valid handle" {
48-
const handle = {{project}}_init() orelse return error.InitFailed;
49-
defer {{project}}_free(handle);
48+
const handle = panel_clades_init() orelse return error.InitFailed;
49+
defer panel_clades_free(handle);
5050

51-
const result = {{project}}_process(handle, 42);
51+
const result = panel_clades_process(handle, 42);
5252
try testing.expectEqual(@as(c_int, 0), result); // 0 = ok
5353
}
5454

5555
test "process with null handle returns error" {
56-
const result = {{project}}_process(null, 42);
56+
const result = panel_clades_process(null, 42);
5757
try testing.expectEqual(@as(c_int, 4), result); // 4 = null_pointer
5858
}
5959

@@ -62,17 +62,17 @@ test "process with null handle returns error" {
6262
//==============================================================================
6363

6464
test "get string result" {
65-
const handle = {{project}}_init() orelse return error.InitFailed;
66-
defer {{project}}_free(handle);
65+
const handle = panel_clades_init() orelse return error.InitFailed;
66+
defer panel_clades_free(handle);
6767

68-
const str = {{project}}_get_string(handle);
69-
defer if (str) |s| {{project}}_free_string(s);
68+
const str = panel_clades_get_string(handle);
69+
defer if (str) |s| panel_clades_free_string(s);
7070

7171
try testing.expect(str != null);
7272
}
7373

7474
test "get string with null handle" {
75-
const str = {{project}}_get_string(null);
75+
const str = panel_clades_get_string(null);
7676
try testing.expect(str == null);
7777
}
7878

@@ -81,9 +81,9 @@ test "get string with null handle" {
8181
//==============================================================================
8282

8383
test "last error after null handle operation" {
84-
_ = {{project}}_process(null, 0);
84+
_ = panel_clades_process(null, 0);
8585

86-
const err = {{project}}_last_error();
86+
const err = panel_clades_last_error();
8787
try testing.expect(err != null);
8888

8989
if (err) |e| {
@@ -93,10 +93,10 @@ test "last error after null handle operation" {
9393
}
9494

9595
test "no error after successful operation" {
96-
const handle = {{project}}_init() orelse return error.InitFailed;
97-
defer {{project}}_free(handle);
96+
const handle = panel_clades_init() orelse return error.InitFailed;
97+
defer panel_clades_free(handle);
9898

99-
_ = {{project}}_process(handle, 0);
99+
_ = panel_clades_process(handle, 0);
100100

101101
// Error should be cleared after successful operation
102102
// (This depends on implementation)
@@ -107,14 +107,14 @@ test "no error after successful operation" {
107107
//==============================================================================
108108

109109
test "version string is not empty" {
110-
const ver = {{project}}_version();
110+
const ver = panel_clades_version();
111111
const ver_str = std.mem.span(ver);
112112

113113
try testing.expect(ver_str.len > 0);
114114
}
115115

116116
test "version string is semantic version format" {
117-
const ver = {{project}}_version();
117+
const ver = panel_clades_version();
118118
const ver_str = std.mem.span(ver);
119119

120120
// Should be in format X.Y.Z
@@ -126,37 +126,37 @@ test "version string is semantic version format" {
126126
//==============================================================================
127127

128128
test "multiple handles are independent" {
129-
const h1 = {{project}}_init() orelse return error.InitFailed;
130-
defer {{project}}_free(h1);
129+
const h1 = panel_clades_init() orelse return error.InitFailed;
130+
defer panel_clades_free(h1);
131131

132-
const h2 = {{project}}_init() orelse return error.InitFailed;
133-
defer {{project}}_free(h2);
132+
const h2 = panel_clades_init() orelse return error.InitFailed;
133+
defer panel_clades_free(h2);
134134

135135
try testing.expect(h1 != h2);
136136

137137
// Operations on h1 should not affect h2
138-
_ = {{project}}_process(h1, 1);
139-
_ = {{project}}_process(h2, 2);
138+
_ = panel_clades_process(h1, 1);
139+
_ = panel_clades_process(h2, 2);
140140
}
141141

142142
test "double free is safe" {
143-
const handle = {{project}}_init() orelse return error.InitFailed;
143+
const handle = panel_clades_init() orelse return error.InitFailed;
144144

145-
{{project}}_free(handle);
146-
{{project}}_free(handle); // Should not crash
145+
panel_clades_free(handle);
146+
panel_clades_free(handle); // Should not crash
147147
}
148148

149149
test "free null is safe" {
150-
{{project}}_free(null); // Should not crash
150+
panel_clades_free(null); // Should not crash
151151
}
152152

153153
//==============================================================================
154154
// Thread Safety Tests (if applicable)
155155
//==============================================================================
156156

157157
test "concurrent operations" {
158-
const handle = {{project}}_init() orelse return error.InitFailed;
159-
defer {{project}}_free(handle);
158+
const handle = panel_clades_init() orelse return error.InitFailed;
159+
defer panel_clades_free(handle);
160160

161161
const ThreadContext = struct {
162162
h: *opaque {},
@@ -165,7 +165,7 @@ test "concurrent operations" {
165165

166166
const thread_fn = struct {
167167
fn run(ctx: ThreadContext) void {
168-
_ = {{project}}_process(ctx.h, ctx.id);
168+
_ = panel_clades_process(ctx.h, ctx.id);
169169
}
170170
}.run;
171171

0 commit comments

Comments
 (0)