(runahead) Cleanups - create core_free_game_info and move it to

core_impl.c - get rid of free_string_list and just reuse
string_list_free
This commit is contained in:
twinaphex 2019-05-22 04:04:10 +02:00
parent 711ea77390
commit bcb474b3a3
5 changed files with 49 additions and 60 deletions

2
core.h
View File

@ -243,6 +243,8 @@ bool core_is_inited(void);
bool core_is_game_loaded(void);
void core_free_retro_game_info(struct retro_game_info *dest);
extern struct retro_callbacks retro_ctx;
RETRO_END_DECLS

View File

@ -530,3 +530,18 @@ bool core_is_game_loaded(void)
{
return current_core.game_loaded;
}
void core_free_retro_game_info(struct retro_game_info *dest)
{
if (!dest)
return;
if (dest->path)
free((void*)dest->path);
if (dest->data)
free((void*)dest->data);
if (dest->meta)
free((void*)dest->meta);
dest->path = NULL;
dest->data = NULL;
dest->meta = NULL;
}

View File

@ -42,8 +42,15 @@ void string_list_free(struct string_list *list)
return;
for (i = 0; i < list->size; i++)
free(list->elems[i].data);
free(list->elems);
{
if (list->elems[i].data)
free(list->elems[i].data);
list->elems[i].data = NULL;
}
if (list->elems)
free(list->elems);
list->elems = NULL;
free(list);
}

View File

@ -11,21 +11,6 @@
retro_ctx_load_content_info_t *load_content_info;
enum rarch_core_type last_core_type;
static void free_retro_game_info(struct retro_game_info *dest)
{
if (!dest)
return;
if (dest->path)
free((void*)dest->path);
if (dest->data)
free((void*)dest->data);
if (dest->meta)
free((void*)dest->meta);
dest->path = NULL;
dest->data = NULL;
dest->meta = NULL;
}
static struct retro_game_info* clone_retro_game_info(const
struct retro_game_info *src)
{
@ -60,23 +45,6 @@ static struct retro_game_info* clone_retro_game_info(const
return dest;
}
static void free_string_list(struct string_list *dest)
{
unsigned i;
if (!dest)
return;
for (i = 0; i < dest->size; i++)
{
if (dest->elems[i].data)
free(dest->elems[i].data);
dest->elems[i].data = NULL;
}
if (dest->elems)
free(dest->elems);
dest->elems = NULL;
}
static struct string_list *string_list_clone(
const struct string_list *src)
{
@ -237,12 +205,10 @@ static void free_retro_ctx_load_content_info(struct
if (!dest)
return;
free_retro_game_info(dest->info);
free_string_list((struct string_list*)dest->content);
core_free_retro_game_info(dest->info);
string_list_free((struct string_list*)dest->content);
if (dest->info)
free(dest->info);
if (dest->content)
free((void*)dest->content);
dest->info = NULL;
dest->content = NULL;

View File

@ -2,49 +2,48 @@
#include "mem_util.h"
char *strcpy_alloc(const char *sourceStr)
char *strcpy_alloc(const char *src)
{
size_t len = 0;
char *result = NULL;
if (sourceStr)
len = strlen(sourceStr);
size_t len = src ? strlen(src) : 0;
if (len == 0)
return NULL;
result = (char*)malloc(len + 1);
strcpy(result, sourceStr);
strcpy(result, src);
return result;
}
char *strcpy_alloc_force(const char *sourceStr)
char *strcpy_alloc_force(const char *src)
{
char *result = strcpy_alloc(sourceStr);
char *result = strcpy_alloc(src);
if (!result)
result = (char*)calloc(1, 1);
return (char*)calloc(1, 1);
return result;
}
void strcat_alloc(char ** destStr_p, const char *appendStr)
void strcat_alloc(char **dst, const char *s)
{
size_t len1, len2, newLen;
char *destStr = *destStr_p;
size_t len1;
char *src = *dst;
if (!destStr)
if (!src)
{
destStr = strcpy_alloc_force(appendStr);
*destStr_p = destStr;
src = strcpy_alloc_force(s);
*dst = src;
return;
}
if (!appendStr)
if (!s)
return;
len1 = strlen(destStr);
len2 = strlen(appendStr);
newLen = len1 + len2 + 1;
destStr = (char*)realloc(destStr, newLen);
*destStr_p = destStr;
strcpy(destStr + len1, appendStr);
len1 = strlen(src);
src = (char*)realloc(src, len1 + strlen(s) + 1);
if (!src)
return;
*dst = src;
strcpy(src + len1, s);
}