From adb15c7e4dddeeb9b7a13c42b8bbf4b9e0c72524 Mon Sep 17 00:00:00 2001 From: Jiacai Liu Date: Mon, 17 Jul 2023 20:24:57 +0800 Subject: [PATCH] free category (#68) * free category * fix ctx --- core/omg.c | 12 ++++++++++++ core/omg.h | 6 ++++++ tests/core.zig | 2 +- tests/discussion.zig | 5 +++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/omg.c b/core/omg.c index 2ee5f0f..e538baf 100644 --- a/core/omg.c +++ b/core/omg.c @@ -1566,3 +1566,15 @@ void omg_free_discussion(omg_discussion *discussion) { } } } + +void omg_free_repo_discussion_category(omg_repo_discussion_category *category) { + if (category != NULL) { + free(category->id); + for (size_t i = 0; i < category->len; i++) { + free(category->categories[i].id); + free(category->categories[i].name); + } + + free(category->categories); + } +} diff --git a/core/omg.h b/core/omg.h index e4d16a1..0bb9db8 100644 --- a/core/omg.h +++ b/core/omg.h @@ -278,6 +278,12 @@ typedef struct { size_t len; } omg_repo_discussion_category; +void omg_free_repo_discussion_category(omg_repo_discussion_category *); + +#define omg_auto_repo_discussion_category \ + omg_repo_discussion_category \ + __attribute__((cleanup(omg_free_repo_discussion_category))) + omg_error omg_query_repo_discussion_category(omg_context, const char *owner, const char *name, omg_repo_discussion_category *); diff --git a/tests/core.zig b/tests/core.zig index a66494c..ce167ba 100644 --- a/tests/core.zig +++ b/tests/core.zig @@ -106,7 +106,7 @@ fn test_create_pull(ctx: ?*clib.struct_omg_context) anyerror!void { } fn test_star_repo(ctx: ?*clib.struct_omg_context) anyerror!void { - try check_error(clib.omg_star_repo(ctx, "jiacai2050/oh-my-github")); + try check_error(clib.omg_star_repo(ctx, "xigua2023/xigua2023")); } pub fn main() anyerror!void { diff --git a/tests/discussion.zig b/tests/discussion.zig index 5df3231..b4ad3f9 100644 --- a/tests/discussion.zig +++ b/tests/discussion.zig @@ -8,7 +8,8 @@ const testing = std.testing; const time = std.time; pub fn main() !void { - const ctx = try util.init_ctx(); + var ctx = try util.init_ctx(); + defer c.omg_free_context(&ctx); // https://github.com/xigua2023/test-github-api/discussions try create(ctx); @@ -23,7 +24,7 @@ fn query(ctx: c.omg_context) !void { }; try util.check_error(c.omg_query_repo_discussion_category(ctx, "xigua2023", "test-github-api", &out)); defer { - // TODO: free out + c.omg_free_repo_discussion_category(&out); } }