mirror of
https://github.com/TokTok/c-toxcore
synced 2026-03-30 15:55:40 +00:00
Use <stdlib.h> for alloca on FreeBSD.
https://www.freebsd.org/cgi/man.cgi?alloca If stdlib.h does not define alloca, and we're using GCC (or Clang), we define the macro ourselves in terms of a GCC builtin.
This commit is contained in:
@@ -37,6 +37,7 @@ matrix:
|
||||
addons:
|
||||
apt: *apt-dependencies
|
||||
- stage: "Stage 1"
|
||||
if: type IN (push, api, cron)
|
||||
env: JOB=toxcore ENV=windows ARCH=i686
|
||||
group: deprecated-2017Q4
|
||||
services:
|
||||
|
||||
@@ -74,6 +74,17 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
# Warn on non-ISO C.
|
||||
add_cflag("-pedantic")
|
||||
|
||||
option(ERROR_ON_WARNING "Make compilation error on a warning" OFF)
|
||||
if(ERROR_ON_WARNING)
|
||||
add_flag("-Werror")
|
||||
endif()
|
||||
|
||||
option(DEBUG "Enable assertions and other debugging facilities" OFF)
|
||||
if(DEBUG)
|
||||
set(MIN_LOGGER_LEVEL DEBUG)
|
||||
add_cflag("-g3")
|
||||
endif()
|
||||
|
||||
option(WARNINGS "Enable additional compiler warnings" ON)
|
||||
if(WARNINGS)
|
||||
# Add all warning flags we can.
|
||||
@@ -91,12 +102,13 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_flag("-Wno-format-nonliteral")
|
||||
add_flag("-Wno-missing-field-initializers")
|
||||
add_flag("-Wno-missing-prototypes")
|
||||
add_flag("-Wno-packed")
|
||||
add_flag("-Wno-padded")
|
||||
add_flag("-Wno-parentheses")
|
||||
add_flag("-Wno-reserved-id-macro")
|
||||
add_flag("-Wno-return-type")
|
||||
add_flag("-Wno-sign-compare")
|
||||
add_flag("-Wno-sign-conversion")
|
||||
add_flag("-Wno-tautological-constant-out-of-range-compare")
|
||||
# Our use of mutexes results in a false positive, see 1bbe446
|
||||
add_flag("-Wno-thread-safety-analysis")
|
||||
add_flag("-Wno-type-limits")
|
||||
@@ -112,7 +124,6 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_cflag("-Wno-double-promotion")
|
||||
add_cflag("-Wno-gnu-zero-variadic-macro-arguments")
|
||||
add_cflag("-Wno-packed")
|
||||
add_cflag("-Wno-reserved-id-macro")
|
||||
add_cflag("-Wno-shadow")
|
||||
add_cflag("-Wno-shorten-64-to-32")
|
||||
add_cflag("-Wno-unreachable-code-return")
|
||||
@@ -120,28 +131,20 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
add_cflag("-Wno-used-but-marked-unused")
|
||||
|
||||
# Disable specific warning flags for C++.
|
||||
add_cxxflag("-Wno-c++11-compat")
|
||||
add_cxxflag("-Wno-c++11-extensions")
|
||||
add_cxxflag("-Wno-c++11-narrowing")
|
||||
add_cxxflag("-Wno-c++98-compat")
|
||||
add_cxxflag("-Wno-c++98-compat-pedantic")
|
||||
add_cxxflag("-Wno-c99-extensions")
|
||||
add_cxxflag("-Wno-double-promotion")
|
||||
add_cxxflag("-Wno-narrowing")
|
||||
add_cxxflag("-Wno-old-style-cast")
|
||||
add_cxxflag("-Wno-shadow")
|
||||
add_cxxflag("-Wno-used-but-marked-unused")
|
||||
add_cxxflag("-Wno-variadic-macros")
|
||||
add_cxxflag("-Wno-vla-extension")
|
||||
endif()
|
||||
|
||||
option(ERROR_ON_WARNING "Make compilation error on a warning" OFF)
|
||||
if(ERROR_ON_WARNING)
|
||||
# Set error-on-warn for C compilation. C++ compilation can't use this because
|
||||
# treating 'c' input as 'c++' when in C++ mode is deprecated in clang and
|
||||
# there is no way to turn off that warning.
|
||||
add_cflag("-Werror")
|
||||
endif()
|
||||
|
||||
option(DEBUG "Enable assertions and other debugging facilities" OFF)
|
||||
if(DEBUG)
|
||||
set(MIN_LOGGER_LEVEL DEBUG)
|
||||
add_cflag("-g3")
|
||||
# Downgrade to warning so we still see it.
|
||||
add_flag("-Wno-error=unused-variable")
|
||||
add_cxxflag("-Wno-error=zero-as-null-pointer-constant")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -403,7 +406,7 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
|
||||
# endif()
|
||||
#
|
||||
# if(MSGPACK_FOUND)
|
||||
# add_binary(toxcore-sut
|
||||
# add_executable(toxcore-sut
|
||||
# testing/hstox/binary_decode.c
|
||||
# testing/hstox/binary_encode.c
|
||||
# testing/hstox/driver.c
|
||||
@@ -445,7 +448,7 @@ endif()
|
||||
|
||||
function(auto_test target)
|
||||
if(CHECK_FOUND AND NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND ARGV1 STREQUAL "MSVC_DONT_BUILD"))
|
||||
add_binary(auto_${target}_test auto_tests/${target}_test.c)
|
||||
add_executable(auto_${target}_test auto_tests/${target}_test.c)
|
||||
target_link_modules(auto_${target}_test
|
||||
toxcore
|
||||
toxcrypto
|
||||
@@ -460,7 +463,7 @@ function(auto_test target)
|
||||
endfunction()
|
||||
|
||||
if(BUILD_TOXAV)
|
||||
add_binary(auto_monolith_test
|
||||
add_executable(auto_monolith_test
|
||||
auto_tests/monolith_test.cpp
|
||||
${ANDROID_CPU_FEATURES})
|
||||
target_link_modules(auto_monolith_test
|
||||
@@ -511,7 +514,7 @@ endif()
|
||||
|
||||
option(DHT_BOOTSTRAP "Enable building of DHT_bootstrap" ON)
|
||||
if(DHT_BOOTSTRAP)
|
||||
add_binary(DHT_bootstrap
|
||||
add_executable(DHT_bootstrap
|
||||
other/DHT_bootstrap.c
|
||||
other/bootstrap_node_packets.c)
|
||||
target_link_modules(DHT_bootstrap toxnetcrypto)
|
||||
@@ -523,7 +526,7 @@ if(BOOTSTRAP_DAEMON)
|
||||
message(FATAL_ERROR "Building tox-bootstrapd for Windows is not supported")
|
||||
endif()
|
||||
if(LIBCONFIG_FOUND)
|
||||
add_binary(tox-bootstrapd
|
||||
add_executable(tox-bootstrapd
|
||||
other/bootstrap_daemon/src/command_line_arguments.c
|
||||
other/bootstrap_daemon/src/command_line_arguments.h
|
||||
other/bootstrap_daemon/src/config.c
|
||||
@@ -554,7 +557,7 @@ option(BUILD_AV_TEST "Build toxav test" ON)
|
||||
if(NOT WIN32
|
||||
AND BUILD_AV_TEST AND BUILD_TOXAV
|
||||
AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND)
|
||||
add_binary(av_test testing/av_test.c)
|
||||
add_executable(av_test testing/av_test.c)
|
||||
target_link_modules(av_test
|
||||
toxcore
|
||||
${OPENCV_LIBRARIES}
|
||||
@@ -567,23 +570,23 @@ if(NOT WIN32
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_binary(DHT_test testing/DHT_test.c)
|
||||
add_executable(DHT_test testing/DHT_test.c)
|
||||
target_link_modules(DHT_test toxdht)
|
||||
|
||||
add_binary(Messenger_test testing/Messenger_test.c)
|
||||
add_executable(Messenger_test testing/Messenger_test.c)
|
||||
target_link_modules(Messenger_test toxmessenger)
|
||||
|
||||
if(NOT WIN32)
|
||||
add_binary(tox_sync testing/tox_sync.c)
|
||||
add_executable(tox_sync testing/tox_sync.c)
|
||||
target_link_modules(tox_sync toxcore)
|
||||
endif()
|
||||
|
||||
if(UTIL_LIBRARIES)
|
||||
add_binary(tox_shell testing/tox_shell.c)
|
||||
add_executable(tox_shell testing/tox_shell.c)
|
||||
target_link_modules(tox_shell toxcore ${UTIL_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(NOT WIN32)
|
||||
add_binary(irc_syncbot testing/irc_syncbot.c)
|
||||
add_executable(irc_syncbot testing/irc_syncbot.c)
|
||||
target_link_modules(irc_syncbot toxcore toxnetwork)
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
option(ENABLE_SHARED "Build shared (dynamic) libraries for all modules" ON)
|
||||
option(ENABLE_STATIC "Build static libraries for all modules" ON)
|
||||
option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
|
||||
|
||||
if(NOT ENABLE_SHARED AND NOT ENABLE_STATIC)
|
||||
message(WARNING
|
||||
@@ -12,28 +11,6 @@ endif()
|
||||
|
||||
find_package(PkgConfig)
|
||||
|
||||
if(COMPILE_AS_CXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS=1")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_LIMIT_MACROS=1")
|
||||
endif()
|
||||
|
||||
macro(set_source_language)
|
||||
if(COMPILE_AS_CXX)
|
||||
foreach(srcfile ${ARGN})
|
||||
get_filename_component(srcext ${srcfile} EXT)
|
||||
if(${srcext} STREQUAL ".c")
|
||||
set_source_files_properties(${srcfile} PROPERTIES LANGUAGE CXX)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(add_binary exec)
|
||||
set_source_language(${ARGN})
|
||||
|
||||
add_executable(${exec} ${ARGN})
|
||||
endfunction()
|
||||
|
||||
function(pkg_use_module mod pkg)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_search_module(${mod} ${pkg})
|
||||
@@ -58,7 +35,6 @@ macro(add_submodule super lib)
|
||||
endmacro()
|
||||
|
||||
function(add_module lib)
|
||||
set_source_language(${ARGN})
|
||||
set(${lib}_SOURCES ${ARGN} PARENT_SCOPE)
|
||||
|
||||
if(ENABLE_SHARED)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
CMAKE=$ARCH-w64-mingw32.shared-cmake
|
||||
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DBOOTSTRAP_DAEMON=OFF -DCOMPILE_AS_CXX=ON"
|
||||
CMAKE_EXTRA_FLAGS="$CMAKE_EXTRA_FLAGS -DBOOTSTRAP_DAEMON=OFF -DERROR_ON_WARNING=OFF"
|
||||
NPROC=`nproc`
|
||||
CURDIR=/work
|
||||
RUN_TESTS=true
|
||||
|
||||
@@ -10,18 +10,6 @@ set_opt() {
|
||||
set -e
|
||||
}
|
||||
|
||||
# Try some combinations of cmake options.
|
||||
for i in `seq 0 7`; do
|
||||
set +x
|
||||
opts="$CMAKE_EXTRA_FLAGS -DWARNINGS=OFF"
|
||||
set_opt STRICT_ABI
|
||||
set_opt ENABLE_STATIC
|
||||
set_opt ENABLE_SHARED
|
||||
set -x
|
||||
RUN $CMAKE -B$BUILD_DIR -H. $opts
|
||||
RUN rm -rf $BUILD_DIR
|
||||
done
|
||||
|
||||
if perl -e '
|
||||
use Socket qw(PF_INET6 SOCK_STREAM pack_sockaddr_in6 IN6ADDR_LOOPBACK);
|
||||
|
||||
|
||||
@@ -535,7 +535,7 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_
|
||||
memcpy(data + packed_length, nodes[i].public_key, CRYPTO_PUBLIC_KEY_SIZE);
|
||||
packed_length += CRYPTO_PUBLIC_KEY_SIZE;
|
||||
|
||||
uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed
|
||||
len_processed += CRYPTO_PUBLIC_KEY_SIZE;
|
||||
++num;
|
||||
|
||||
uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
const uint32_t increment = ipp_size + CRYPTO_PUBLIC_KEY_SIZE;
|
||||
assert(increment == PACKED_NODE_SIZE_IP4 || increment == PACKED_NODE_SIZE_IP6);
|
||||
}
|
||||
|
||||
|
||||
@@ -2258,10 +2258,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
||||
|
||||
uint8_t filenumber = data[0];
|
||||
|
||||
#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
|
||||
|
||||
if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint64_t filesize;
|
||||
uint32_t file_type;
|
||||
uint16_t filename_length = data_length - head_length;
|
||||
@@ -2318,10 +2322,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
||||
uint8_t filenumber = data[1];
|
||||
uint8_t control_type = data[2];
|
||||
|
||||
#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
|
||||
|
||||
if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (handle_filecontrol(m, i, send_receive, filenumber, control_type, data + 3, data_length - 3, userdata) == -1) {
|
||||
// TODO(iphydf): Do something different here? Right now, this
|
||||
// check is pointless.
|
||||
@@ -2338,10 +2346,14 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
|
||||
|
||||
uint8_t filenumber = data[0];
|
||||
|
||||
#if UINT8_MAX >= MAX_CONCURRENT_FILE_PIPES
|
||||
|
||||
if (filenumber >= MAX_CONCURRENT_FILE_PIPES) {
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
struct File_Transfers *ft = &m->friendlist[i].file_receiving[filenumber];
|
||||
|
||||
if (ft->status != FILESTATUS_TRANSFERRING) {
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
/* This cannot be bigger than 256 */
|
||||
#define MAX_CONCURRENT_FILE_PIPES 256
|
||||
|
||||
#if MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1
|
||||
#error "uint8_t cannot represent all file transfer numbers"
|
||||
#endif
|
||||
|
||||
|
||||
#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@
|
||||
// Emulation using alloca.
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <stdlib.h>
|
||||
#if !defined(alloca) && defined(__GNUC__)
|
||||
#define alloca __builtin_alloca
|
||||
#endif
|
||||
#else
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x501
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user