From 9c7dd3068fbb8077afed04db1567611504165f3f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 16 Apr 2017 10:39:42 +0200 Subject: [PATCH] Get rid of unnecessary wrappers around calloc/free --- libretro-common/gfx/scaler/scaler.c | 57 ++++++--------------- libretro-common/gfx/scaler/scaler_filter.c | 8 +-- libretro-common/include/gfx/scaler/scaler.h | 20 -------- 3 files changed, 21 insertions(+), 64 deletions(-) diff --git a/libretro-common/gfx/scaler/scaler.c b/libretro-common/gfx/scaler/scaler.c index d00fe0415c..7d2b084e19 100644 --- a/libretro-common/gfx/scaler/scaler.c +++ b/libretro-common/gfx/scaler/scaler.c @@ -30,43 +30,13 @@ #include #include -/** - * scaler_alloc: - * @elem_size : size of the elements to be used. - * @siz : size of the image that the scaler needs to handle. - * - * Allocate and returns a scaler object. - * - * Returns: pointer to a scaler object of type 'void *' on success, - * NULL in case of error. Has to be freed manually. - **/ -void *scaler_alloc(size_t elem_size, size_t size) -{ - void *ptr = calloc(elem_size, size); - if (!ptr) - return NULL; - return ptr; -} - -/** - * scaler_free: - * @ptr : pointer to scaler object. - * - * Frees a scaler object. - **/ -void scaler_free(void *ptr) -{ - if (ptr) - free(ptr); -} - static bool allocate_frames(struct scaler_ctx *ctx) { uint64_t *scaled_frame = NULL; ctx->scaled.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint64_t); ctx->scaled.width = ctx->out_width; ctx->scaled.height = ctx->in_height; - scaled_frame = (uint64_t*)scaler_alloc(sizeof(uint64_t), + scaled_frame = (uint64_t*)calloc(sizeof(uint64_t), (ctx->scaled.stride * ctx->scaled.height) >> 3); if (!scaled_frame) @@ -78,7 +48,7 @@ static bool allocate_frames(struct scaler_ctx *ctx) { uint32_t *input_frame = NULL; ctx->input.stride = ((ctx->in_width + 7) & ~7) * sizeof(uint32_t); - input_frame = (uint32_t*)scaler_alloc(sizeof(uint32_t), + input_frame = (uint32_t*)calloc(sizeof(uint32_t), (ctx->input.stride * ctx->in_height) >> 2); if (!input_frame) @@ -92,7 +62,7 @@ static bool allocate_frames(struct scaler_ctx *ctx) uint32_t *output_frame = NULL; ctx->output.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint32_t); - output_frame = (uint32_t*)scaler_alloc(sizeof(uint32_t), + output_frame = (uint32_t*)calloc(sizeof(uint32_t), (ctx->output.stride * ctx->out_height) >> 2); if (!output_frame) @@ -282,13 +252,20 @@ bool scaler_ctx_gen_filter(struct scaler_ctx *ctx) void scaler_ctx_gen_reset(struct scaler_ctx *ctx) { - scaler_free(ctx->horiz.filter); - scaler_free(ctx->horiz.filter_pos); - scaler_free(ctx->vert.filter); - scaler_free(ctx->vert.filter_pos); - scaler_free(ctx->scaled.frame); - scaler_free(ctx->input.frame); - scaler_free(ctx->output.frame); + if (ctx->horiz.filter) + free(ctx->horiz.filter); + if (ctx->horiz.filter_pos) + free(ctx->horiz.filter_pos); + if (ctx->vert.filter) + free(ctx->vert.filter); + if (ctx->vert.filter_pos) + free(ctx->vert.filter_pos); + if (ctx->scaled.frame) + free(ctx->scaled.frame); + if (ctx->input.frame) + free(ctx->input.frame); + if (ctx->output.frame) + free(ctx->output.frame); ctx->horiz.filter = NULL; ctx->horiz.filter_len = 0; diff --git a/libretro-common/gfx/scaler/scaler_filter.c b/libretro-common/gfx/scaler/scaler_filter.c index df56399328..9f00e88d1c 100644 --- a/libretro-common/gfx/scaler/scaler_filter.c +++ b/libretro-common/gfx/scaler/scaler_filter.c @@ -34,11 +34,11 @@ static bool allocate_filters(struct scaler_ctx *ctx) { - ctx->horiz.filter = (int16_t*)scaler_alloc(sizeof(int16_t), ctx->horiz.filter_stride * ctx->out_width); - ctx->horiz.filter_pos = (int*)scaler_alloc(sizeof(int), ctx->out_width); + ctx->horiz.filter = (int16_t*)calloc(sizeof(int16_t), ctx->horiz.filter_stride * ctx->out_width); + ctx->horiz.filter_pos = (int*)calloc(sizeof(int), ctx->out_width); - ctx->vert.filter = (int16_t*)scaler_alloc(sizeof(int16_t), ctx->vert.filter_stride * ctx->out_height); - ctx->vert.filter_pos = (int*)scaler_alloc(sizeof(int), ctx->out_height); + ctx->vert.filter = (int16_t*)calloc(sizeof(int16_t), ctx->vert.filter_stride * ctx->out_height); + ctx->vert.filter_pos = (int*)calloc(sizeof(int), ctx->out_height); return ctx->horiz.filter && ctx->vert.filter; } diff --git a/libretro-common/include/gfx/scaler/scaler.h b/libretro-common/include/gfx/scaler/scaler.h index 1c1c2b467d..469afaf3ce 100644 --- a/libretro-common/include/gfx/scaler/scaler.h +++ b/libretro-common/include/gfx/scaler/scaler.h @@ -123,26 +123,6 @@ void scaler_ctx_gen_reset(struct scaler_ctx *ctx); void scaler_ctx_scale(struct scaler_ctx *ctx, void *output, const void *input); -/** - * scaler_alloc: - * @elem_size : size of the elements to be used. - * @siz : size of the image that the scaler needs to handle. - * - * Allocate and returns a scaler object. - * - * Returns: pointer to a scaler object of type 'void *' on success, - * NULL in case of error. Has to be freed manually. - **/ -void *scaler_alloc(size_t elem_size, size_t size); - -/** - * scaler_free: - * @ptr : pointer to scaler object. - * - * Frees a scaler object. - **/ -void scaler_free(void *ptr); - RETRO_END_DECLS #endif