(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:
parent
711ea77390
commit
bcb474b3a3
2
core.h
2
core.h
|
@ -243,6 +243,8 @@ bool core_is_inited(void);
|
||||||
|
|
||||||
bool core_is_game_loaded(void);
|
bool core_is_game_loaded(void);
|
||||||
|
|
||||||
|
void core_free_retro_game_info(struct retro_game_info *dest);
|
||||||
|
|
||||||
extern struct retro_callbacks retro_ctx;
|
extern struct retro_callbacks retro_ctx;
|
||||||
|
|
||||||
RETRO_END_DECLS
|
RETRO_END_DECLS
|
||||||
|
|
15
core_impl.c
15
core_impl.c
|
@ -530,3 +530,18 @@ bool core_is_game_loaded(void)
|
||||||
{
|
{
|
||||||
return current_core.game_loaded;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -42,8 +42,15 @@ void string_list_free(struct string_list *list)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < list->size; i++)
|
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);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,21 +11,6 @@
|
||||||
retro_ctx_load_content_info_t *load_content_info;
|
retro_ctx_load_content_info_t *load_content_info;
|
||||||
enum rarch_core_type last_core_type;
|
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
|
static struct retro_game_info* clone_retro_game_info(const
|
||||||
struct retro_game_info *src)
|
struct retro_game_info *src)
|
||||||
{
|
{
|
||||||
|
@ -60,23 +45,6 @@ static struct retro_game_info* clone_retro_game_info(const
|
||||||
return dest;
|
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(
|
static struct string_list *string_list_clone(
|
||||||
const struct string_list *src)
|
const struct string_list *src)
|
||||||
{
|
{
|
||||||
|
@ -237,12 +205,10 @@ static void free_retro_ctx_load_content_info(struct
|
||||||
if (!dest)
|
if (!dest)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free_retro_game_info(dest->info);
|
core_free_retro_game_info(dest->info);
|
||||||
free_string_list((struct string_list*)dest->content);
|
string_list_free((struct string_list*)dest->content);
|
||||||
if (dest->info)
|
if (dest->info)
|
||||||
free(dest->info);
|
free(dest->info);
|
||||||
if (dest->content)
|
|
||||||
free((void*)dest->content);
|
|
||||||
|
|
||||||
dest->info = NULL;
|
dest->info = NULL;
|
||||||
dest->content = NULL;
|
dest->content = NULL;
|
||||||
|
|
|
@ -2,49 +2,48 @@
|
||||||
|
|
||||||
#include "mem_util.h"
|
#include "mem_util.h"
|
||||||
|
|
||||||
char *strcpy_alloc(const char *sourceStr)
|
char *strcpy_alloc(const char *src)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
size_t len = src ? strlen(src) : 0;
|
||||||
if (sourceStr)
|
|
||||||
len = strlen(sourceStr);
|
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
result = (char*)malloc(len + 1);
|
result = (char*)malloc(len + 1);
|
||||||
strcpy(result, sourceStr);
|
strcpy(result, src);
|
||||||
return result;
|
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)
|
if (!result)
|
||||||
result = (char*)calloc(1, 1);
|
return (char*)calloc(1, 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void strcat_alloc(char ** destStr_p, const char *appendStr)
|
void strcat_alloc(char **dst, const char *s)
|
||||||
{
|
{
|
||||||
size_t len1, len2, newLen;
|
size_t len1;
|
||||||
char *destStr = *destStr_p;
|
char *src = *dst;
|
||||||
|
|
||||||
if (!destStr)
|
if (!src)
|
||||||
{
|
{
|
||||||
destStr = strcpy_alloc_force(appendStr);
|
src = strcpy_alloc_force(s);
|
||||||
*destStr_p = destStr;
|
*dst = src;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!appendStr)
|
if (!s)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
len1 = strlen(destStr);
|
len1 = strlen(src);
|
||||||
len2 = strlen(appendStr);
|
src = (char*)realloc(src, len1 + strlen(s) + 1);
|
||||||
newLen = len1 + len2 + 1;
|
|
||||||
destStr = (char*)realloc(destStr, newLen);
|
if (!src)
|
||||||
*destStr_p = destStr;
|
return;
|
||||||
strcpy(destStr + len1, appendStr);
|
|
||||||
|
*dst = src;
|
||||||
|
strcpy(src + len1, s);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue