Squashed 'external/toxcore/c-toxcore/' changes from 6d634674a9..73d9b845a3

73d9b845a3 cleanup: Remove old type-ordered event getters.
b0840cc02d feat: add ngc events
7df9a51349 refactor: Make event dispatch ordered by receive time.
bcb6592af5 test: Add C++ classes wrapping system interfaces.
4cea4f9ca4 fix: Make all the fuzzers work again, and add a test for protodump.
c4e209ea1d refactor: Factor out malloc+memcpy into memdup.
87bcc4322d fix: Remove fatal error for non-erroneous case
REVERT: 6d634674a9 cleanup: Remove old type-ordered event getters.
REVERT: d1d48d1dfc feat: add ngc events
REVERT: 994ffecc6b refactor: Make event dispatch ordered by receive time.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: 73d9b845a310c3f56d2d6d77ed56b93d84256d6e
This commit is contained in:
2024-01-14 21:51:01 +01:00
parent 8eb4892b49
commit b1fe064484
39 changed files with 775 additions and 307 deletions

View File

@ -3,7 +3,10 @@
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <type_traits>
#include <vector>
template <typename T, void (*Delete)(T *)>
@ -41,7 +44,7 @@ std::array<T, N> to_array(T const (&arr)[N])
template <std::size_t N, typename T, typename... Args>
auto array_of(T &&make, Args... args)
{
std::array<typename std::result_of<T(Args...)>::type, N> arr;
std::array<std::invoke_result_t<T, Args...>, N> arr;
for (auto &elem : arr) {
elem = make(args...);
}
@ -51,7 +54,7 @@ auto array_of(T &&make, Args... args)
template <typename T, typename... Args>
auto vector_of(std::size_t n, T &&make, Args... args)
{
std::vector<typename std::result_of<T(Args...)>::type> vec;
std::vector<std::invoke_result_t<T, Args...>> vec;
for (std::size_t i = 0; i < n; ++i) {
vec.push_back(make(args...));
}
@ -65,4 +68,16 @@ Container sorted(Container arr, Less less)
return arr;
}
template <typename T>
T *require_not_null(const char *file, int line, T *ptr)
{
if (ptr == nullptr) {
std::fprintf(stderr, "unexpected null pointer at %s:%d\n", file, line);
std::exit(7);
}
return ptr;
}
#define REQUIRE_NOT_NULL(ptr) require_not_null(__FILE__, __LINE__, ptr)
#endif // C_TOXCORE_TOXCORE_TEST_UTIL_H