Skip to content

Commit 6b4f4a8

Browse files
committed
refactor: Implement buffered event dispatch in tox_iterate.
1 parent d5b5e87 commit 6b4f4a8

61 files changed

Lines changed: 322 additions & 601 deletions

Some content is hidden

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

auto_tests/BUILD.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ cc_library(
1616
deps = [
1717
":check_compat",
1818
"//c-toxcore/testing:misc_tools",
19+
"//c-toxcore/toxcore",
1920
"//c-toxcore/toxcore:DHT",
2021
"//c-toxcore/toxcore:Messenger",
2122
"//c-toxcore/toxcore:mono_time",
2223
"//c-toxcore/toxcore:net_crypto",
2324
"//c-toxcore/toxcore:tox",
2425
"//c-toxcore/toxcore:tox_dispatch",
25-
"//c-toxcore/toxcore:tox_events",
2626
"//c-toxcore/toxcore:tox_log_level",
2727
],
2828
)
@@ -59,6 +59,7 @@ extra_data = {
5959
":check_compat",
6060
"//c-toxcore/testing:misc_tools",
6161
"//c-toxcore/toxav",
62+
"//c-toxcore/toxcore",
6263
"//c-toxcore/toxcore:Messenger",
6364
"//c-toxcore/toxcore:TCP_client",
6465
"//c-toxcore/toxcore:TCP_common",
@@ -81,8 +82,6 @@ extra_data = {
8182
"//c-toxcore/toxcore:os_random",
8283
"//c-toxcore/toxcore:tox",
8384
"//c-toxcore/toxcore:tox_dispatch",
84-
"//c-toxcore/toxcore:tox_events",
85-
"//c-toxcore/toxcore:tox_unpack",
8685
"//c-toxcore/toxcore:util",
8786
"//c-toxcore/toxencryptsave",
8887
"@libsodium",

auto_tests/scenarios/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ cc_library(
99
deps = [
1010
"//c-toxcore/auto_tests:check_compat",
1111
"//c-toxcore/testing:misc_tools",
12+
"//c-toxcore/toxcore",
1213
"//c-toxcore/toxcore:attributes",
1314
"//c-toxcore/toxcore:ccompat",
1415
"//c-toxcore/toxcore:mono_time",
1516
"//c-toxcore/toxcore:network",
1617
"//c-toxcore/toxcore:tox",
1718
"//c-toxcore/toxcore:tox_dispatch",
18-
"//c-toxcore/toxcore:tox_events",
1919
],
2020
)
2121

@@ -26,7 +26,7 @@ cc_library(
2626
deps = [
2727
":scenario_framework",
2828
"//c-toxcore/toxav",
29+
"//c-toxcore/toxcore",
2930
"//c-toxcore/toxcore:tox",
30-
"//c-toxcore/toxcore:tox_events",
3131
],
3232
) for src in glob(["scenario_*_test.c"])]

auto_tests/scenarios/framework/framework.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,6 @@ ToxNode *tox_scenario_add_node_ex(ToxScenario *s, const char *alias, tox_node_sc
577577
}
578578

579579
node->dispatch = tox_dispatch_new(nullptr);
580-
tox_events_init(node->tox);
581580
mono_time_set_current_time_callback(node->tox->mono_time, get_scenario_clock, s);
582581

583582
// Initial mirror population
@@ -784,7 +783,6 @@ void tox_node_reload(ToxNode *node)
784783

785784
ck_assert_msg(new_tox != nullptr, "tox_new said OK but returned NULL");
786785
Tox_Dispatch *new_dispatch = tox_dispatch_new(nullptr);
787-
tox_events_init(new_tox);
788786
mono_time_set_current_time_callback(new_tox->mono_time, get_scenario_clock, s);
789787

790788
pthread_mutex_lock(&s->mutex);

auto_tests/tox_dispatch_test.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ static void test_tox_events(void)
108108
for (uint32_t i = 0; i < 2; ++i) {
109109
index[i] = i + 1;
110110
toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
111-
tox_events_init(toxes[i]);
112111
ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
113112
}
114113

other/docker/esp32/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ cc_binary(
99
"main/tox_main.h",
1010
],
1111
deps = [
12+
"//c-toxcore/toxcore",
1213
"//c-toxcore/toxcore:ccompat",
1314
"//c-toxcore/toxcore:tox",
14-
"//c-toxcore/toxcore:tox_events",
1515
],
1616
)

other/docker/modules/check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class BuildContext:
110110
def bzl_exports_files(self, *args: Any, **kwargs: Any) -> None:
111111
pass
112112

113-
def bzl_alias(self, *args: Any, **kwargs: Any) -> None:
114-
pass
113+
def bzl_alias(self, name: str, actual: str, **kwargs: Any) -> None:
114+
self._add_target(name, (), (), (actual, ))
115115

116116
def bzl_sh_library(self, *args: Any, **kwargs: Any) -> None:
117117
pass

other/event_tooling/generate_event_c.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,9 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
582582
583583
)";
584584
f << "void tox_events_handle_" << event_name_l << "(\n";
585-
f << " Tox *tox";
586585

587586
for (const auto& t : event_types) {
588-
f << ",\n ";
587+
f << " ";
589588
std::visit(
590589
overloaded{
591590
[&](const EventTypeTrivial& t) {
@@ -600,11 +599,11 @@ void generate_event_impl(const std::string& event_name, const std::vector<EventT
600599
},
601600
t
602601
);
602+
f << ",\n";
603603
}
604604

605-
f << ",\n void *user_data)\n{\n";
606-
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
607-
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_event_" << event_name_l << "_alloc(state);\n\n";
605+
f << " Tox_Events_State *state)\n{\n";
606+
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_event_" << event_name_l << "_alloc(tox_events_alloc(state));\n\n";
608607
f << " if (" << event_name_l << " == nullptr) {\n return;\n }\n\n";
609608

610609
for (const auto& t : event_types) {

testing/fuzzing/BUILD.bazel

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ cc_fuzz_test(
99
corpus = ["//tools/toktok-fuzzer/corpus:bootstrap_fuzz_test"],
1010
deps = [
1111
"//c-toxcore/testing/support",
12+
"//c-toxcore/toxcore",
1213
"//c-toxcore/toxcore:tox",
13-
"//c-toxcore/toxcore:tox_dispatch",
14-
"//c-toxcore/toxcore:tox_events",
1514
],
1615
)
1716

@@ -24,10 +23,9 @@ cc_fuzz_test(
2423
data = ["//tools/toktok-fuzzer/init:e2e_fuzz_test.dat"],
2524
deps = [
2625
"//c-toxcore/testing/support",
26+
"//c-toxcore/toxcore",
2727
"//c-toxcore/toxcore:crypto_core",
2828
"//c-toxcore/toxcore:tox",
29-
"//c-toxcore/toxcore:tox_dispatch",
30-
"//c-toxcore/toxcore:tox_events",
3129
],
3230
)
3331

@@ -49,9 +47,8 @@ cc_binary(
4947
copts = ["-UNDEBUG"],
5048
deps = [
5149
"//c-toxcore/testing/support",
50+
"//c-toxcore/toxcore",
5251
"//c-toxcore/toxcore:tox",
53-
"//c-toxcore/toxcore:tox_dispatch",
54-
"//c-toxcore/toxcore:tox_events",
5552
"//c-toxcore/toxcore:util",
5653
],
5754
)

testing/fuzzing/bootstrap_fuzz_test.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ void TestBootstrap(Fuzz_Data &input)
190190
tox_bootstrap(tox, "127.0.0.2", 33446, pub_key, nullptr);
191191
tox_add_tcp_relay(tox, "127.0.0.2", 33446, pub_key, nullptr);
192192

193-
tox_events_init(tox);
194-
195193
Tox_Dispatch *dispatch = tox_dispatch_new(nullptr);
196194
assert(dispatch != nullptr);
197195
setup_callbacks(dispatch);

testing/fuzzing/e2e_fuzz_test.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,6 @@ void TestEndToEnd(Fuzz_Data &input)
202202
assert(error_new == TOX_ERR_NEW_OK);
203203
assert(error_new_testing == TOX_ERR_NEW_TESTING_OK);
204204

205-
tox_events_init(tox);
206-
207205
Tox_Dispatch *dispatch = tox_dispatch_new(nullptr);
208206
assert(dispatch != nullptr);
209207
setup_callbacks(dispatch);

0 commit comments

Comments
 (0)