@thi.ng/wasm-api 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-09-01T16:38:35Z
3
+ - **Last updated**: 2025-09-02T13:15:31Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -11,6 +11,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ### [2.4.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@2.4.1) (2025-09-02)
15
+
16
+ #### ♻️ Refactoring
17
+
18
+ - update zig `_wasm_allocate()` & `ManagedIndex` ([3e8870c](https://github.com/thi-ng/umbrella/commit/3e8870c))
19
+ - store allocator in `ManagedIndex` due to Zig ArrayList defaulting to unmanaged in 0.15.1
20
+ and managed versions will be removed in future
21
+ - fix alignment param in `_wasm_allocate()`
22
+
14
23
  ## [2.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/wasm-api@2.4.0) (2025-09-01)
15
24
 
16
25
  #### 🚀 Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/wasm-api",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Generic, modular, extensible API bridge and infrastructure for hybrid JS & WebAssembly projects",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -126,5 +126,5 @@
126
126
  "tag": "wasm",
127
127
  "year": 2022
128
128
  },
129
- "gitHead": "e215a3e8de3809736ba0042c93bd8703a5a1a337\n"
129
+ "gitHead": "4ebea5f30d4e2d28a12dfb01b39533fdfda0ab43\n"
130
130
  }
package/zig/lib.zig CHANGED
@@ -52,7 +52,7 @@ pub inline fn allocator() ?std.mem.Allocator {
52
52
  /// Note: For SIMD compatibility all allocations are aligned to 16 bytes
53
53
  pub export fn _wasm_allocate(numBytes: usize) usize {
54
54
  if (allocator()) |alloc| {
55
- const mem = alloc.alignedAlloc(u8, 16, numBytes) catch return 0;
55
+ const mem = alloc.alignedAlloc(u8, .@"16", numBytes) catch return 0;
56
56
  return @intFromPtr(mem.ptr);
57
57
  }
58
58
  return 0;
@@ -24,6 +24,7 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
24
24
  };
25
25
 
26
26
  return struct {
27
+ allocator: Allocator,
27
28
  /// backing array list
28
29
  list: std.ArrayList(Item),
29
30
  /// Index of the head of the implicitly stored list of free slots
@@ -37,22 +38,24 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
37
38
  const Self = @This();
38
39
 
39
40
  /// Initializes the underlying array list
40
- pub fn init(allocator: Allocator) Self {
41
+ pub fn init(alloc: Allocator) Self {
41
42
  return .{
42
- .list = std.ArrayList(Item).init(allocator),
43
+ .allocator = alloc,
44
+ .list = std.ArrayList(Item).empty,
43
45
  };
44
46
  }
45
47
 
46
48
  /// Initializes the underlying array list with given initial capacity
47
- pub fn initCapacity(allocator: Allocator, num: usize) !Self {
49
+ pub fn initCapacity(alloc: Allocator, num: usize) Allocator.Error!Self {
48
50
  return .{
49
- .list = try std.ArrayList(Item).initCapacity(allocator, num),
51
+ .allocator = alloc,
52
+ .list = try std.ArrayList(Item).initCapacity(alloc, num),
50
53
  };
51
54
  }
52
55
 
53
56
  /// De-initializes the underlying array list
54
57
  pub fn deinit(self: *Self) void {
55
- self.list.deinit();
58
+ self.list.deinit(self.allocator);
56
59
  }
57
60
 
58
61
  /// Clears, frees & resets this list and its backing array list.
@@ -72,7 +75,7 @@ pub fn ManagedIndex(comptime T: type, comptime I: type) type {
72
75
  return @intCast(id);
73
76
  } else {
74
77
  const id = self.list.items.len;
75
- try self.list.append(.{ .value = item });
78
+ try self.list.append(self.allocator, .{ .value = item });
76
79
  self.used += 1;
77
80
  return @intCast(id);
78
81
  }
@@ -179,53 +182,53 @@ test "ManagedIndex" {
179
182
  const expect = std.testing.expect;
180
183
  const expectEqualSlices = std.testing.expectEqualSlices;
181
184
 
182
- var list = ManagedIndex(f64, u8).init(allocator);
183
- defer list.deinit();
184
- try expect(try list.add(123) == 0);
185
- try expect(try list.add(123) == 1);
185
+ var index = ManagedIndex(f64, u8).init(allocator);
186
+ defer index.deinit();
187
+ try expect(try index.add(123) == 0);
188
+ try expect(try index.add(123) == 1);
186
189
 
187
- try expect(list.has(0));
188
- try expect(list.has(1));
189
- try expect(list.used == 2);
190
+ try expect(index.has(0));
191
+ try expect(index.has(1));
192
+ try expect(index.used == 2);
190
193
 
191
- list.remove(0);
192
- try expect(!list.has(0));
193
- try expect(!list.has(2));
194
- try expect(list.used == 1);
194
+ index.remove(0);
195
+ try expect(!index.has(0));
196
+ try expect(!index.has(2));
197
+ try expect(index.used == 1);
195
198
 
196
- try expect(try list.add(123) == 0);
197
- try expect(try list.add(123) == 2);
198
- try expect(list.has(2));
199
- try expect(list.used == 3);
199
+ try expect(try index.add(123) == 0);
200
+ try expect(try index.add(123) == 2);
201
+ try expect(index.has(2));
202
+ try expect(index.used == 3);
200
203
 
201
- list.remove(1);
202
- list.remove(2);
204
+ index.remove(1);
205
+ index.remove(2);
203
206
 
204
- const ids = try list.freeIndicesAsSlice(allocator);
207
+ const ids = try index.freeIndicesAsSlice(allocator);
205
208
  defer allocator.free(ids);
206
209
  try expectEqualSlices(u8, &[_]u8{ 2, 1 }, ids);
207
210
 
208
- try expect(try list.add(202) == 2);
209
- list.remove(0);
210
- try expect(try list.add(200) == 0);
211
- try expect(try list.add(201) == 1);
212
- try expect(list.freeID == null);
211
+ try expect(try index.add(202) == 2);
212
+ index.remove(0);
213
+ try expect(try index.add(200) == 0);
214
+ try expect(try index.add(201) == 1);
215
+ try expect(index.freeID == null);
213
216
 
214
- var iter = list.values();
217
+ var iter = index.values();
215
218
  try expect(if (iter.next()) |v| v == 200 else false);
216
219
  try expect(if (iter.next()) |v| v == 201 else false);
217
220
  try expect(if (iter.next()) |v| v == 202 else false);
218
221
  try expect(iter.next() == null);
219
222
 
220
- const slice = try list.valuesAsSlice(allocator);
223
+ const slice = try index.valuesAsSlice(allocator);
221
224
  defer allocator.free(slice);
222
225
  try expectEqualSlices(f64, &[_]f64{ 200, 201, 202 }, slice);
223
226
 
224
- list.remove(0);
225
- list.remove(2);
226
- list.remove(1);
227
+ index.remove(0);
228
+ index.remove(2);
229
+ index.remove(1);
227
230
 
228
- const ids2 = try list.freeIndicesAsSlice(allocator);
231
+ const ids2 = try index.freeIndicesAsSlice(allocator);
229
232
  defer allocator.free(ids2);
230
233
  try expectEqualSlices(u8, &[_]u8{ 1, 2, 0 }, ids2);
231
234
  }