Skip to content

Commit

Permalink
cleanup: Add a TOX_HIDE_DEPRECATED check to hide deprecated symbols.
Browse files Browse the repository at this point in the history
Compiling with that flag will make tox compile roughly as if it were
v0.3.0.
  • Loading branch information
iphydf committed Dec 28, 2024
1 parent 8a96816 commit 69be322
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
12 changes: 6 additions & 6 deletions auto_tests/save_compatibility_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ static uint8_t *read_save(const char *save_path, size_t *length)

static void test_save_compatibility(const char *save_path)
{
struct Tox_Options options = {0};
tox_options_default(&options);
Tox_Options *options = tox_options_new(nullptr);
ck_assert(options != nullptr);

size_t size = 0;
uint8_t *save_data = read_save(save_path, &size);
ck_assert_msg(save_data != nullptr, "error while reading save file '%s'", save_path);

options.savedata_data = save_data;
options.savedata_length = size;
options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE;
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, save_data, size);

size_t index = 0;
Tox_Err_New err;
Tox *tox = tox_new_log(&options, &err, &index);
Tox *tox = tox_new_log(options, &err, &index);
ck_assert_msg(tox, "failed to create tox, error number: %d", err);

tox_options_free(options);
free(save_data);

const size_t name_size = tox_self_get_name_size(tox);
Expand Down
3 changes: 2 additions & 1 deletion toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define _XOPEN_SOURCE 600
#endif /* _XOPEN_SOURCE */

#undef TOX_HIDE_DEPRECATED
#include "tox.h"

#include <assert.h>
Expand All @@ -33,7 +34,7 @@
#include "onion_client.h"
#include "state.h"
#include "tox_private.h"
#include "tox_struct.h"
#include "tox_struct.h" // IWYU pragma: keep
#include "util.h"

#include "../toxencryptsave/defines.h"
Expand Down
17 changes: 17 additions & 0 deletions toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
* If any other thread calls tox_self_set_name while this thread is allocating
* memory, the length may have become invalid, and the call to
* tox_self_get_name may cause undefined behaviour.
*
* @section deprecations
*
* Some functions and types are deprecated. We recommend compiling with
* `-DTOX_HIDE_DEPRECATED` to hide them. They will be removed in the next major
* version of Tox (and since we're in major version 0, that means the next
* minor version).
*/
#ifndef C_TOXCORE_TOXCORE_TOX_H
#define C_TOXCORE_TOXCORE_TOX_H
Expand Down Expand Up @@ -512,6 +519,7 @@ typedef void tox_log_cb(Tox *tox, Tox_Log_Level level, const char *file, uint32_
* private) in v0.3.0.
*/
typedef struct Tox_Options Tox_Options;
#ifndef TOX_HIDE_DEPRECATED
struct Tox_Options {

/**
Expand Down Expand Up @@ -687,6 +695,7 @@ struct Tox_Options {
*/
bool experimental_disable_dns;
};
#endif /* TOX_HIDE_DEPRECATED */

bool tox_options_get_ipv6_enabled(const Tox_Options *options);

Expand Down Expand Up @@ -3165,6 +3174,7 @@ const char *tox_err_conference_by_id_to_string(Tox_Err_Conference_By_Id value);
Tox_Conference_Number tox_conference_by_id(
const Tox *tox, const uint8_t id[TOX_CONFERENCE_ID_SIZE], Tox_Err_Conference_By_Id *error);

#ifndef TOX_HIDE_DEPRECATED
/**
* @brief Get the conference unique ID.
*
Expand All @@ -3179,6 +3189,7 @@ Tox_Conference_Number tox_conference_by_id(
*/
bool tox_conference_get_uid(
const Tox *tox, Tox_Conference_Number conference_number, uint8_t uid[TOX_CONFERENCE_UID_SIZE]);
#endif /* TOX_HIDE_DEPRECATED */

typedef enum Tox_Err_Conference_By_Uid {

Expand All @@ -3201,6 +3212,7 @@ typedef enum Tox_Err_Conference_By_Uid {

const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value);

#ifndef TOX_HIDE_DEPRECATED
/**
* @brief Return the conference number associated with the specified uid.
*
Expand All @@ -3213,6 +3225,7 @@ const char *tox_err_conference_by_uid_to_string(Tox_Err_Conference_By_Uid value)
*/
Tox_Conference_Number tox_conference_by_uid(
const Tox *tox, const uint8_t uid[TOX_CONFERENCE_UID_SIZE], Tox_Err_Conference_By_Uid *error);
#endif /* TOX_HIDE_DEPRECATED */

/** @} */

Expand Down Expand Up @@ -3820,6 +3833,7 @@ typedef enum Tox_Err_Group_Reconnect {

const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value);

#ifndef TOX_HIDE_DEPRECATED
/**
* Reconnects to a group.
*
Expand All @@ -3834,6 +3848,7 @@ const char *tox_err_group_reconnect_to_string(Tox_Err_Group_Reconnect value);
* @deprecated Use `tox_group_join` instead.
*/
bool tox_group_reconnect(Tox *tox, Tox_Group_Number group_number, Tox_Err_Group_Reconnect *error);
#endif /* TOX_HIDE_DEPRECATED */

typedef enum Tox_Err_Group_Leave {

Expand Down Expand Up @@ -5747,6 +5762,7 @@ void tox_callback_group_moderation(Tox *tox, tox_group_moderation_cb *callback);
//!TOKSTYLE-
#ifndef DOXYGEN_IGNORE

#ifndef TOX_HIDE_DEPRECATED
typedef Tox_Err_Options_New TOX_ERR_OPTIONS_NEW;
typedef Tox_Err_New TOX_ERR_NEW;
typedef Tox_Err_Bootstrap TOX_ERR_BOOTSTRAP;
Expand Down Expand Up @@ -5786,6 +5802,7 @@ typedef Tox_Connection TOX_CONNECTION;
typedef Tox_File_Control TOX_FILE_CONTROL;
typedef Tox_Conference_Type TOX_CONFERENCE_TYPE;
typedef enum Tox_File_Kind TOX_FILE_KIND;
#endif /* TOX_HIDE_DEPRECATED */

#endif
//!TOKSTYLE+
Expand Down
1 change: 1 addition & 0 deletions toxcore/tox_api.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2021 The TokTok team.
*/
#undef TOX_HIDE_DEPRECATED
#include "tox.h"

#include <stdlib.h>
Expand Down

0 comments on commit 69be322

Please sign in to comment.