Skip to content

Commit

Permalink
less
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 committed Oct 30, 2023
1 parent f1e99fe commit c6747c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
19 changes: 0 additions & 19 deletions pydust/src/functions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -358,25 +358,6 @@ pub fn unwrapArgs(comptime Args: type, pyargs: py.Args, pykwargs: py.Kwargs) !Ar
return args;
}

pub fn deinitArgs(comptime Args: type, args: Args, allPosArgs: []py.PyObject) void {
const s = @typeInfo(Args).Struct;
if (comptime varArgsIdx(Args)) |idx| {
py.allocator.free(allPosArgs[0..idx]);
} else {
py.allocator.free(allPosArgs);
}

inline for (s.fields) |field| {
if (field.type == py.Args) {
py.allocator.free(@field(args, field.name));
}
if (field.type == py.Kwargs) {
var kwargs: py.Kwargs = @field(args, field.name);
kwargs.deinit();
}
}
}

pub fn Methods(comptime definition: type) type {
const empty = ffi.PyMethodDef{ .ml_name = null, .ml_meth = null, .ml_flags = 0, .ml_doc = null };

Expand Down
16 changes: 15 additions & 1 deletion pydust/src/trampoline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,21 @@ pub fn Trampoline(comptime T: type) type {
}

pub fn deinit(self: @This()) void {
funcs.deinitArgs(T, self.argsStruct, self.allPosArgs);
if (comptime funcs.varArgsIdx(T)) |idx| {
py.allocator.free(self.allPosArgs[0..idx]);
} else {
py.allocator.free(self.allPosArgs);
}

inline for (@typeInfo(T).Struct.fields) |field| {
if (field.type == py.Args) {
py.allocator.free(@field(self.argsStruct, field.name));
}
if (field.type == py.Kwargs) {
var kwargs: py.Kwargs = @field(self.argsStruct, field.name);
kwargs.deinit();
}
}
}
};
};
Expand Down

0 comments on commit c6747c6

Please sign in to comment.