Skip to content

Commit 1973640

Browse files
committed
cleanup: Add nullability to more function params and return types.
1 parent 36a5b77 commit 1973640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+882
-883
lines changed

auto_tests/scenarios/scenario_group_by_id_test.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ static void script(ToxNode *self, void *ctx)
5353
group_number = tox_group_by_id(tox, invalid_chat_id, &err_by_id);
5454
ck_assert_int_eq(err_by_id, TOX_ERR_GROUP_BY_ID_NOT_FOUND);
5555
ck_assert_uint_eq(group_number, UINT32_MAX);
56-
57-
// Test tox_group_by_id with NULL ID
58-
group_number = tox_group_by_id(tox, NULL, &err_by_id);
59-
ck_assert_int_eq(err_by_id, TOX_ERR_GROUP_BY_ID_NULL);
60-
ck_assert_uint_eq(group_number, UINT32_MAX);
6156
}
6257

6358
// Create another group to ensure it works with multiple groups

other/event_tooling/generate_event_c.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ std::string zero_initializer_for_type(const std::string& type) {
168168
}
169169
}
170170

171-
void generate_event_impl(const std::string& event_name, const std::vector<EventType>& event_types) {
171+
void generate_event_impl(const std::string& event_name, const std::vector<EventType>& event_types, bool is_public = true) {
172172
const std::string event_name_l = str_tolower(event_name);
173173
const std::string event_name_u = str_toupper(event_name);
174174
std::string file_name = output_folder + "/" + event_name_l + ".c";
@@ -543,7 +543,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
543543
f << " mem_delete(mem, " << event_name_l << ");\n}\n\n";
544544

545545
// add
546-
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)\n{\n";
546+
f << "static Tox_Event_" << event_name << " *_Nullable tox_events_add_" << event_name_l << "(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)\n{\n";
547547
f << " Tox_Event_" << event_name << " *const " << event_name_l << " = tox_event_" << event_name_l << "_new(mem);\n\n";
548548
f << " if (" << event_name_l << " == nullptr) {\n";
549549
f << " return nullptr;\n }\n\n";
@@ -552,8 +552,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
552552
f << " event.data." << event_name_l << " = " << event_name_l << ";\n\n";
553553
f << " if (!tox_events_add(events, &event)) {\n";
554554
f << " tox_event_" << event_name_l << "_free(" << event_name_l << ", mem);\n";
555-
f << " return nullptr;\n";
556-
f << " }\n";
555+
f << " return nullptr;\n }\n";
557556
f << " return " << event_name_l << ";\n}\n\n";
558557

559558
// unpack
@@ -566,7 +565,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
566565
f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n";
567566

568567
// alloc
569-
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(Tox_Events_State *_Nonnull state)\n{\n";
568+
f << "static Tox_Event_" << event_name << " *_Nullable tox_event_" << event_name_l << "_alloc(Tox_Events_State *_Nonnull state)\n{\n";
570569
f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n";
571570
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_events_add_" << event_name_l << "(state->events, state->mem);\n\n";
572571
f << " if (" << event_name_l << " == nullptr) {\n";
@@ -583,7 +582,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
583582
584583
)";
585584
f << "void tox_events_handle_" << event_name_l << "(\n";
586-
f << " Tox *tox";
585+
f << " Tox " << (is_public ? "*_Nonnull " : "*") << "tox";
587586

588587
for (const auto& t : event_types) {
589588
f << ",\n ";
@@ -593,17 +592,17 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
593592
f << (t.cb_type.empty() ? t.type : t.cb_type) << " " << t.name;
594593
},
595594
[&](const EventTypeByteRange& t) {
596-
f << "const " << t.type_c_arg << " *" << t.name_data << ", " << t.type_length_cb << " " << t.name_length_cb;
595+
f << "const " << t.type_c_arg << " " << (is_public ? "*_Nullable " : "*") << t.name_data << ", " << t.type_length_cb << " " << t.name_length_cb;
597596
},
598597
[&](const EventTypeByteArray& t) {
599-
f << "const uint8_t *" << t.name;
598+
f << "const uint8_t " << (is_public ? "*_Nonnull " : "*") << t.name;
600599
}
601600
},
602601
t
603602
);
604603
}
605604

606-
f << ",\n void *user_data)\n{\n";
605+
f << ",\n void " << (is_public ? "*_Nullable " : "*") << "user_data)\n{\n";
607606
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
608607
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_event_" << event_name_l << "_alloc(state);\n\n";
609608
f << " if (" << event_name_l << " == nullptr) {\n return;\n }\n\n";
@@ -988,11 +987,11 @@ int main(int argc, char** argv) {
988987

989988
if (argc < 2) {
990989
for (const auto& [event, event_types] : event_defs) {
991-
generate_event_impl(event, event_types);
990+
generate_event_impl(event, event_types, event != "Dht_Nodes_Response");
992991
}
993992
} else {
994993
if (event_defs.count(argv[1])) {
995-
generate_event_impl(argv[1], event_defs[argv[1]]);
994+
generate_event_impl(argv[1], event_defs[argv[1]], std::string(argv[1]) != "Dht_Nodes_Response");
996995
} else {
997996
std::cerr << "error: unknown event " << argv[1] << "\n";
998997
return 1;

toxav/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports_files(
1111
cc_library(
1212
name = "public_api",
1313
hdrs = ["toxav.h"],
14+
deps = ["//c-toxcore/toxcore:attributes"],
1415
)
1516

1617
cc_library(
@@ -129,6 +130,7 @@ cc_library(
129130
deps = [
130131
":ring_buffer",
131132
":rtp",
133+
"//c-toxcore/toxcore:attributes",
132134
"//c-toxcore/toxcore:ccompat",
133135
"//c-toxcore/toxcore:logger",
134136
"//c-toxcore/toxcore:mono_time",
@@ -179,6 +181,7 @@ cc_library(
179181
deps = [
180182
":ring_buffer",
181183
":rtp",
184+
"//c-toxcore/toxcore:attributes",
182185
"//c-toxcore/toxcore:ccompat",
183186
"//c-toxcore/toxcore:logger",
184187
"//c-toxcore/toxcore:mono_time",
@@ -295,6 +298,7 @@ cc_library(
295298
":rtp",
296299
":video",
297300
"//c-toxcore/toxcore:Messenger",
301+
"//c-toxcore/toxcore:attributes",
298302
"//c-toxcore/toxcore:ccompat",
299303
"//c-toxcore/toxcore:group",
300304
"//c-toxcore/toxcore:logger",

toxav/audio.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "rtp.h"
1414

15+
#include "../toxcore/attributes.h"
1516
#include "../toxcore/ccompat.h"
1617
#include "../toxcore/logger.h"
1718
#include "../toxcore/mono_time.h"
@@ -20,33 +21,33 @@
2021

2122

2223
struct ACSession {
23-
Mono_Time *mono_time;
24-
const Logger *log;
24+
Mono_Time *_Nonnull mono_time;
25+
const Logger *_Nonnull log;
2526

2627
/* encoding */
27-
OpusEncoder *encoder;
28+
OpusEncoder *_Nullable encoder;
2829
uint32_t le_sample_rate; /* Last encoder sample rate */
2930
uint8_t le_channel_count; /* Last encoder channel count */
3031
uint32_t le_bit_rate; /* Last encoder bit rate */
3132

3233
/* decoding */
33-
OpusDecoder *decoder;
34+
OpusDecoder *_Nullable decoder;
3435
uint8_t lp_channel_count; /* Last packet channel count */
3536
uint32_t lp_sampling_rate; /* Last packet sample rate */
3637
uint32_t lp_frame_duration; /* Last packet frame duration */
3738
uint32_t ld_sample_rate; /* Last decoder sample rate */
3839
uint8_t ld_channel_count; /* Last decoder channel count */
3940
uint64_t ldrts; /* Last decoder reconfiguration time stamp */
40-
void *j_buf;
41+
void *_Nullable j_buf;
4142

4243
pthread_mutex_t queue_mutex[1];
4344

44-
int16_t *decode_buffer;
45+
int16_t *_Nullable decode_buffer;
4546

4647
uint32_t friend_number;
4748
/* Audio frame receive callback */
48-
ac_audio_receive_frame_cb *acb;
49-
void *user_data;
49+
ac_audio_receive_frame_cb *_Nullable acb;
50+
void *_Nullable user_data;
5051
};
5152

5253

@@ -327,7 +328,7 @@ int ac_encode(ACSession *ac, const int16_t *pcm, size_t sample_count, uint8_t *d
327328
}
328329

329330
struct JitterBuffer {
330-
struct RTPMessage **queue;
331+
struct RTPMessage *_Nullable *_Nonnull queue;
331332
uint32_t size;
332333
uint32_t capacity;
333334
uint16_t bottom;

toxav/bwcontroller.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ typedef struct BWCCycle {
3333

3434
typedef struct BWCRcvPkt {
3535
uint32_t packet_length_array[BWC_AVG_PKT_COUNT];
36-
RingBuffer *rb;
36+
RingBuffer *_Nonnull rb;
3737
} BWCRcvPkt;
3838

3939
struct BWController {
40-
bwc_loss_report_cb *mcb;
41-
void *mcb_user_data;
42-
bwc_send_packet_cb *send_packet;
43-
void *send_packet_user_data;
44-
const Logger *log;
40+
bwc_loss_report_cb *_Nullable mcb;
41+
void *_Nullable mcb_user_data;
42+
bwc_send_packet_cb *_Nullable send_packet;
43+
void *_Nullable send_packet_user_data;
44+
const Logger *_Nonnull log;
4545
uint32_t friend_number;
4646

4747
BWCCycle cycle;
4848

4949
BWCRcvPkt rcvpkt; /* To calculate average received packet (this means split parts, not the full message!) */
5050

5151
uint32_t packet_loss_counted_cycles;
52-
Mono_Time *bwc_mono_time;
52+
Mono_Time *_Nonnull bwc_mono_time;
5353
bool bwc_receive_active; /* if this is set to false then incoming bwc packets will not be processed by bwc_handle_data() */
5454
};
5555

toxav/groupav.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
typedef struct Group_Audio_Packet {
2020
uint16_t sequnum;
2121
uint16_t length;
22-
uint8_t *data;
22+
uint8_t *_Nonnull data;
2323
} Group_Audio_Packet;
2424

2525
typedef struct Group_JitterBuffer {
26-
Group_Audio_Packet **queue;
26+
Group_Audio_Packet *_Nullable *_Nonnull queue;
2727
uint32_t size;
2828
uint32_t capacity;
2929
uint16_t bottom;
@@ -161,26 +161,26 @@ static Group_Audio_Packet *_Nullable dequeue(Group_JitterBuffer *_Nonnull q, int
161161
}
162162

163163
typedef struct Group_AV {
164-
const Logger *log;
165-
Tox *tox;
166-
Group_Chats *g_c;
167-
OpusEncoder *audio_encoder;
164+
const Logger *_Nonnull log;
165+
Tox *_Nonnull tox;
166+
Group_Chats *_Nonnull g_c;
167+
OpusEncoder *_Nullable audio_encoder;
168168

169169
unsigned int audio_channels;
170170
unsigned int audio_sample_rate;
171171
unsigned int audio_bitrate;
172172

173173
uint16_t audio_sequnum;
174174

175-
audio_data_cb *audio_data;
176-
void *userdata;
175+
audio_data_cb *_Nullable audio_data;
176+
void *_Nullable userdata;
177177
} Group_AV;
178178

179179
typedef struct Group_Peer_AV {
180-
const Mono_Time *mono_time;
181-
Group_JitterBuffer *buffer;
180+
const Mono_Time *_Nonnull mono_time;
181+
Group_JitterBuffer *_Nonnull buffer;
182182

183-
OpusDecoder *audio_decoder;
183+
OpusDecoder *_Nullable audio_decoder;
184184
int decoder_channels;
185185
unsigned int last_packet_samples;
186186
} Group_Peer_AV;

toxav/ring_buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct RingBuffer {
1313
uint16_t size; /* Max size */
1414
uint16_t start;
1515
uint16_t end;
16-
void **data;
16+
void *_Nullable *_Nonnull data;
1717
};
1818

1919
bool rb_full(const RingBuffer *b)

toxav/rtp.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct RTPWorkBuffer {
104104
/**
105105
* The message currently being assembled.
106106
*/
107-
struct RTPMessage *buf;
107+
struct RTPMessage *_Nullable buf;
108108
};
109109

110110
struct RTPWorkBufferList {
@@ -121,22 +121,22 @@ struct RTPSession {
121121
uint16_t rsequnum; /* Receiving sequence number */
122122
uint32_t rtimestamp;
123123
uint32_t ssrc; // this seems to be unused!?
124-
struct RTPMessage *mp; /* Expected parted message */
125-
struct RTPWorkBufferList *work_buffer_list;
124+
struct RTPMessage *_Nullable mp; /* Expected parted message */
125+
struct RTPWorkBufferList *_Nonnull work_buffer_list;
126126
uint8_t first_packets_counter; /* dismiss first few lost video packets */
127-
const Logger *log;
128-
Mono_Time *mono_time;
127+
const Logger *_Nonnull log;
128+
Mono_Time *_Nonnull mono_time;
129129
bool rtp_receive_active; /* if this is set to false then incoming rtp packets will not be processed by rtp_receive_packet() */
130130

131-
rtp_send_packet_cb *send_packet;
132-
void *send_packet_user_data;
131+
rtp_send_packet_cb *_Nullable send_packet;
132+
void *_Nullable send_packet_user_data;
133133

134-
rtp_add_recv_cb *add_recv;
135-
rtp_add_lost_cb *add_lost;
136-
void *bwc_user_data;
134+
rtp_add_recv_cb *_Nullable add_recv;
135+
rtp_add_lost_cb *_Nullable add_lost;
136+
void *_Nullable bwc_user_data;
137137

138-
void *cs;
139-
rtp_m_cb *mcb;
138+
void *_Nonnull cs;
139+
rtp_m_cb *_Nonnull mcb;
140140
};
141141

142142
const uint8_t *rtp_message_data(const RTPMessage *msg)

0 commit comments

Comments
 (0)