From af0c4b776f769d0009720a0e592f44daf3983d37 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 12 May 2024 19:21:23 -0300 Subject: [PATCH] Wrap / unwrap hbsdctrl_ctx_t Remove unneccessary abstraction --- ext/bsdcontrol.rb/context.c | 16 ++++------------ ext/bsdcontrol.rb/context.h | 4 ---- ext/bsdcontrol.rb/glue.c | 6 +++--- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/ext/bsdcontrol.rb/context.c b/ext/bsdcontrol.rb/context.c index d5e96b7..2d8cc53 100644 --- a/ext/bsdcontrol.rb/context.c +++ b/ext/bsdcontrol.rb/context.c @@ -5,32 +5,24 @@ static int FLAGS = HBSDCTRL_FEATURE_STATE_FLAG_NONE; static const char *NAMESPACE = LIBHBSDCONTROL_DEFAULT_NAMESPACE; -static void bsdcontrol_context_free(struct bsdcontrol_ctx_t *); +static void bsdcontrol_context_free(hbsdctrl_ctx_t *); VALUE bsdcontrol_context_alloc(VALUE klass) { hbsdctrl_ctx_t *ctx; - struct bsdcontrol_ctx_t *rbctx; ctx = hbsdctrl_ctx_new(FLAGS, NAMESPACE); - rbctx = calloc(1, sizeof(struct bsdcontrol_ctx_t)); if (ctx == NULL) { rb_raise(rb_eSystemCallError, "hbsdctrl_ctx_new"); } - else if (rbctx == NULL) - { - rb_raise(rb_eSystemCallError, "calloc"); - } - rbctx->ctx = ctx; - return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, rbctx); + return Data_Wrap_Struct(klass, NULL, bsdcontrol_context_free, ctx); } static void -bsdcontrol_context_free(struct bsdcontrol_ctx_t *rbctx) +bsdcontrol_context_free(hbsdctrl_ctx_t *ctx) { - hbsdctrl_ctx_free(&rbctx->ctx); - free(rbctx); + hbsdctrl_ctx_free(&ctx); } /* diff --git a/ext/bsdcontrol.rb/context.h b/ext/bsdcontrol.rb/context.h index ea83079..2ecbbdc 100644 --- a/ext/bsdcontrol.rb/context.h +++ b/ext/bsdcontrol.rb/context.h @@ -1,10 +1,6 @@ #include #include -struct bsdcontrol_ctx_t { - hbsdctrl_ctx_t *ctx; -}; - VALUE bsdcontrol_context_alloc(VALUE); VALUE bsdcontrol_context_library_version(VALUE); VALUE bsdcontrol_context_available_features(VALUE); diff --git a/ext/bsdcontrol.rb/glue.c b/ext/bsdcontrol.rb/glue.c index df84e1f..332f9e5 100644 --- a/ext/bsdcontrol.rb/glue.c +++ b/ext/bsdcontrol.rb/glue.c @@ -20,9 +20,9 @@ bsdcontrol_open(VALUE path) hbsdctrl_ctx_t * bsdcontrol_unwrap(VALUE rbcontext) { - struct bsdcontrol_ctx_t *rbctx; - Data_Get_Struct(rbcontext, struct bsdcontrol_ctx_t, rbctx); - return rbctx->ctx; + hbsdctrl_ctx_t *ctx; + Data_Get_Struct(rbcontext, hbsdctrl_ctx_t, ctx); + return ctx; } hbsdctrl_feature_t *