From 8beb5306e921deee5c07712b08afb559c0a386db Mon Sep 17 00:00:00 2001 From: Nicholas Gates Date: Mon, 30 Oct 2023 09:22:20 +0000 Subject: [PATCH] Support Zig master --- pydust/src/pydust.build.zig | 7 +++++-- pydust/src/trampoline.zig | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pydust/src/pydust.build.zig b/pydust/src/pydust.build.zig index 2236d05b..75a2e1cb 100644 --- a/pydust/src/pydust.build.zig +++ b/pydust/src/pydust.build.zig @@ -9,6 +9,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +const builtin = @import("builtin"); const std = @import("std"); const Step = std.Build.Step; const LazyPath = std.Build.LazyPath; @@ -295,7 +296,7 @@ fn getLibpython(allocator: std.mem.Allocator, python_exe: []const u8) ![]const u } fn getPythonOutput(allocator: std.mem.Allocator, python_exe: []const u8, code: []const u8) ![]const u8 { - const result = try std.process.Child.exec(.{ + const result = try runProcess(.{ .allocator = allocator, .argv = &.{ python_exe, "-c", code }, }); @@ -308,7 +309,7 @@ fn getPythonOutput(allocator: std.mem.Allocator, python_exe: []const u8, code: [ } fn getStdOutput(allocator: std.mem.Allocator, argv: []const []const u8) ![]const u8 { - const result = try std.process.Child.exec(.{ .allocator = allocator, .argv = argv }); + const result = try runProcess(.{ .allocator = allocator, .argv = argv }); if (result.term.Exited != 0) { std.debug.print("Failed to execute {any}:\n{s}\n", .{ argv, result.stderr }); std.process.exit(1); @@ -316,3 +317,5 @@ fn getStdOutput(allocator: std.mem.Allocator, argv: []const []const u8) ![]const allocator.free(result.stderr); return result.stdout; } + +const runProcess = if (builtin.zig_version.minor >= 12) std.process.Child.run else std.process.Child.exec; diff --git a/pydust/src/trampoline.zig b/pydust/src/trampoline.zig index dc308988..a5e11854 100644 --- a/pydust/src/trampoline.zig +++ b/pydust/src/trampoline.zig @@ -287,7 +287,6 @@ pub fn Trampoline(comptime T: type) type { } const args = try py.allocator.alloc(py.PyObject, if (pyargs) |a| a.length() else 0); - defer py.allocator.free(args); if (pyargs) |a| { for (0..a.length()) |i| { args[i] = try a.getItem(py.PyObject, i);