Skip to content

Commit 40b3f0b

Browse files
committed
refactor: Use clang's nullability qualifiers instead of attributes.
1 parent f81e306 commit 40b3f0b

File tree

134 files changed

+2793
-2784
lines changed

Some content is hidden

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

134 files changed

+2793
-2784
lines changed

.circleci/config.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,12 @@ jobs:
125125
cimple:
126126
working_directory: /tmp/cirrus-ci-build
127127
docker:
128-
- image: toxchat/toktok-stack:latest-release
128+
- image: toxchat/toktok-stack:latest
129129

130130
steps:
131131
- checkout
132-
- run: git submodule update --init --recursive
133-
- run: /src/workspace/tools/inject-repo c-toxcore
134-
- run: cd /src/workspace &&
135-
bazel test
136-
-k
132+
- run:
133+
CIRCLE_JOB=release bash <(curl -s https://raw.githubusercontent.com/TokTok/ci-tools/refs/heads/master/tools/circleci-bazel-test)
137134
--build_tag_filters=haskell
138135
--test_tag_filters=haskell
139136
--

.github/scripts/flags-clang.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ add_flag -Weverything
99

1010
# Disable specific warning flags for both C and C++.
1111

12+
# We're not checking nullability, yet.
13+
# TODO(iphydf): Remove.
14+
add_flag -Wno-nullable-to-nonnull-conversion
15+
add_flag -Wno-nullability-completeness
16+
1217
# Very verbose, not very useful. This warns about things like int -> uint
1318
# conversions that change sign without a cast and narrowing conversions.
1419
add_flag -Wno-conversion
@@ -30,6 +35,8 @@ add_flag -Wno-missing-braces
3035
add_flag -Wno-missing-field-initializers
3136
# We don't use this attribute. It appears in the non-NDEBUG stderr logger.
3237
add_flag -Wno-missing-noreturn
38+
# We want to use this extension.
39+
add_flag -Wno-nullability-extension
3340
# Useful sometimes, but we accept padding in structs for clarity.
3441
# Reordering fields to avoid padding will reduce readability.
3542
add_flag -Wno-padded

other/analysis/run-clang

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ run() {
2525
-Wno-missing-braces \
2626
-Wno-missing-field-initializers \
2727
-Wno-missing-noreturn \
28+
-Wno-nullability-completeness \
29+
-Wno-nullability-extension \
30+
-Wno-nullable-to-nonnull-conversion \
2831
-Wno-old-style-cast \
2932
-Wno-padded \
33+
-Wno-source-uses-openmp \
3034
-Wno-switch-default \
3135
-Wno-tautological-pointer-compare \
3236
-Wno-unreachable-code-return \
3337
-Wno-unsafe-buffer-usage \
3438
-Wno-unused-parameter \
35-
-Wno-used-but-marked-unused \
36-
-Wno-source-uses-openmp
39+
-Wno-used-but-marked-unused
3740
}
3841

3942
. other/analysis/variants.sh

other/analysis/run-clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ ERRORS="*"
77
# Still good to occasionally look at.
88
ERRORS="$ERRORS,-google-readability-casting"
99

10+
# TODO(iphydf): Fix these.
11+
CHECKS="$CHECKS,-clang-analyzer-nullability.NullableDereferenced"
12+
CHECKS="$CHECKS,-clang-analyzer-nullability.NullablePassedToNonnull"
13+
CHECKS="$CHECKS,-clang-analyzer-nullability.NullPassedToNonnull"
14+
1015
# Need to investigate or disable and document these.
1116
# =========================================================
1217

other/event_tooling/generate_event_c.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,14 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
228228
},
229229
t
230230
);
231-
f << "(non_null() Tox_Event_" << event_name << " *" << event_name_l << ",";
231+
f << "(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ",";
232232
std::visit(
233233
overloaded{
234234
[&](const EventTypeTrivial& t) {
235235
f << " " << t.type << " " << t.name << ")\n";
236236
},
237237
[&](const EventTypeByteRange& t) {
238-
f << "\n nullable() const uint8_t *" << t.name_data << ", uint32_t " << t.name_length << ")\n";
238+
f << "\n const uint8_t *_Nullable " << t.name_data << ", uint32_t " << t.name_length << ")\n";
239239
}
240240
},
241241
t
@@ -296,14 +296,14 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
296296

297297

298298
// gen contruct
299-
f << "static void tox_event_" << event_name_l << "_construct(non_null() Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
299+
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ")\n{\n";
300300
// TODO: initialize all members properly
301301
// TODO: check if _NONE is universal
302302
// str_toupper(
303303
f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n";
304304

305305
// gen destruct
306-
f << "static void tox_event_" << event_name_l << "_destruct(non_null() Tox_Event_" << event_name << " *" << event_name_l << ", non_null() const Memory *mem)\n{\n";
306+
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *_Nonnull " << event_name_l << ", const Memory *_Nonnull mem)\n{\n";
307307
size_t data_count = 0;
308308
for (const auto& t : event_types) {
309309
std::visit(
@@ -361,7 +361,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
361361
f << ";\n}\n\n";
362362

363363
// unpack
364-
f << "static bool tox_event_" << event_name_l << "_unpack_into(non_null() Tox_Event_" << event_name << " *event, non_null() Bin_Unpack *bu)\n{\n";
364+
f << "static bool tox_event_" << event_name_l << "_unpack_into(Tox_Event_" << event_name << " *_Nonnull event, Bin_Unpack *_Nonnull bu)\n{\n";
365365
f << " assert(event != nullptr);\n";
366366
if (event_types.size() > 1) {
367367
f << " if (!bin_unpack_array_fixed(bu, " << event_types.size() << ", nullptr)) {\n return false;\n }\n\n";
@@ -421,7 +421,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
421421
f << " mem_delete(mem, " << event_name_l << ");\n}\n\n";
422422

423423
// add
424-
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(non_null() Tox_Events *events, non_null() const Memory *mem)\n{\n";
424+
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *_Nonnull events, const Memory *_Nonnull mem)\n{\n";
425425
f << " Tox_Event_" << event_name << " *const " << event_name_l << " = tox_event_" << event_name_l << "_new(mem);\n\n";
426426
f << " if (" << event_name_l << " == nullptr) {\n";
427427
f << " return nullptr;\n }\n\n";
@@ -444,7 +444,7 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
444444
f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n";
445445

446446
// alloc
447-
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(non_null() void *user_data)\n{\n";
447+
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *_Nonnull user_data)\n{\n";
448448
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
449449
f << " assert(state != nullptr);\n\n";
450450
f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n";

toxav/toxav_hacks.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
typedef struct ToxAVCall ToxAVCall;
1515
#endif /* TOXAV_CALL_DEFINED */
1616

17-
ToxAVCall *call_get(non_null() ToxAV *av, uint32_t friend_number);
17+
ToxAVCall *_Nullable call_get(ToxAV *_Nonnull av, uint32_t friend_number);
1818

19-
RTPSession *rtp_session_get(non_null() ToxAVCall *call, int payload_type);
19+
RTPSession *_Nullable rtp_session_get(ToxAVCall *_Nonnull call, int payload_type);
2020

21-
MSISession *tox_av_msi_get(non_null() const ToxAV *av);
21+
MSISession *_Nullable tox_av_msi_get(const ToxAV *_Nonnull av);
2222

23-
BWController *bwc_controller_get(non_null() const ToxAVCall *call);
23+
BWController *_Nullable bwc_controller_get(const ToxAVCall *_Nonnull call);
2424

25-
Mono_Time *toxav_get_av_mono_time(non_null() const ToxAV *av);
25+
Mono_Time *_Nullable toxav_get_av_mono_time(const ToxAV *_Nonnull av);
2626

27-
const Logger *toxav_get_logger(non_null() const ToxAV *av);
27+
const Logger *_Nonnull toxav_get_logger(const ToxAV *_Nonnull av);
2828

2929
#endif /* C_TOXCORE_TOXAV_HACKS_H */

0 commit comments

Comments
 (0)