Add a check that we don't have any unused functions.

This check puts all of our code in a C++ anonymous namespace, which is
effectively making all functions `static`. This allows the compiler to
determine that a function is unused, so we can delete it.
This commit is contained in:
iphydf 2020-05-02 00:34:13 +01:00
parent 2570ddcb17
commit f8ab32aaa4
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
14 changed files with 28 additions and 123 deletions

View File

@ -17,20 +17,20 @@ put() {
if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >> amalgamation.cc
fi
cat $1 >> amalgamation.cc
cat "$1" >> amalgamation.cc
}
putmain() {
echo "namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc
echo "namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc
if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >> amalgamation.cc
fi
sed -e 's/^int main(/static &/' $1 >> amalgamation.cc
echo "} // namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc
sed -e 's/^int main(/static &/' "$1" >> amalgamation.cc
echo "} // namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc
}
callmain() {
echo " call($(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc
echo " call($(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc
}
:> amalgamation.cc
@ -53,25 +53,32 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
for i in $(eval $FIND_QUERY); do
if ! grep -q '^int main(' $i; then
put $i
(for i in $(eval "$FIND_QUERY"); do
grep -o '#include <[^>]*>' "$i" \
| grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
done) | sort -u >> amalgamation.cc
echo 'namespace {' >> amalgamation.cc
for i in $(eval "$FIND_QUERY"); do
if ! grep -q '^int main(' "$i"; then
put "$i"
fi
done
for i in $(eval $FIND_QUERY); do
if grep -q '^int main(' $i; then
putmain $i
for i in $(eval "$FIND_QUERY"); do
if grep -q '^int main(' "$i"; then
putmain "$i"
fi
done
echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc
echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc
echo '} // namespace' >> amalgamation.cc
echo "int main(int argc, char **argv) {" >> amalgamation.cc
for i in $(eval $FIND_QUERY); do
if grep -q '^int main(' $i; then
callmain $i
for i in $(eval "$FIND_QUERY"); do
if grep -q '^int main(' "$i"; then
callmain "$i"
fi
done
echo " return 0;" >> amalgamation.cc

View File

@ -1 +1 @@
e7b6d31485b5e1561659be08f3e3ef003cef186042d7e0fe2ef48cf341932b5a /usr/local/bin/tox-bootstrapd
89df21d6a19a1b6652db5b7e6e9f65ad5f8be8abdca9f58645548b9e0c9383e3 /usr/local/bin/tox-bootstrapd

View File

@ -3,4 +3,4 @@
#include ANDROID_CPU_FEATURES
#endif
extern int unused_declaration;
typedef int unused_declaration;

View File

@ -17,6 +17,7 @@
#define _XOPEN_SOURCE 600
#endif
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

View File

@ -21,7 +21,7 @@ namespace lan_discovery {
/**
* Interval in seconds between LAN discovery packet sending.
*/
const INTERVAL = 10;
#define LAN_DISCOVERY_INTERVAL 10
/**
* Send a LAN discovery pcaket to the broadcast address with port port.

View File

@ -26,8 +26,6 @@ typedef struct IP IP;
*/
#define LAN_DISCOVERY_INTERVAL 10
uint32_t lan_discovery_interval(void);
/**
* Send a LAN discovery pcaket to the broadcast address with port port.
*/

View File

@ -1450,38 +1450,6 @@ int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
return -6;
}
/* Give the number of bytes left to be sent/received.
*
* send_receive is 0 if we want the sending files, 1 if we want the receiving.
*
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive)
{
if (!friend_is_valid(m, friendnumber)) {
return 0;
}
const struct File_Transfers *const sending = &m->friendlist[friendnumber].file_sending[filenumber];
if (send_receive == 0) {
if (sending->status == FILESTATUS_NONE) {
return 0;
}
return sending->size - sending->transferred;
}
const struct File_Transfers *const receiving = &m->friendlist[friendnumber].file_receiving[filenumber];
if (receiving->status == FILESTATUS_NONE) {
return 0;
}
return receiving->size - receiving->transferred;
}
/**
* Iterate over all file transfers and request chunks (from the client) for each
* of them.

View File

@ -651,15 +651,6 @@ int file_seek(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uin
int file_data(const Messenger *m, int32_t friendnumber, uint32_t filenumber, uint64_t position, const uint8_t *data,
uint16_t length);
/* Give the number of bytes left to be sent/received.
*
* send_receive is 0 if we want the sending files, 1 if we want the receiving.
*
* return number of bytes remaining to be sent/received on success
* return 0 on failure
*/
uint64_t file_dataremaining(const Messenger *m, int32_t friendnumber, uint8_t filenumber, uint8_t send_receive);
/** A/V related */
/* Set the callback for msi packets.

View File

@ -12,11 +12,12 @@
#include "config.h"
#endif
#include "crypto_core.h"
#include <stdlib.h>
#include <string.h>
#include "ccompat.h"
#include "crypto_core.h"
#ifndef VANILLA_NACL
/* We use libsodium by default. */

View File

@ -1301,36 +1301,6 @@ int group_set_max_frozen(const Group_Chats *g_c, uint32_t groupnumber, uint32_t
return 0;
}
/* List all the (frozen, if frozen is true) peers in the group chat.
*
* Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array.
*
* Copies the lengths of the names to `lengths[length]`
*
* returns the number of peers on success.
*
* return -1 on failure.
*/
int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[],
uint16_t length, bool frozen)
{
const Group_c *g = get_group_c(g_c, groupnumber);
if (!g) {
return -1;
}
const uint32_t num = frozen ? g->numfrozen : g->numpeers;
unsigned int i;
for (i = 0; i < num && i < length; ++i) {
lengths[i] = group_peername(g_c, groupnumber, i, names[i], frozen);
}
return i;
}
/* Return the number of (frozen, if frozen is true) peers in the group chat on
* success.
* return -1 if groupnumber is invalid.

View File

@ -355,19 +355,6 @@ int group_number_peers(const Group_Chats *g_c, uint32_t groupnumber, bool frozen
*/
int group_peernumber_is_ours(const Group_Chats *g_c, uint32_t groupnumber, uint32_t peernumber);
/* List all the (frozen, if frozen is true) peers in the group chat.
*
* Copies the names of the peers to the `name[length][MAX_NAME_LENGTH]` array.
*
* Copies the lengths of the names to `lengths[length]`
*
* returns the number of peers on success.
*
* return -1 on failure.
*/
int group_names(const Group_Chats *g_c, uint32_t groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[],
uint16_t length, bool frozen);
/* Set handlers for custom lossy packets. */
void group_lossy_packet_registerhandler(Group_Chats *g_c, uint8_t byte, lossy_packet_cb *function);

View File

@ -248,13 +248,3 @@ int bs_list_remove(BS_List *list, const uint8_t *data, int id)
return 1;
}
int bs_list_trim(BS_List *list)
{
if (!resize(list, list->n)) {
return 0;
}
list->capacity = list->n;
return 1;
}

View File

@ -57,12 +57,4 @@ int bs_list_add(BS_List *list, const uint8_t *data, int id);
*/
int bs_list_remove(BS_List *list, const uint8_t *data, int id);
/* Removes the memory overhead
*
* return value:
* 1 : success
* 0 : failure
*/
int bs_list_trim(BS_List *list);
#endif

View File

@ -398,4 +398,4 @@ escrypt_kdf_sse(escrypt_local_t * local,
#endif
/* ISO C requires a translation unit to contain at least one declaration */
extern int non_empty_tu_decl;
typedef int non_empty_tu_decl;