Skip to content

Commit

Permalink
use fixed size types in more places (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Nov 1, 2023
1 parent 491d881 commit 7044890
Show file tree
Hide file tree
Showing 53 changed files with 420 additions and 413 deletions.
2 changes: 1 addition & 1 deletion include/rc_api_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
*/
typedef struct rc_api_fetch_code_notes_request_t {
/* The unique identifier of the game */
unsigned game_id;
uint32_t game_id;
}
rc_api_fetch_code_notes_request_t;

Expand Down
14 changes: 8 additions & 6 deletions include/rc_consoles.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
extern "C" {
#endif

#include <stdint.h>

/*****************************************************************************\
| Console identifiers |
\*****************************************************************************/
Expand Down Expand Up @@ -113,21 +115,21 @@ enum {
};

typedef struct rc_memory_region_t {
unsigned start_address; /* first address of block as queried by RetroAchievements */
unsigned end_address; /* last address of block as queried by RetroAchievements */
unsigned real_address; /* real address for first address of block */
char type; /* RC_MEMORY_TYPE_ for block */
uint32_t start_address; /* first address of block as queried by RetroAchievements */
uint32_t end_address; /* last address of block as queried by RetroAchievements */
uint32_t real_address; /* real address for first address of block */
uint8_t type; /* RC_MEMORY_TYPE_ for block */
const char* description; /* short description of block */
}
rc_memory_region_t;

typedef struct rc_memory_regions_t {
const rc_memory_region_t* region;
unsigned num_regions;
uint32_t num_regions;
}
rc_memory_regions_t;

const rc_memory_regions_t* rc_console_memory_regions(int console_id);
const rc_memory_regions_t* rc_console_memory_regions(uint32_t console_id);


#ifdef __cplusplus
Expand Down
28 changes: 14 additions & 14 deletions include/rc_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef struct rc_runtime_trigger_t {
rc_trigger_t* trigger;
void* buffer;
rc_memref_t* invalid_memref;
unsigned char md5[16];
uint8_t md5[16];
int32_t serialized_size;
uint8_t owns_memrefs;
}
Expand All @@ -58,7 +58,7 @@ typedef struct rc_runtime_lboard_t {
rc_lboard_t* lboard;
void* buffer;
rc_memref_t* invalid_memref;
unsigned char md5[16];
uint8_t md5[16];
uint32_t serialized_size;
uint8_t owns_memrefs;
}
Expand All @@ -68,7 +68,7 @@ typedef struct rc_runtime_richpresence_t {
rc_richpresence_t* richpresence;
void* buffer;
struct rc_runtime_richpresence_t* previous;
unsigned char md5[16];
uint8_t md5[16];
uint8_t owns_memrefs;
}
rc_runtime_richpresence_t;
Expand Down Expand Up @@ -98,20 +98,20 @@ rc_runtime_t* rc_runtime_alloc(void);
void rc_runtime_init(rc_runtime_t* runtime);
void rc_runtime_destroy(rc_runtime_t* runtime);

int rc_runtime_activate_achievement(rc_runtime_t* runtime, unsigned id, const char* memaddr, lua_State* L, int funcs_idx);
void rc_runtime_deactivate_achievement(rc_runtime_t* runtime, unsigned id);
rc_trigger_t* rc_runtime_get_achievement(const rc_runtime_t* runtime, unsigned id);
int rc_runtime_get_achievement_measured(const rc_runtime_t* runtime, unsigned id, unsigned* measured_value, unsigned* measured_target);
int rc_runtime_format_achievement_measured(const rc_runtime_t* runtime, unsigned id, char *buffer, size_t buffer_size);
int rc_runtime_activate_achievement(rc_runtime_t* runtime, uint32_t id, const char* memaddr, lua_State* L, int funcs_idx);
void rc_runtime_deactivate_achievement(rc_runtime_t* runtime, uint32_t id);
rc_trigger_t* rc_runtime_get_achievement(const rc_runtime_t* runtime, uint32_t id);
int rc_runtime_get_achievement_measured(const rc_runtime_t* runtime, uint32_t id, unsigned* measured_value, unsigned* measured_target);
int rc_runtime_format_achievement_measured(const rc_runtime_t* runtime, uint32_t id, char *buffer, size_t buffer_size);

int rc_runtime_activate_lboard(rc_runtime_t* runtime, unsigned id, const char* memaddr, lua_State* L, int funcs_idx);
void rc_runtime_deactivate_lboard(rc_runtime_t* runtime, unsigned id);
rc_lboard_t* rc_runtime_get_lboard(const rc_runtime_t* runtime, unsigned id);
int rc_runtime_format_lboard_value(char* buffer, int size, int value, int format);
int rc_runtime_activate_lboard(rc_runtime_t* runtime, uint32_t id, const char* memaddr, lua_State* L, int funcs_idx);
void rc_runtime_deactivate_lboard(rc_runtime_t* runtime, uint32_t id);
rc_lboard_t* rc_runtime_get_lboard(const rc_runtime_t* runtime, uint32_t id);
int rc_runtime_format_lboard_value(char* buffer, int size, int32_t value, int format);


int rc_runtime_activate_richpresence(rc_runtime_t* runtime, const char* script, lua_State* L, int funcs_idx);
int rc_runtime_get_richpresence(const rc_runtime_t* runtime, char* buffer, unsigned buffersize, rc_runtime_peek_t peek, void* peek_ud, lua_State* L);
int rc_runtime_get_richpresence(const rc_runtime_t* runtime, char* buffer, size_t buffersize, rc_runtime_peek_t peek, void* peek_ud, lua_State* L);

enum {
RC_RUNTIME_EVENT_ACHIEVEMENT_ACTIVATED, /* from WAITING, PAUSED, or PRIMED to ACTIVE */
Expand Down Expand Up @@ -147,7 +147,7 @@ void rc_runtime_invalidate_address(rc_runtime_t* runtime, uint32_t address);

int rc_runtime_progress_size(const rc_runtime_t* runtime, lua_State* L);
int rc_runtime_serialize_progress(void* buffer, const rc_runtime_t* runtime, lua_State* L);
int rc_runtime_deserialize_progress(rc_runtime_t* runtime, const unsigned char* serialized, lua_State* L);
int rc_runtime_deserialize_progress(rc_runtime_t* runtime, const uint8_t* serialized, lua_State* L);

#ifdef __cplusplus
}
Expand Down
11 changes: 6 additions & 5 deletions include/rc_runtime_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

#include "rc_error.h"

#include <stddef.h>
#include <stdint.h>

#ifndef RC_RUNTIME_H /* prevents pedantic redefiniton error */
Expand Down Expand Up @@ -304,7 +305,7 @@ struct rc_value_t {

int rc_value_size(const char* memaddr);
rc_value_t* rc_parse_value(void* buffer, const char* memaddr, lua_State* L, int funcs_ndx);
int rc_evaluate_value(rc_value_t* value, rc_peek_t peek, void* ud, lua_State* L);
int32_t rc_evaluate_value(rc_value_t* value, rc_peek_t peek, void* ud, lua_State* L);

/*****************************************************************************\
| Leaderboards |
Expand Down Expand Up @@ -334,7 +335,7 @@ struct rc_lboard_t {

int rc_lboard_size(const char* memaddr);
rc_lboard_t* rc_parse_lboard(void* buffer, const char* memaddr, lua_State* L, int funcs_ndx);
int rc_evaluate_lboard(rc_lboard_t* lboard, int* value, rc_peek_t peek, void* peek_ud, lua_State* L);
int rc_evaluate_lboard(rc_lboard_t* lboard, int32_t* value, rc_peek_t peek, void* peek_ud, lua_State* L);
void rc_reset_lboard(rc_lboard_t* lboard);

/*****************************************************************************\
Expand All @@ -359,7 +360,7 @@ enum {
};

int rc_parse_format(const char* format_str);
int rc_format_value(char* buffer, int size, int value, int format);
int rc_format_value(char* buffer, int size, int32_t value, int format);

/*****************************************************************************\
| Rich Presence |
Expand Down Expand Up @@ -413,9 +414,9 @@ struct rc_richpresence_t {
int rc_richpresence_size(const char* script);
int rc_richpresence_size_lines(const char* script, int* lines_read);
rc_richpresence_t* rc_parse_richpresence(void* buffer, const char* script, lua_State* L, int funcs_ndx);
int rc_evaluate_richpresence(rc_richpresence_t* richpresence, char* buffer, unsigned buffersize, rc_peek_t peek, void* peek_ud, lua_State* L);
int rc_evaluate_richpresence(rc_richpresence_t* richpresence, char* buffer, size_t buffersize, rc_peek_t peek, void* peek_ud, lua_State* L);
void rc_update_richpresence(rc_richpresence_t* richpresence, rc_peek_t peek, void* peek_ud, lua_State* L);
int rc_get_richpresence_display_string(rc_richpresence_t* richpresence, char* buffer, unsigned buffersize, rc_peek_t peek, void* peek_ud, lua_State* L);
int rc_get_richpresence_display_string(rc_richpresence_t* richpresence, char* buffer, size_t buffersize, rc_peek_t peek, void* peek_ud, lua_State* L);
void rc_reset_richpresence(rc_richpresence_t* self);

#ifdef __cplusplus
Expand Down
36 changes: 18 additions & 18 deletions src/rapi/rc_api_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static int rc_json_get_next_field(rc_json_iterator_t* iterator, rc_json_field_t*

static int rc_json_parse_object(rc_json_iterator_t* iterator, rc_json_field_t* fields, size_t field_count, unsigned* fields_seen) {
size_t i;
unsigned num_fields = 0;
uint32_t num_fields = 0;
rc_json_field_t field;
int result;

Expand Down Expand Up @@ -433,7 +433,7 @@ static int rc_json_get_array_entry_value(rc_json_field_t* field, rc_json_iterato
return 1;
}

int rc_json_get_required_unum_array(unsigned** entries, unsigned* num_entries, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_required_unum_array(uint32_t** entries, uint32_t* num_entries, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
rc_json_iterator_t iterator;
rc_json_field_t array;
rc_json_field_t value;
Expand Down Expand Up @@ -469,7 +469,7 @@ int rc_json_get_required_unum_array(unsigned** entries, unsigned* num_entries, r
return RC_OK;
}

int rc_json_get_required_array(unsigned* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_required_array(uint32_t* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
#ifndef NDEBUG
if (strcmp(field->name, field_name) != 0)
return 0;
Expand All @@ -481,7 +481,7 @@ int rc_json_get_required_array(unsigned* num_entries, rc_json_field_t* array_fie
return 1;
}

int rc_json_get_optional_array(unsigned* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_optional_array(uint32_t* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
#ifndef NDEBUG
if (strcmp(field->name, field_name) != 0)
return 0;
Expand Down Expand Up @@ -518,13 +518,13 @@ int rc_json_get_array_entry_object(rc_json_field_t* fields, size_t field_count,
return 1;
}

static unsigned rc_json_decode_hex4(const char* input) {
static uint32_t rc_json_decode_hex4(const char* input) {
char hex[5];

memcpy(hex, input, 4);
hex[4] = '\0';

return (unsigned)strtoul(hex, NULL, 16);
return (uint32_t)strtoul(hex, NULL, 16);
}

static int rc_json_ucs32_to_utf8(uint8_t* dst, uint32_t ucs32_char) {
Expand Down Expand Up @@ -624,13 +624,13 @@ int rc_json_get_string(const char** out, rc_buffer_t* buffer, const rc_json_fiel

if (*src == 'u') {
/* unicode character */
unsigned ucs32_char = rc_json_decode_hex4(src + 1);
uint32_t ucs32_char = rc_json_decode_hex4(src + 1);
src += 5;

if (ucs32_char >= 0xD800 && ucs32_char < 0xE000) {
/* surrogate lead - look for surrogate tail */
if (ucs32_char < 0xDC00 && src[0] == '\\' && src[1] == 'u') {
const unsigned surrogate = rc_json_decode_hex4(src + 2);
const uint32_t surrogate = rc_json_decode_hex4(src + 2);
src += 6;

if (surrogate >= 0xDC00 && surrogate < 0xE000) {
Expand Down Expand Up @@ -685,9 +685,9 @@ int rc_json_get_required_string(const char** out, rc_api_response_t* response, c
return rc_json_missing_field(response, field);
}

int rc_json_get_num(int* out, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_num(int32_t* out, const rc_json_field_t* field, const char* field_name) {
const char* src = field->value_start;
int value = 0;
int32_t value = 0;
int negative = 0;

#ifndef NDEBUG
Expand Down Expand Up @@ -727,21 +727,21 @@ int rc_json_get_num(int* out, const rc_json_field_t* field, const char* field_na
return 1;
}

void rc_json_get_optional_num(int* out, const rc_json_field_t* field, const char* field_name, int default_value) {
void rc_json_get_optional_num(int32_t* out, const rc_json_field_t* field, const char* field_name, int default_value) {
if (!rc_json_get_num(out, field, field_name))
*out = default_value;
}

int rc_json_get_required_num(int* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_required_num(int32_t* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
if (rc_json_get_num(out, field, field_name))
return 1;

return rc_json_missing_field(response, field);
}

int rc_json_get_unum(unsigned* out, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_unum(uint32_t* out, const rc_json_field_t* field, const char* field_name) {
const char* src = field->value_start;
int value = 0;
uint32_t value = 0;

#ifndef NDEBUG
if (strcmp(field->name, field_name) != 0)
Expand Down Expand Up @@ -771,12 +771,12 @@ int rc_json_get_unum(unsigned* out, const rc_json_field_t* field, const char* fi
return 1;
}

void rc_json_get_optional_unum(unsigned* out, const rc_json_field_t* field, const char* field_name, unsigned default_value) {
void rc_json_get_optional_unum(uint32_t* out, const rc_json_field_t* field, const char* field_name, uint32_t default_value) {
if (!rc_json_get_unum(out, field, field_name))
*out = default_value;
}

int rc_json_get_required_unum(unsigned* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
int rc_json_get_required_unum(uint32_t* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name) {
if (rc_json_get_unum(out, field, field_name))
return 1;

Expand Down Expand Up @@ -1014,15 +1014,15 @@ static int rc_url_builder_append_param_equals(rc_api_url_builder_t* builder, con
return builder->result;
}

void rc_url_builder_append_unum_param(rc_api_url_builder_t* builder, const char* param, unsigned value) {
void rc_url_builder_append_unum_param(rc_api_url_builder_t* builder, const char* param, uint32_t value) {
if (rc_url_builder_append_param_equals(builder, param) == RC_OK) {
char num[16];
int chars = snprintf(num, sizeof(num), "%u", value);
rc_url_builder_append(builder, num, chars);
}
}

void rc_url_builder_append_num_param(rc_api_url_builder_t* builder, const char* param, int value) {
void rc_url_builder_append_num_param(rc_api_url_builder_t* builder, const char* param, int32_t value) {
if (rc_url_builder_append_param_equals(builder, param) == RC_OK) {
char num[16];
int chars = snprintf(num, sizeof(num), "%d", value);
Expand Down
24 changes: 12 additions & 12 deletions src/rapi/rc_api_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct rc_json_field_t {
const char* value_end;
const char* name;
size_t name_len;
unsigned array_size;
uint32_t array_size;
}
rc_json_field_t;

Expand All @@ -45,30 +45,30 @@ rc_json_iterator_t;

int rc_json_parse_server_response(rc_api_response_t* response, const rc_api_server_response_t* server_response, rc_json_field_t* fields, size_t field_count);
int rc_json_get_string(const char** out, rc_buffer_t* buffer, const rc_json_field_t* field, const char* field_name);
int rc_json_get_num(int* out, const rc_json_field_t* field, const char* field_name);
int rc_json_get_unum(unsigned* out, const rc_json_field_t* field, const char* field_name);
int rc_json_get_num(int32_t* out, const rc_json_field_t* field, const char* field_name);
int rc_json_get_unum(uint32_t* out, const rc_json_field_t* field, const char* field_name);
int rc_json_get_bool(int* out, const rc_json_field_t* field, const char* field_name);
int rc_json_get_datetime(time_t* out, const rc_json_field_t* field, const char* field_name);
void rc_json_get_optional_string(const char** out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name, const char* default_value);
void rc_json_get_optional_num(int* out, const rc_json_field_t* field, const char* field_name, int default_value);
void rc_json_get_optional_unum(unsigned* out, const rc_json_field_t* field, const char* field_name, unsigned default_value);
void rc_json_get_optional_num(int32_t* out, const rc_json_field_t* field, const char* field_name, int default_value);
void rc_json_get_optional_unum(uint32_t* out, const rc_json_field_t* field, const char* field_name, uint32_t default_value);
void rc_json_get_optional_bool(int* out, const rc_json_field_t* field, const char* field_name, int default_value);
int rc_json_get_optional_array(unsigned* num_entries, rc_json_field_t* iterator, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_optional_array(uint32_t* num_entries, rc_json_field_t* iterator, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_string(const char** out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_num(int* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_unum(unsigned* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_num(int32_t* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_unum(uint32_t* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_bool(int* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_datetime(time_t* out, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_object(rc_json_field_t* fields, size_t field_count, rc_api_response_t* response, rc_json_field_t* field, const char* field_name);
int rc_json_get_required_unum_array(unsigned** entries, unsigned* num_entries, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_array(unsigned* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_unum_array(uint32_t** entries, uint32_t* num_entries, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_required_array(uint32_t* num_entries, rc_json_field_t* array_field, rc_api_response_t* response, const rc_json_field_t* field, const char* field_name);
int rc_json_get_array_entry_object(rc_json_field_t* fields, size_t field_count, rc_json_iterator_t* iterator);
int rc_json_get_next_object_field(rc_json_iterator_t* iterator, rc_json_field_t* field);
int rc_json_get_object_string_length(const char* json);

void rc_url_builder_append_encoded_str(rc_api_url_builder_t* builder, const char* str);
void rc_url_builder_append_num_param(rc_api_url_builder_t* builder, const char* param, int value);
void rc_url_builder_append_unum_param(rc_api_url_builder_t* builder, const char* param, unsigned value);
void rc_url_builder_append_num_param(rc_api_url_builder_t* builder, const char* param, int32_t value);
void rc_url_builder_append_unum_param(rc_api_url_builder_t* builder, const char* param, uint32_t value);
void rc_url_builder_append_str_param(rc_api_url_builder_t* builder, const char* param, const char* value);

void rc_api_url_build_dorequest_url(rc_api_request_t* request);
Expand Down
4 changes: 2 additions & 2 deletions src/rapi/rc_api_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int rc_api_process_fetch_achievement_info_server_response(rc_api_fetch_achieveme
rc_api_achievement_awarded_entry_t* entry;
rc_json_field_t array_field;
rc_json_iterator_t iterator;
unsigned timet;
uint32_t timet;
int result;

rc_json_field_t fields[] = {
Expand Down Expand Up @@ -165,7 +165,7 @@ int rc_api_process_fetch_leaderboard_info_server_response(rc_api_fetch_leaderboa
rc_api_lboard_info_entry_t* entry;
rc_json_field_t array_field;
rc_json_iterator_t iterator;
unsigned timet;
uint32_t timet;
int result;
size_t len;
char format[16];
Expand Down
2 changes: 1 addition & 1 deletion src/rapi/rc_api_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int rc_api_process_fetch_game_data_server_response(rc_api_fetch_game_data_respon
const char* last_author_field = "";
size_t last_author_len = 0;
size_t len;
unsigned timet;
uint32_t timet;
int result;
char format[16];

Expand Down
2 changes: 1 addition & 1 deletion src/rapi/rc_api_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int rc_api_process_start_session_server_response(rc_api_start_session_response_t
rc_api_unlock_entry_t* unlock;
rc_json_field_t array_field;
rc_json_iterator_t iterator;
unsigned timet;
uint32_t timet;
int result;

rc_json_field_t fields[] = {
Expand Down
Loading

0 comments on commit 7044890

Please sign in to comment.