Skip to content

Commit 144c19e

Browse files
Antigravity Agentclaude
andcommitted
fix(multi): errdefer memory safety in data.zig + bitnet_loader, patent strategy update, zenodo tests
- data.zig: errdefer on Batch.init allocations - bitnet_loader.zig: errdefer on shape/name/dtype allocations - tri_patent.zig: defensive publication strategy with CPC codes - tri_zenodo.zig: add json_escape and update_records tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0d01582 commit 144c19e

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

src/hslm/data.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ pub const Batch = struct {
2828

2929
pub fn init(allocator: std.mem.Allocator, batch_size: usize, seq_len: usize) !Self {
3030
const total = batch_size * seq_len;
31+
const inputs = try allocator.alloc(u16, total);
32+
errdefer allocator.free(inputs);
33+
const targets = try allocator.alloc(u16, total);
3134
return Self{
32-
.inputs = try allocator.alloc(u16, total),
33-
.targets = try allocator.alloc(u16, total),
35+
.inputs = inputs,
36+
.targets = targets,
3437
.batch_size = batch_size,
3538
.seq_len = seq_len,
3639
.allocator = allocator,

src/tri/tri_patent.zig

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -228,27 +228,31 @@ fn showClaims(filter: []const u8) void {
228228
// ═══════════════════════════════════════════════════════════════════════════════
229229

230230
fn showStrategy() void {
231-
print("\n{s}{s}PATENT FILING STRATEGY{s}\n", .{ BOLD, GOLDEN, RESET });
231+
print("\n{s}{s}PATENT & DEFENSIVE PUBLICATION STRATEGY{s}\n", .{ BOLD, GOLDEN, RESET });
232232
print("{s}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{s}\n\n", .{ GRAY, RESET });
233233

234-
print(" {s}PHASE 1: PROVISIONAL (IMMEDIATE){s}\n", .{ GREEN, RESET });
234+
print(" {s}DEFENSIVE PUBLICATIONS (ACTIVE){s}\n", .{ GREEN, RESET });
235+
print(" {s}──────────────────────────────────{s}\n", .{ GRAY, RESET });
236+
print(" All 7 discoveries published as rich defensive publications on Zenodo.\n", .{});
237+
print(" Each includes: Problem + Technical Disclosure + Evidence + Prior Art\n", .{});
238+
print(" + Picket Fence extensions + CPC codes + cross-references.\n", .{});
239+
print(" {s}Run: tri zenodo update [D001-D007]{s}\n\n", .{ CYAN, RESET });
240+
241+
print(" {s}CPC CLASSIFICATIONS{s}\n", .{ GOLDEN, RESET });
242+
print(" {s}───────────────────{s}\n", .{ GRAY, RESET });
243+
print(" D001-D003: H03K19/20, G06F30/34, G06N3/04, G06F7/544\n", .{});
244+
print(" D004: G06F8/65, G06N20/00, G06F11/36\n", .{});
245+
print(" D005: G06F7/72, G06N3/04, G06F17/16\n", .{});
246+
print(" D006: G06N3/0455, G06F17/14, G06N3/084\n", .{});
247+
print(" D007: G06F7/544, G06F7/72, G06F17/16\n\n", .{});
248+
249+
print(" {s}PHASE 1: PROVISIONAL (OPTIONAL){s}\n", .{ YELLOW, RESET });
235250
print(" {s}──────────────────────────────────{s}\n", .{ GRAY, RESET });
236251
print(" P1 Resonance + Square Attention CRITICAL $2,000-3,000\n", .{});
237252
print(" P2 Zero-DSP FPGA Inference CRITICAL $2,000-3,000\n", .{});
238253
print(" P3 Self-Evolving Ouroboros HIGH $1,500-2,500\n", .{});
239254
print(" {s}Provisionals give 12 months priority date.{s}\n\n", .{ CYAN, RESET });
240255

241-
print(" {s}PHASE 2: FULL UTILITY (6-9 months){s}\n", .{ YELLOW, RESET });
242-
print(" {s}────────────────────────────────────{s}\n", .{ GRAY, RESET });
243-
print(" Convert P1, P2 to full utility patents\n", .{});
244-
print(" Add dependent claims (VSA, sparse matmul, phi-RoPE)\n", .{});
245-
print(" File with USPTO $15,000-25,000\n\n", .{});
246-
247-
print(" {s}PHASE 3: PCT INTERNATIONAL (12 months){s}\n", .{ YELLOW, RESET });
248-
print(" {s}───────────────────────────────────────{s}\n", .{ GRAY, RESET });
249-
print(" Markets: US, EU (EPO), China (CNIPA), Japan, Korea\n", .{});
250-
print(" Per jurisdiction: $3,000-5,000 $30,000-50,000\n\n", .{});
251-
252256
print(" {s}TOTAL BUDGET{s}\n", .{ GOLDEN, RESET });
253257
print(" {s}────────────{s}\n", .{ GRAY, RESET });
254258
print(" Phase 1 (provisionals): $5,500 - $8,500\n", .{});
@@ -258,17 +262,13 @@ fn showStrategy() void {
258262

259263
print(" {s}DEFENSE STRENGTHS{s}\n", .{ GREEN, RESET });
260264
print(" {s}─────────────────{s}\n", .{ GRAY, RESET });
261-
print(" 1. Zenodo DOI 10.5281/zenodo.18939352 (2026-03-10) — prior art\n", .{});
262-
print(" 2. 42 Railway services — reproducible experiments\n", .{});
263-
print(" 3. Open-source Yosys toolchain — FPGA results reproducible\n", .{});
264-
print(" 4. Published papers in papers/hslm/ and papers/trinity-fpga/\n", .{});
265-
print(" 5. Full git history — every experiment documented\n\n", .{});
266-
267-
print(" {s}RISKS{s}\n", .{ RED, RESET });
268-
print(" {s}─────{s}\n", .{ GRAY, RESET });
269-
print(" 101 rejection (Ouroboros) — mitigate with concrete metrics\n", .{});
270-
print(" Obviousness (0-DSP) — TerEffic 2025 uses 3,041 DSP\n", .{});
271-
print(" Prior art (VSA) — Kanerva 2009 but not ternary+SIMD\n\n", .{});
265+
print(" 1. 7 Zenodo DOIs with rich defensive publication descriptions\n", .{});
266+
print(" 2. CPC-classified for patent examiner discoverability\n", .{});
267+
print(" 3. Cross-referenced DOI graph (all 5 records linked)\n", .{});
268+
print(" 4. Picket fence extensions block trivial variations\n", .{});
269+
print(" 5. 42 Railway services — reproducible experiments\n", .{});
270+
print(" 6. Open-source Yosys toolchain — FPGA results reproducible\n", .{});
271+
print(" 7. Full git history — every experiment documented\n\n", .{});
272272
}
273273

274274
// ═══════════════════════════════════════════════════════════════════════════════

src/tri/tri_zenodo.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,19 @@ test "token load from env" {
846846
// Expected when no token set
847847
}
848848
}
849+
850+
test "json_escape_string" {
851+
const allocator = std.testing.allocator;
852+
const escaped = try jsonEscapeString(allocator, "hello \"world\"\nnew line");
853+
defer allocator.free(escaped);
854+
try std.testing.expectEqualStrings("hello \\\"world\\\"\\nnew line", escaped);
855+
}
856+
857+
test "update_records_table_valid" {
858+
for (update_records) |rec| {
859+
try std.testing.expect(rec.id.len > 0);
860+
try std.testing.expect(rec.zenodo_id.len > 0);
861+
try std.testing.expect(rec.file.len > 0);
862+
}
863+
try std.testing.expectEqual(@as(usize, 5), update_records.len);
864+
}

src/vibeec/bitnet_loader.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ pub const SafetensorsHeader = struct {
8585

8686
// Get shape
8787
const shape_arr = tensor_obj.get("shape").?.array;
88-
var shape = try allocator.alloc(i64, shape_arr.items.len);
88+
const shape = try allocator.alloc(i64, shape_arr.items.len);
89+
errdefer allocator.free(shape);
8990
for (shape_arr.items, 0..) |item, i| {
9091
shape[i] = item.integer;
9192
}
@@ -99,8 +100,11 @@ pub const SafetensorsHeader = struct {
99100

100101
// Store tensor info
101102
const name_copy = try allocator.dupe(u8, name);
103+
errdefer allocator.free(name_copy);
104+
const dtype_copy = try allocator.dupe(u8, dtype);
105+
errdefer allocator.free(dtype_copy);
102106
try tensors.put(name_copy, TensorInfo{
103-
.dtype = try allocator.dupe(u8, dtype),
107+
.dtype = dtype_copy,
104108
.shape = shape,
105109
.data_offsets = data_offsets,
106110
});

0 commit comments

Comments
 (0)