(runahead) Style nits - no more '== NULL'

This commit is contained in:
twinaphex 2018-04-08 01:36:30 +02:00
parent 8e4df27305
commit 4f32eb9cc1
2 changed files with 72 additions and 51 deletions

View File

@ -12,7 +12,7 @@ enum rarch_core_type last_core_type;
static void free_retro_game_info(struct retro_game_info *dest)
{
if (dest == NULL)
if (!dest)
return;
FREE(dest->path);
FREE(dest->data);
@ -22,15 +22,19 @@ static void free_retro_game_info(struct retro_game_info *dest)
static struct retro_game_info* clone_retro_game_info(const
struct retro_game_info *src)
{
struct retro_game_info *dest;
if (src == NULL)
struct retro_game_info *dest = NULL;
if (!src)
return NULL;
dest = (struct retro_game_info*)calloc(1,
sizeof(struct retro_game_info));
if (!dest)
return NULL;
dest->path = strcpy_alloc(src->path);
dest->data = memcpy_alloc(src->data, src->size);
dest->size = src->size;
dest->meta = strcpy_alloc(src->meta);
return dest;
}
@ -55,10 +59,12 @@ static struct string_list* clone_string_list(const struct string_list *src)
if (!src)
return NULL;
dest = (struct string_list*)calloc(1, 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*)calloc(dest->size, sizeof(struct string_list_elem));
dest->elems = (struct string_list_elem*)
calloc(dest->size, sizeof(struct string_list_elem));
for (i = 0; i < src->size; i++)
{
@ -74,7 +80,8 @@ static struct string_list* clone_string_list(const struct string_list *src)
static void free_retro_subsystem_memory_info(struct
retro_subsystem_memory_info *dest)
{
if (dest == NULL) return;
if (!dest)
return;
FREE(dest->extension);
}
@ -90,7 +97,7 @@ static void free_retro_subsystem_rom_info(struct
retro_subsystem_rom_info *dest)
{
int i;
if (dest == NULL)
if (!dest)
return;
FREE(dest->desc);
@ -130,7 +137,7 @@ static void free_retro_subsystem_info(struct retro_subsystem_info *dest)
{
int i;
if (dest == NULL)
if (!dest)
return;
FREE(dest->desc);
@ -150,7 +157,7 @@ static retro_subsystem_info* clone_retro_subsystem_info(struct
retro_subsystem_info *dest = NULL;
retro_subsystem_rom_info *roms = NULL;
if (src == NULL)
if (!src)
return NULL;
dest = (struct retro_subsystem_info*)calloc(1,
sizeof(struct retro_subsystem_info));
@ -172,7 +179,7 @@ static retro_subsystem_info* clone_retro_subsystem_info(struct
static void free_retro_ctx_load_content_info(struct
retro_ctx_load_content_info *dest)
{
if (dest == NULL)
if (!dest)
return;
free_retro_game_info(dest->info);
@ -190,8 +197,8 @@ static struct retro_ctx_load_content_info
*clone_retro_ctx_load_content_info(
const struct retro_ctx_load_content_info *src)
{
struct retro_ctx_load_content_info *dest;
if (src == NULL || src->special != NULL)
struct retro_ctx_load_content_info *dest = NULL;
if (!src || src->special != NULL)
return NULL; /* refuse to deal with the Special field */
dest = (struct retro_ctx_load_content_info*)calloc(1,

View File

@ -8,8 +8,8 @@
#include "mylist.h"
#include "mem_util.h"
bool input_is_dirty;
static MyList *inputStateList;
bool input_is_dirty = false;
static MyList *input_state_list = NULL;
typedef struct InputListElement_t
{
@ -41,22 +41,23 @@ static void* InputListElementConstructor(void)
static void input_state_destory(void)
{
mylist_destroy(&inputStateList);
mylist_destroy(&input_state_list);
}
static void input_state_setlast(unsigned port, unsigned device,
static void input_state_set_last(unsigned port, unsigned device,
unsigned index, unsigned id, int16_t value)
{
int i;
InputListElement *element;
unsigned i;
InputListElement *element = NULL;
if (!inputStateList)
mylist_create(&inputStateList, 16, InputListElementConstructor, free);
if (!input_state_list)
mylist_create(&input_state_list, 16,
InputListElementConstructor, free);
/* find list item */
for (i = 0; i < inputStateList->size; i++)
for (i = 0; i < input_state_list->size; i++)
{
element = (InputListElement*)inputStateList->data[i];
element = (InputListElement*)input_state_list->data[i];
if ( element->port == port
&& element->device == device && element->index == index)
{
@ -64,40 +65,49 @@ static void input_state_setlast(unsigned port, unsigned device,
return;
}
}
element = (InputListElement*)mylist_add_element(inputStateList);
element->port = port;
element->device = device;
element->index = index;
element = (InputListElement*)
mylist_add_element(input_state_list);
element->port = port;
element->device = device;
element->index = index;
element->state[id] = value;
}
static int16_t input_state_getlast(unsigned port, unsigned device, unsigned index, unsigned id)
static int16_t input_state_get_last(unsigned port,
unsigned device, unsigned index, unsigned id)
{
int i;
InputListElement *element = NULL;
unsigned i;
if (!inputStateList)
if (!input_state_list)
return 0;
/* find list item */
for (i = 0; i < inputStateList->size; i++)
for (i = 0; i < input_state_list->size; i++)
{
element = (InputListElement*)inputStateList->data[i];
if (element->port == port && element->device == device && element->index == index)
InputListElement *element =
(InputListElement*)input_state_list->data[i];
if ( (element->port == port) &&
(element->device == device) &&
(element->index == index)
)
return element->state[id];
}
return 0;
}
static int16_t input_state_with_logging(unsigned port, unsigned device, unsigned index, unsigned id)
static int16_t input_state_with_logging(unsigned port,
unsigned device, unsigned index, unsigned id)
{
if (input_state_callback_original != NULL)
if (input_state_callback_original)
{
int16_t result = input_state_callback_original(port, device, index, id);
int16_t lastInput = input_state_getlast(port, device, index, id);
if (result != lastInput)
int16_t result = input_state_callback_original(
port, device, index, id);
int16_t last_input = input_state_get_last(port, device, index, id);
if (result != last_input)
input_is_dirty = true;
input_state_setlast(port, device, index, id, result);
input_state_set_last(port, device, index, id, result);
return result;
}
return 0;
@ -120,41 +130,45 @@ static bool unserialze_hook(const void *buf, size_t size)
void add_input_state_hook(void)
{
if (input_state_callback_original == NULL)
if (!input_state_callback_original)
{
input_state_callback_original = retro_ctx.state_cb;
retro_ctx.state_cb = input_state_with_logging;
retro_ctx.state_cb = input_state_with_logging;
current_core.retro_set_input_state(retro_ctx.state_cb);
}
if (retro_reset_callback_original == NULL)
if (!retro_reset_callback_original)
{
retro_reset_callback_original = current_core.retro_reset;
current_core.retro_reset = reset_hook;
current_core.retro_reset = reset_hook;
}
if (retro_unserialize_callback_original == NULL)
if (!retro_unserialize_callback_original)
{
retro_unserialize_callback_original = current_core.retro_unserialize;
current_core.retro_unserialize = unserialze_hook;
current_core.retro_unserialize = unserialze_hook;
}
}
void remove_input_state_hook(void)
{
if (input_state_callback_original != NULL)
if (input_state_callback_original)
{
retro_ctx.state_cb = input_state_callback_original;
retro_ctx.state_cb = input_state_callback_original;
current_core.retro_set_input_state(retro_ctx.state_cb);
input_state_callback_original = NULL;
input_state_destory();
}
if (retro_reset_callback_original != NULL)
if (retro_reset_callback_original)
{
current_core.retro_reset = retro_reset_callback_original;
current_core.retro_reset = retro_reset_callback_original;
retro_reset_callback_original = NULL;
}
if (retro_unserialize_callback_original != NULL)
if (retro_unserialize_callback_original)
{
current_core.retro_unserialize = retro_unserialize_callback_original;
current_core.retro_unserialize = retro_unserialize_callback_original;
retro_unserialize_callback_original = NULL;
}
}