Skip to content

Commit 350ec18

Browse files
e0328ericnatecraddock
authored andcommitted
GeneralPurposeAllocator is removed
1 parent 4e0427e commit 350ec18

5 files changed

Lines changed: 17 additions & 25 deletions

File tree

examples/interpreter.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn flushedStdoutPrint(io: std.Io, comptime fmt: []const u8, args: anytype) !void
2929
}
3030

3131
pub fn main() anyerror!void {
32-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
32+
var gpa = std.heap.DebugAllocator(.{}){};
3333
const allocator = gpa.allocator();
3434
defer _ = gpa.deinit();
3535

examples/luau-bytecode.zig

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@ const std = @import("std");
1111
// The zlua module is made available in build.zig
1212
const zlua = @import("zlua");
1313

14-
pub fn main() anyerror!void {
15-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
16-
const allocator = gpa.allocator();
17-
defer _ = gpa.deinit();
14+
pub fn main(init: std.process.Init) anyerror!void {
15+
const gpa = init.gpa;
1816

1917
// Initialize The Lua vm and get a reference to the main thread
2018
//
2119
// Passing a Zig allocator to the Lua state requires a stable pointer
22-
var lua = try zlua.Lua.init(allocator);
20+
var lua = try zlua.Lua.init(gpa);
2321
defer lua.deinit();
2422

2523
// Open all Lua standard libraries
2624
lua.openLibs();
2725

2826
// Load bytecode
2927
const src = @embedFile("./test.luau");
30-
const bc = try zlua.compile(allocator, src, zlua.CompileOptions{});
31-
defer allocator.free(bc);
28+
const bc = try zlua.compile(gpa, src, zlua.CompileOptions{});
29+
defer gpa.free(bc);
3230

3331
try lua.loadBytecode("...", bc);
3432
try lua.protectedCall(.{});

examples/multithreaded.zig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ fn add_to_x(lua: *zlua.Lua, num: usize) void {
3434
lua.protectedCall(.{}) catch return;
3535
}
3636

37-
pub fn main() anyerror!void {
38-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
39-
const allocator = gpa.allocator();
40-
defer _ = gpa.deinit();
37+
pub fn main(init: std.process.Init) anyerror!void {
38+
const gpa = init.gpa;
4139

4240
// Initialize The Lua vm and get a reference to the main thread
43-
var lua = try zlua.Lua.init(allocator);
41+
var lua = try zlua.Lua.init(gpa);
4442
defer lua.deinit();
4543

4644
lua.openLibs();
@@ -56,7 +54,7 @@ pub fn main() anyerror!void {
5654

5755
// create a thread pool to run all the functions
5856
var pool: std.Thread.Pool = undefined;
59-
try pool.init(.{ .allocator = allocator, .n_jobs = n_jobs });
57+
try pool.init(.{ .allocator = gpa, .n_jobs = n_jobs });
6058
defer pool.deinit();
6159

6260
var wg: std.Thread.WaitGroup = .{};

examples/zig-fn.zig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ fn adder(lua: *Lua) i32 {
1616
return 1;
1717
}
1818

19-
pub fn main() anyerror!void {
20-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
21-
const allocator = gpa.allocator();
22-
defer _ = gpa.deinit();
19+
pub fn main(init: std.process.Init) anyerror!void {
20+
const gpa = init.gpa;
2321

2422
// Initialize The Lua vm and get a reference to the main thread
25-
var lua = try Lua.init(allocator);
23+
var lua = try Lua.init(gpa);
2624
defer lua.deinit();
2725

2826
// Push the adder function to the Lua stack.

readme.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ const zlua = @import("zlua");
8787
8888
const Lua = zlua.Lua;
8989
90-
pub fn main() anyerror!void {
91-
// Create an allocator
92-
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
93-
const allocator = gpa.allocator();
94-
defer _ = gpa.deinit();
90+
pub fn main(init: std.process.Init) anyerror!void {
91+
// Get an allocator from juicy main
92+
const gpa = init.gpa;
9593
9694
// Initialize the Lua vm
97-
var lua = try Lua.init(allocator);
95+
var lua = try Lua.init(gpa);
9896
defer lua.deinit();
9997
10098
// Add an integer to the Lua stack and retrieve it

0 commit comments

Comments
 (0)