From d4164edb548b95f23afc4f095651bab71a456f06 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 25 Jan 2025 21:57:03 +0000 Subject: [PATCH] refactor: Remove tox_types.h; use `struct` tags instead. This header was a nice idea but causes a *lot* of pain with C++ modules. --- BUILD.bazel | 3 --- CMakeLists.txt | 5 +--- other/docker/pkgsrc/pkgsrc.patch | 3 +-- toxcore/BUILD.bazel | 14 +---------- toxcore/Makefile.inc | 5 +--- toxcore/tox.h | 3 +-- toxcore/tox_options.h | 11 +++++---- toxcore/tox_private.c | 3 +-- toxcore/tox_private.h | 2 +- toxcore/tox_types.c | 6 ----- toxcore/tox_types.h | 40 -------------------------------- 11 files changed, 13 insertions(+), 82 deletions(-) delete mode 100644 toxcore/tox_types.c delete mode 100644 toxcore/tox_types.h diff --git a/BUILD.bazel b/BUILD.bazel index e84606069..5bd521fb7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -12,7 +12,6 @@ genrule( "//c-toxcore/toxcore:tox_events.h", "//c-toxcore/toxcore:tox_options.h", "//c-toxcore/toxcore:tox_private.h", - "//c-toxcore/toxcore:tox_types.h", "//c-toxcore/toxencryptsave:toxencryptsave.h", ], outs = [ @@ -22,7 +21,6 @@ genrule( "tox/tox_events.h", "tox/tox_options.h", "tox/tox_private.h", - "tox/tox_types.h", "tox/toxencryptsave.h", ], cmd = """ @@ -32,7 +30,6 @@ genrule( cp $(location //c-toxcore/toxcore:tox_events.h) $(GENDIR)/c-toxcore/tox/tox_events.h cp $(location //c-toxcore/toxcore:tox_options.h) $(GENDIR)/c-toxcore/tox/tox_options.h cp $(location //c-toxcore/toxcore:tox_private.h) $(GENDIR)/c-toxcore/tox/tox_private.h - cp $(location //c-toxcore/toxcore:tox_types.h) $(GENDIR)/c-toxcore/tox/tox_types.h cp $(location //c-toxcore/toxencryptsave:toxencryptsave.h) $(GENDIR)/c-toxcore/tox/toxencryptsave.h """, visibility = ["//visibility:public"], diff --git a/CMakeLists.txt b/CMakeLists.txt index 63c955ae9..2331fa2d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,8 +354,6 @@ set(toxcore_SOURCES toxcore/tox_private.h toxcore/tox_pack.c toxcore/tox_pack.h - toxcore/tox_types.c - toxcore/tox_types.h toxcore/tox_unpack.c toxcore/tox_unpack.h toxcore/util.c @@ -375,8 +373,7 @@ set(toxcore_API_HEADERS ${toxcore_SOURCE_DIR}/toxcore/tox.h^tox ${toxcore_SOURCE_DIR}/toxcore/tox_dispatch.h^tox ${toxcore_SOURCE_DIR}/toxcore/tox_events.h^tox - ${toxcore_SOURCE_DIR}/toxcore/tox_options.h^tox - ${toxcore_SOURCE_DIR}/toxcore/tox_types.h^tox) + ${toxcore_SOURCE_DIR}/toxcore/tox_options.h^tox) if(EXPERIMENTAL_API) set(toxcore_API_HEADERS ${toxcore_API_HEADERS} ${toxcore_SOURCE_DIR}/toxcore/tox_private.h^tox) diff --git a/other/docker/pkgsrc/pkgsrc.patch b/other/docker/pkgsrc/pkgsrc.patch index 5db437e08..6d16b8aa8 100644 --- a/other/docker/pkgsrc/pkgsrc.patch +++ b/other/docker/pkgsrc/pkgsrc.patch @@ -14,12 +14,11 @@ diff --git a/chat/toxcore/PLIST b/chat/toxcore/PLIST index f0a5e4f04..4122b0867 100644 --- a/chat/toxcore/PLIST +++ b/chat/toxcore/PLIST -@@ -4,11 +4,13 @@ bin/tox-bootstrapd +@@ -4,11 +4,12 @@ bin/tox-bootstrapd include/tox/tox.h include/tox/tox_dispatch.h include/tox/tox_events.h +include/tox/tox_options.h -+include/tox/tox_types.h include/tox/toxav.h include/tox/toxencryptsave.h lib/libtoxcore.a diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index 0a794bfe5..1469f51c1 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -8,7 +8,6 @@ exports_files( "tox_events.h", "tox_options.h", "tox_private.h", - "tox_types.h", ], visibility = ["//c-toxcore:__subpackages__"], ) @@ -1074,23 +1073,13 @@ cc_library( ], ) -cc_library( - name = "tox_types", - srcs = ["tox_types.c"], - hdrs = ["tox_types.h"], - visibility = ["//c-toxcore:__subpackages__"], -) - cc_library( name = "tox_options", srcs = ["tox_options.c"], hdrs = ["tox_options.h"], copts = ["-UTOX_HIDE_DEPRECATED"], visibility = ["//c-toxcore:__subpackages__"], - deps = [ - ":ccompat", - ":tox_types", - ], + deps = [":ccompat"], ) cc_library( @@ -1126,7 +1115,6 @@ cc_library( ":onion_client", ":state", ":tox_options", - ":tox_types", ":util", "//c-toxcore/toxencryptsave:defines", "@pthread", diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc index 4deb496a5..ff1faa5bc 100644 --- a/toxcore/Makefile.inc +++ b/toxcore/Makefile.inc @@ -2,8 +2,7 @@ lib_LTLIBRARIES += libtoxcore.la libtoxcore_la_include_HEADERS = \ ../toxcore/tox.h \ - ../toxcore/tox_options.h \ - ../toxcore/tox_types.h + ../toxcore/tox_options.h libtoxcore_la_includedir = $(includedir)/tox @@ -145,8 +144,6 @@ libtoxcore_la_SOURCES = ../third_party/cmp/cmp.c \ ../toxcore/tox_private.c \ ../toxcore/tox_private.h \ ../toxcore/tox_struct.h \ - ../toxcore/tox_types.c \ - ../toxcore/tox_types.h \ ../toxcore/tox_unpack.c \ ../toxcore/tox_unpack.h \ ../toxcore/tox.c \ diff --git a/toxcore/tox.h b/toxcore/tox.h index 8a9324499..5fabb6de4 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -103,7 +103,6 @@ #include #include "tox_options.h" // IWYU pragma: export -#include "tox_types.h" // IWYU pragma: export #ifdef __cplusplus extern "C" { @@ -120,7 +119,7 @@ extern "C" { * device is limited. Note that this is not just a per-process limit, since the * limiting factor is the number of usable ports on a device. */ -struct Tox; +typedef struct Tox Tox; /** @{ * @name API version diff --git a/toxcore/tox_options.h b/toxcore/tox_options.h index 6cf6b93c2..31b797bcd 100644 --- a/toxcore/tox_options.h +++ b/toxcore/tox_options.h @@ -10,12 +10,12 @@ #include #include -#include "tox_types.h" // IWYU pragma: export - #ifdef __cplusplus extern "C" { #endif +struct Tox; + /** @{ * @name Startup options */ @@ -117,8 +117,9 @@ const char *tox_log_level_to_string(Tox_Log_Level value); * @param message The log message. * @param user_data The user data pointer passed to tox_new in options. */ -typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line, - const char *func, const char *message, void *user_data); +typedef void tox_log_cb(struct Tox *tox, Tox_Log_Level level, const char *file, + uint32_t line, const char *func, const char *message, + void *user_data); /** * @brief This struct contains all the startup options for Tox. @@ -135,7 +136,7 @@ typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_ * members. The struct will become opaque (i.e. the definition will become * private) in v0.3.0. */ -struct Tox_Options; +typedef struct Tox_Options Tox_Options; #ifndef TOX_HIDE_DEPRECATED struct Tox_Options { diff --git a/toxcore/tox_private.c b/toxcore/tox_private.c index d7e13ac13..1cb2dd6dc 100644 --- a/toxcore/tox_private.c +++ b/toxcore/tox_private.c @@ -12,7 +12,6 @@ #include "DHT.h" #include "TCP_server.h" -#include "attributes.h" #include "ccompat.h" #include "crypto_core.h" #include "group_chats.h" @@ -23,7 +22,7 @@ #include "net_profile.h" #include "network.h" #include "tox.h" -#include "tox_struct.h" +#include "tox_struct.h" // IWYU pragma: keep #define SET_ERROR_PARAMETER(param, x) \ do { \ diff --git a/toxcore/tox_private.h b/toxcore/tox_private.h index 0b7116776..dec60645f 100644 --- a/toxcore/tox_private.h +++ b/toxcore/tox_private.h @@ -11,7 +11,7 @@ #include #include "tox.h" -#include "tox_types.h" +#include "tox_options.h" #ifdef __cplusplus extern "C" { diff --git a/toxcore/tox_types.c b/toxcore/tox_types.c deleted file mode 100644 index f9c16fe5f..000000000 --- a/toxcore/tox_types.c +++ /dev/null @@ -1,6 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2025 The TokTok team. - * Copyright © 2013 Tox project. - */ - -#include "tox_types.h" // IWYU pragma: keep diff --git a/toxcore/tox_types.h b/toxcore/tox_types.h deleted file mode 100644 index e471f0b45..000000000 --- a/toxcore/tox_types.h +++ /dev/null @@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later - * Copyright © 2016-2025 The TokTok team. - * Copyright © 2013 Tox project. - */ - -/** @brief Typedefs for Tox types. - * - * This file contains typedefs for Tox structs. It's not necessary to include - * this file directly, as it's included and exported by other headers with - * functions. - * - * More documentation about the types is available in the respective header - * files, e.g. tox.h, tox_options.h, etc. linked in the comments. - */ -#ifndef C_TOXCORE_TOXCORE_TOX_TYPES_H -#define C_TOXCORE_TOXCORE_TOX_TYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** @{ @namespace tox */ - -#ifndef TOX_DEFINED -#define TOX_DEFINED -typedef struct Tox Tox; // tox.h -#endif /* TOX_DEFINED */ - -#ifndef TOX_OPTIONS_DEFINED -#define TOX_OPTIONS_DEFINED -typedef struct Tox_Options Tox_Options; // tox_options.h -#endif /* TOX_OPTIONS_DEFINED */ - -/** @} */ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* C_TOXCORE_TOXCORE_TOX_TYPES_H */