mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 09:39:56 +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;
|
struct retro_game_info *dest;
|
||||||
if (src == NULL)
|
if (src == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dest = (struct retro_game_info*)malloc_zero(
|
dest = (struct retro_game_info*)calloc(1,
|
||||||
sizeof(struct retro_game_info));
|
sizeof(struct retro_game_info));
|
||||||
dest->path = strcpy_alloc(src->path);
|
dest->path = strcpy_alloc(src->path);
|
||||||
dest->data = memcpy_alloc(src->data, src->size);
|
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)
|
if (!src)
|
||||||
return NULL;
|
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->size = src->size;
|
||||||
dest->cap = src->cap;
|
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++)
|
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->desc = strcpy_alloc(src->desc);
|
||||||
dest->valid_extensions = strcpy_alloc(src->valid_extensions);
|
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->num_memory * sizeof(struct retro_subsystem_memory_info));
|
||||||
|
|
||||||
dest->memory = memory;
|
dest->memory = memory;
|
||||||
@ -152,14 +152,14 @@ static retro_subsystem_info* clone_retro_subsystem_info(struct
|
|||||||
|
|
||||||
if (src == NULL)
|
if (src == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
dest = (struct retro_subsystem_info*)malloc_zero(
|
dest = (struct retro_subsystem_info*)calloc(1,
|
||||||
sizeof(struct retro_subsystem_info));
|
sizeof(struct retro_subsystem_info));
|
||||||
dest->desc = strcpy_alloc(src->desc);
|
dest->desc = strcpy_alloc(src->desc);
|
||||||
dest->ident = strcpy_alloc(src->ident);
|
dest->ident = strcpy_alloc(src->ident);
|
||||||
dest->num_roms = src->num_roms;
|
dest->num_roms = src->num_roms;
|
||||||
dest->id = src->id;
|
dest->id = src->id;
|
||||||
roms = (struct retro_subsystem_rom_info*)
|
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;
|
dest->roms = roms;
|
||||||
|
|
||||||
for (i = 0; i < src->num_roms; i++)
|
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)
|
if (src == NULL || src->special != NULL)
|
||||||
return NULL; /* refuse to deal with the Special field */
|
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));
|
sizeof(struct retro_ctx_load_content_info));
|
||||||
dest->info = clone_retro_game_info(src->info);
|
dest->info = clone_retro_game_info(src->info);
|
||||||
dest->content = clone_string_list(src->content);
|
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)
|
static void* InputListElementConstructor(void)
|
||||||
{
|
{
|
||||||
const int size = sizeof(InputListElement);
|
const int size = sizeof(InputListElement);
|
||||||
void *ptr = malloc_zero(size);
|
void *ptr = calloc(1, size);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,6 @@
|
|||||||
|
|
||||||
#include "mem_util.h"
|
#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 *memcpy_alloc(const void *src, size_t size)
|
||||||
{
|
{
|
||||||
void *result = malloc(size);
|
void *result = malloc(size);
|
||||||
@ -44,7 +29,7 @@ char *strcpy_alloc_force(const char *sourceStr)
|
|||||||
{
|
{
|
||||||
char *result = strcpy_alloc(sourceStr);
|
char *result = strcpy_alloc(sourceStr);
|
||||||
if (!result)
|
if (!result)
|
||||||
result = (char*)malloc_zero(1);
|
result = (char*)calloc(1, 1);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
RETRO_BEGIN_DECLS
|
RETRO_BEGIN_DECLS
|
||||||
|
|
||||||
void *malloc_zero(size_t size);
|
|
||||||
void free_ptr(void **data_p);
|
|
||||||
char *strcpy_alloc(const char *sourceStr);
|
char *strcpy_alloc(const char *sourceStr);
|
||||||
char *strcpy_alloc_force(const char *sourceStr);
|
char *strcpy_alloc_force(const char *sourceStr);
|
||||||
void strcat_alloc(char ** destStr_p, const char *appendStr);
|
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
|
RETRO_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void mylist_create(MyList **list_p, int initialCapacity,
|
|||||||
|
|
||||||
if (initialCapacity > 0)
|
if (initialCapacity > 0)
|
||||||
{
|
{
|
||||||
list->data = (void**)malloc_zero(initialCapacity * sizeof(void*));
|
list->data = (void**)calloc(initialCapacity, sizeof(void*));
|
||||||
list->capacity = initialCapacity;
|
list->capacity = initialCapacity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -128,16 +128,16 @@ char* copy_core_to_temp_file(void)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_ptr((void**)&tempDirectory);
|
FREE(tempDirectory);
|
||||||
free_ptr((void**)&retroarchTempPath);
|
FREE(retroarchTempPath);
|
||||||
free_ptr(&dllFileData);
|
FREE(dllFileData);
|
||||||
return tempDllPath;
|
return tempDllPath;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
free_ptr((void**)&tempDirectory);
|
FREE(tempDirectory);
|
||||||
free_ptr((void**)&retroarchTempPath);
|
FREE(retroarchTempPath);
|
||||||
free_ptr((void**)&tempDllPath);
|
FREE(tempDllPath);
|
||||||
free_ptr((void**)&dllFileData);
|
FREE(dllFileData);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ bool write_file_with_random_name(char **tempDllPath,
|
|||||||
numberValue = numberValue * 214013 + 2531011;
|
numberValue = numberValue * 214013 + 2531011;
|
||||||
number = (numberValue >> 14) % 100000;
|
number = (numberValue >> 14) % 100000;
|
||||||
sprintf(numberBuf, "%05d", number);
|
sprintf(numberBuf, "%05d", number);
|
||||||
free_ptr((void**)tempDllPath);
|
FREE(*tempDllPath);
|
||||||
strcat_alloc(tempDllPath, retroarchTempPath);
|
strcat_alloc(tempDllPath, retroarchTempPath);
|
||||||
strcat_alloc(tempDllPath, prefix);
|
strcat_alloc(tempDllPath, prefix);
|
||||||
strcat_alloc(tempDllPath, numberBuf);
|
strcat_alloc(tempDllPath, numberBuf);
|
||||||
@ -178,7 +178,7 @@ bool write_file_with_random_name(char **tempDllPath,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_ptr((void**)&ext);
|
FREE(ext);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ bool secondary_core_create(void)
|
|||||||
load_content_info->special)
|
load_content_info->special)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
free_ptr((void**)&secondary_library_path);
|
FREE(secondary_library_path);
|
||||||
secondary_library_path = copy_core_to_temp_file();
|
secondary_library_path = copy_core_to_temp_file();
|
||||||
|
|
||||||
if (!secondary_library_path)
|
if (!secondary_library_path)
|
||||||
@ -321,7 +321,7 @@ void secondary_core_destroy(void)
|
|||||||
dylib_close(secondary_module);
|
dylib_close(secondary_module);
|
||||||
secondary_module = NULL;
|
secondary_module = NULL;
|
||||||
filestream_delete(secondary_library_path);
|
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++)
|
for (port = 0; port < 16; port++)
|
||||||
port_map[port] = -1;
|
port_map[port] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user