mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 00:20:01 +00:00
Remove malloc_zero, replace with calloc
Replace free_ptr with FREE macro
This commit is contained in:
parent
d04d1c0214
commit
dd392dcdfb
@ -25,7 +25,7 @@ static struct retro_game_info* clone_retro_game_info(const
|
||||
struct retro_game_info *dest;
|
||||
if (src == NULL)
|
||||
return NULL;
|
||||
dest = (struct retro_game_info*)malloc_zero(
|
||||
dest = (struct retro_game_info*)calloc(1,
|
||||
sizeof(struct retro_game_info));
|
||||
dest->path = strcpy_alloc(src->path);
|
||||
dest->data = memcpy_alloc(src->data, src->size);
|
||||
@ -55,10 +55,10 @@ static struct string_list* clone_string_list(const struct string_list *src)
|
||||
if (!src)
|
||||
return NULL;
|
||||
|
||||
dest = (struct string_list*)malloc_zero(sizeof(struct string_list));
|
||||
dest = (struct string_list*)calloc(1, sizeof(struct string_list));
|
||||
dest->size = src->size;
|
||||
dest->cap = src->cap;
|
||||
dest->elems = (struct string_list_elem*)malloc_zero(sizeof(struct string_list_elem) * dest->size);
|
||||
dest->elems = (struct string_list_elem*)calloc(dest->size, sizeof(struct string_list_elem));
|
||||
|
||||
for (i = 0; i < src->size; i++)
|
||||
{
|
||||
@ -117,7 +117,7 @@ static void clone_retro_subsystem_rom_info(struct
|
||||
dest->desc = strcpy_alloc(src->desc);
|
||||
dest->valid_extensions = strcpy_alloc(src->valid_extensions);
|
||||
|
||||
memory = (struct retro_subsystem_memory_info*)malloc_zero(
|
||||
memory = (struct retro_subsystem_memory_info*)calloc(1,
|
||||
dest->num_memory * sizeof(struct retro_subsystem_memory_info));
|
||||
|
||||
dest->memory = memory;
|
||||
@ -152,14 +152,14 @@ static retro_subsystem_info* clone_retro_subsystem_info(struct
|
||||
|
||||
if (src == NULL)
|
||||
return NULL;
|
||||
dest = (struct retro_subsystem_info*)malloc_zero(
|
||||
dest = (struct retro_subsystem_info*)calloc(1,
|
||||
sizeof(struct retro_subsystem_info));
|
||||
dest->desc = strcpy_alloc(src->desc);
|
||||
dest->ident = strcpy_alloc(src->ident);
|
||||
dest->num_roms = src->num_roms;
|
||||
dest->id = src->id;
|
||||
roms = (struct retro_subsystem_rom_info*)
|
||||
malloc_zero(src->num_roms * sizeof(struct retro_subsystem_rom_info));
|
||||
calloc(src->num_roms, sizeof(struct retro_subsystem_rom_info));
|
||||
dest->roms = roms;
|
||||
|
||||
for (i = 0; i < src->num_roms; i++)
|
||||
@ -194,7 +194,7 @@ static struct retro_ctx_load_content_info
|
||||
if (src == NULL || src->special != NULL)
|
||||
return NULL; /* refuse to deal with the Special field */
|
||||
|
||||
dest = (struct retro_ctx_load_content_info*)malloc_zero(
|
||||
dest = (struct retro_ctx_load_content_info*)calloc(1,
|
||||
sizeof(struct retro_ctx_load_content_info));
|
||||
dest->info = clone_retro_game_info(src->info);
|
||||
dest->content = clone_string_list(src->content);
|
||||
|
@ -34,7 +34,7 @@ static bool unserialze_hook(const void *buf, size_t size);
|
||||
static void* InputListElementConstructor(void)
|
||||
{
|
||||
const int size = sizeof(InputListElement);
|
||||
void *ptr = malloc_zero(size);
|
||||
void *ptr = calloc(1, size);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
@ -2,21 +2,6 @@
|
||||
|
||||
#include "mem_util.h"
|
||||
|
||||
void *malloc_zero(size_t size)
|
||||
{
|
||||
void *ptr = malloc(size);
|
||||
memset(ptr, 0, size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void free_ptr(void **data_p)
|
||||
{
|
||||
if (!data_p || !*data_p)
|
||||
return;
|
||||
free(*data_p);
|
||||
*data_p = NULL;
|
||||
}
|
||||
|
||||
void *memcpy_alloc(const void *src, size_t size)
|
||||
{
|
||||
void *result = malloc(size);
|
||||
@ -44,7 +29,7 @@ char *strcpy_alloc_force(const char *sourceStr)
|
||||
{
|
||||
char *result = strcpy_alloc(sourceStr);
|
||||
if (!result)
|
||||
result = (char*)malloc_zero(1);
|
||||
result = (char*)calloc(1, 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
void *malloc_zero(size_t size);
|
||||
void free_ptr(void **data_p);
|
||||
char *strcpy_alloc(const char *sourceStr);
|
||||
char *strcpy_alloc_force(const char *sourceStr);
|
||||
void strcat_alloc(char ** destStr_p, const char *appendStr);
|
||||
@ -21,4 +19,3 @@ void *memcpy_alloc(const void *src, size_t size);
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -91,7 +91,7 @@ void mylist_create(MyList **list_p, int initialCapacity,
|
||||
|
||||
if (initialCapacity > 0)
|
||||
{
|
||||
list->data = (void**)malloc_zero(initialCapacity * sizeof(void*));
|
||||
list->data = (void**)calloc(initialCapacity, sizeof(void*));
|
||||
list->capacity = initialCapacity;
|
||||
}
|
||||
else
|
||||
|
@ -128,16 +128,16 @@ char* copy_core_to_temp_file(void)
|
||||
goto failed;
|
||||
}
|
||||
|
||||
free_ptr((void**)&tempDirectory);
|
||||
free_ptr((void**)&retroarchTempPath);
|
||||
free_ptr(&dllFileData);
|
||||
FREE(tempDirectory);
|
||||
FREE(retroarchTempPath);
|
||||
FREE(dllFileData);
|
||||
return tempDllPath;
|
||||
|
||||
failed:
|
||||
free_ptr((void**)&tempDirectory);
|
||||
free_ptr((void**)&retroarchTempPath);
|
||||
free_ptr((void**)&tempDllPath);
|
||||
free_ptr((void**)&dllFileData);
|
||||
FREE(tempDirectory);
|
||||
FREE(retroarchTempPath);
|
||||
FREE(tempDllPath);
|
||||
FREE(dllFileData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ bool write_file_with_random_name(char **tempDllPath,
|
||||
numberValue = numberValue * 214013 + 2531011;
|
||||
number = (numberValue >> 14) % 100000;
|
||||
sprintf(numberBuf, "%05d", number);
|
||||
free_ptr((void**)tempDllPath);
|
||||
FREE(*tempDllPath);
|
||||
strcat_alloc(tempDllPath, retroarchTempPath);
|
||||
strcat_alloc(tempDllPath, prefix);
|
||||
strcat_alloc(tempDllPath, numberBuf);
|
||||
@ -178,7 +178,7 @@ bool write_file_with_random_name(char **tempDllPath,
|
||||
break;
|
||||
}
|
||||
|
||||
free_ptr((void**)&ext);
|
||||
FREE(ext);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ bool secondary_core_create(void)
|
||||
load_content_info->special)
|
||||
return false;
|
||||
|
||||
free_ptr((void**)&secondary_library_path);
|
||||
FREE(secondary_library_path);
|
||||
secondary_library_path = copy_core_to_temp_file();
|
||||
|
||||
if (!secondary_library_path)
|
||||
@ -321,7 +321,7 @@ void secondary_core_destroy(void)
|
||||
dylib_close(secondary_module);
|
||||
secondary_module = NULL;
|
||||
filestream_delete(secondary_library_path);
|
||||
free_ptr((void**)&secondary_library_path);
|
||||
FREE(secondary_library_path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,6 +339,7 @@ void clear_controller_port_map(void)
|
||||
for (port = 0; port < 16; port++)
|
||||
port_map[port] = -1;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <boolean.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user