Skip to content

Commit

Permalink
cleanup: Put the size of fixed arrays into the API types.
Browse files Browse the repository at this point in the history
These are ignored by C compilers, but can be used as documentation and
by bindings generators.
  • Loading branch information
iphydf committed Jan 4, 2024
1 parent 1e73698 commit c7ea73c
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 119 deletions.
48 changes: 24 additions & 24 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void tox_friend_read_receipt_handler(Messenger *m, uint32_t friend_number

static m_friend_request_cb tox_friend_request_handler;
non_null(1, 2, 3) nullable(5)
static void tox_friend_request_handler(Messenger *m, const uint8_t *public_key, const uint8_t *message, size_t length,
static void tox_friend_request_handler(Messenger *m, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], const uint8_t *message, size_t length,
void *user_data)
{
struct Tox_Userdata *tox_data = (struct Tox_Userdata *)user_data;
Expand Down Expand Up @@ -1013,7 +1013,7 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata)
}

non_null(5) nullable(1, 2, 4, 6)
static int32_t resolve_bootstrap_node(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
static int32_t resolve_bootstrap_node(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE],
IP_Port **root, Tox_Err_Bootstrap *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -1042,7 +1042,7 @@ static int32_t resolve_bootstrap_node(Tox *tox, const char *host, uint16_t port,
return count;
}

bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error)
bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Bootstrap *error)
{
IP_Port *root;
const int32_t count = resolve_bootstrap_node(tox, host, port, public_key, &root, error);
Expand Down Expand Up @@ -1093,7 +1093,7 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
return true;
}

bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE],
Tox_Err_Bootstrap *error)
{
IP_Port *root;
Expand Down Expand Up @@ -1182,7 +1182,7 @@ void tox_iterate(Tox *tox, void *user_data)
tox_unlock(tox);
}

void tox_self_get_address(const Tox *tox, uint8_t *address)
void tox_self_get_address(const Tox *tox, uint8_t address[TOX_ADDRESS_SIZE])
{
assert(tox != nullptr);

Expand Down Expand Up @@ -1210,7 +1210,7 @@ uint32_t tox_self_get_nospam(const Tox *tox)
return ret;
}

void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
void tox_self_get_public_key(const Tox *tox, uint8_t public_key[TOX_PUBLIC_KEY_SIZE])
{
assert(tox != nullptr);

Expand All @@ -1221,7 +1221,7 @@ void tox_self_get_public_key(const Tox *tox, uint8_t *public_key)
}
}

void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
void tox_self_get_secret_key(const Tox *tox, uint8_t secret_key[TOX_SECRET_KEY_SIZE])
{
assert(tox != nullptr);

Expand Down Expand Up @@ -1382,7 +1382,7 @@ static void set_friend_error(const Logger *log, int32_t ret, Tox_Err_Friend_Add
}
}

uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length,
uint32_t tox_friend_add(Tox *tox, const uint8_t address[TOX_ADDRESS_SIZE], const uint8_t *message, size_t length,
Tox_Err_Friend_Add *error)
{
assert(tox != nullptr);
Expand All @@ -1406,7 +1406,7 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message
return UINT32_MAX;
}

uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error)
uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_Add *error)
{
assert(tox != nullptr);

Expand Down Expand Up @@ -1446,7 +1446,7 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *
return true;
}

uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error)
uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Friend_By_Public_Key *error)
{
assert(tox != nullptr);

Expand All @@ -1469,7 +1469,7 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox
return (uint32_t)ret;
}

bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key,
bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE],
Tox_Err_Friend_Get_Public_Key *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -1925,7 +1925,7 @@ void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback
tox->file_recv_control_callback = callback;
}

bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t file_id[TOX_FILE_ID_LENGTH],
Tox_Err_File_Get *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -1953,7 +1953,7 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
return false;
}

uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t file_id[TOX_FILE_ID_LENGTH],
const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -2215,7 +2215,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
}

bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error)
{
assert(tox != nullptr);
tox_lock(tox);
Expand Down Expand Up @@ -2336,7 +2336,7 @@ bool tox_conference_offline_peer_get_name(const Tox *tox, uint32_t conference_nu

bool tox_conference_offline_peer_get_public_key(const Tox *tox, uint32_t conference_number,
uint32_t offline_peer_number,
uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
uint8_t public_key[TOX_PUBLIC_KEY_SIZE], Tox_Err_Conference_Peer_Query *error)
{
assert(tox != nullptr);
tox_lock(tox);
Expand Down Expand Up @@ -2629,7 +2629,7 @@ Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_
return (Tox_Conference_Type)ret;
}

bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *id)
bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t id[TOX_CONFERENCE_ID_SIZE])
{
assert(tox != nullptr);
tox_lock(tox);
Expand All @@ -2639,13 +2639,13 @@ bool tox_conference_get_id(const Tox *tox, uint32_t conference_number, uint8_t *
}

// TODO(iphydf): Delete in 0.3.0.
bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t *uid)
bool tox_conference_get_uid(const Tox *tox, uint32_t conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE])
{
assert(tox != nullptr);
return tox_conference_get_id(tox, conference_number, uid);
}

uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Conference_By_Id *error)
uint32_t tox_conference_by_id(const Tox *tox, const uint8_t id[TOX_CONFERENCE_ID_SIZE], Tox_Err_Conference_By_Id *error)
{
assert(tox != nullptr);

Expand All @@ -2669,7 +2669,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere
}

// TODO(iphydf): Delete in 0.3.0.
uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error)
uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error)
{
assert(tox != nullptr);
Tox_Err_Conference_By_Id id_error;
Expand Down Expand Up @@ -2805,7 +2805,7 @@ void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb
}
}

void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
void tox_self_get_dht_id(const Tox *tox, uint8_t dht_id[TOX_PUBLIC_KEY_SIZE])
{
assert(tox != nullptr);

Expand Down Expand Up @@ -3007,7 +3007,7 @@ uint32_t tox_group_new(Tox *tox, Tox_Group_Privacy_State privacy_state, const ui
return UINT32_MAX;
}

uint32_t tox_group_join(Tox *tox, const uint8_t *chat_id, const uint8_t *name, size_t name_length,
uint32_t tox_group_join(Tox *tox, const uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], const uint8_t *name, size_t name_length,
const uint8_t *password, size_t password_length, Tox_Err_Group_Join *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -3372,7 +3372,7 @@ uint32_t tox_group_self_get_peer_id(const Tox *tox, uint32_t group_number, Tox_E
return ret;
}

bool tox_group_self_get_public_key(const Tox *tox, uint32_t group_number, uint8_t *public_key,
bool tox_group_self_get_public_key(const Tox *tox, uint32_t group_number, uint8_t public_key[TOX_PUBLIC_KEY_SIZE],
Tox_Err_Group_Self_Query *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -3498,7 +3498,7 @@ Tox_Group_Role tox_group_peer_get_role(const Tox *tox, uint32_t group_number, ui
return (Tox_Group_Role)ret;
}

bool tox_group_peer_get_public_key(const Tox *tox, uint32_t group_number, uint32_t peer_id, uint8_t *public_key,
bool tox_group_peer_get_public_key(const Tox *tox, uint32_t group_number, uint32_t peer_id, uint8_t public_key[TOX_PUBLIC_KEY_SIZE],
Tox_Err_Group_Peer_Query *error)
{
assert(tox != nullptr);
Expand Down Expand Up @@ -3689,7 +3689,7 @@ bool tox_group_get_name(const Tox *tox, uint32_t group_number, uint8_t *group_na
return true;
}

bool tox_group_get_chat_id(const Tox *tox, uint32_t group_number, uint8_t *chat_id, Tox_Err_Group_State_Queries *error)
bool tox_group_get_chat_id(const Tox *tox, uint32_t group_number, uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE], Tox_Err_Group_State_Queries *error)
{
assert(tox != nullptr);

Expand Down
Loading

0 comments on commit c7ea73c

Please sign in to comment.