Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Portability fixes" #395

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ install_manifest.txt
tags
Makefile.in
CMakeLists.txt.user
DartConfiguration.tcl
CTestTestfile.cmake
*.pc

# Testing
testing/data
Expand All @@ -43,9 +40,6 @@ testing/data
*.app
*.la

# Libraries
*.so

# Misc (?)
m4/*
configure
Expand All @@ -57,6 +51,8 @@ config.log
config.status
stamp-h1
autom4te.cache
libtoxcore.pc
libtoxav.pc
libtool
.deps
.libs
Expand Down
15 changes: 8 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,22 @@ macro(add_flag flag)
add_cflag(${flag})
add_cxxflag(${flag})
endmacro()

# Set standard version for compiler.
add_cflag("-std=c99")
add_cxxflag("-std=c++11")

# Error on non-ISO C.
add_cflag("-pedantic-errors")

option(WARNINGS "Enable additional compiler warnings" ON)
if(WARNINGS)
# Set standard version for compiler.
add_cflag("-std=gnu99")
add_cxxflag("-std=c++98")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks incorrect to me. You only define the C standard if warnings are enabled?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. By default, gcc uses gnu89, which is sufficient for us at the moment (soon it won't be). @Zer0-One will hopefully make the original PR again which reverts this revert.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why are cxxflags set in a C-only library?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also compile the code as C++ to make sure it's C++ compatible. Reasons:

  • Additional C++-only tooling becomes available (static analysers).
  • A few checks performed by C++ compilers (enum compatibility, void pointer casts) are useful for us.

# Add all warning flags we can.
add_flag("-Wall")
add_flag("-Wextra")
add_flag("-Weverything")

# -pedantic only for C, because in C++ we want to allow the GNU/C99 extension
# of having a comma at the end of an enumerator list.
add_cflag("-pedantic")

# Disable specific warning flags for both C and C++.
add_flag("-Wno-cast-align")
add_flag("-Wno-conversion")
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
8 changes: 3 additions & 5 deletions auto_tests/conference_test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Auto Tests: Conferences.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down Expand Up @@ -177,7 +175,7 @@ START_TEST(test_many_group)
* Either way in this case it's fine */
if (peer_count != NUM_GROUP_TOX) {
++test_run;
printf("\tError starting up the first group (peer_count %" PRIu32 " != %d, test_run = %d)\n", peer_count, NUM_GROUP_TOX,
printf("\tError starting up the first group (peer_count %"PRIu32" != %d, test_run = %d)\n", peer_count, NUM_GROUP_TOX,
test_run);

for (j = 0; j < NUM_GROUP_TOX; ++j) {
Expand All @@ -196,7 +194,7 @@ START_TEST(test_many_group)
* important again.
*/
ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n",
NUM_GROUP_TOX, i, peer_count);

uint8_t title[2048];
Expand Down Expand Up @@ -243,7 +241,7 @@ START_TEST(test_many_group)
for (i = 0; i < (k - 1); ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %"PRIu32"\n\n",
(k - 1), i, peer_count);
}
}
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/dht_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
4 changes: 2 additions & 2 deletions auto_tests/network_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ START_TEST(test_ip_equal)
ip2.ip6.uint32[2] = htonl(0xFFFF);
ip2.ip6.uint32[3] = htonl(0x7F000001);

ck_assert_msg(IPV6_IPV4_IN_V6(ip2.ip6) != 0,
"IPV6_IPV4_IN_V6(::ffff:127.0.0.1): expected != 0, got 0.");
ck_assert_msg(IN6_IS_ADDR_V4MAPPED(&ip2.ip6.in6_addr) != 0,
"IN6_IS_ADDR_V4MAPPED(::ffff:127.0.0.1): expected != 0, got 0.");

res = ip_equal(&ip1, &ip2);
ck_assert_msg(res != 0, "ip_equal( {AF_INET, 127.0.0.1}, {AF_INET6, ::ffff:127.0.0.1} ): expected result != 0, got 0.");
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/onion_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
3 changes: 0 additions & 3 deletions auto_tests/save_friend_test.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* Auto Tests: Save and load friends.
*/

#define _XOPEN_SOURCE 600

#include "helpers.h"
#include "../toxcore/tox.h"

#include <assert.h>
#include <stdio.h>
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/tox_many_tcp_test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Auto Tests: Many TCP.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/tox_many_test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Auto Tests: Many clients.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/tox_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/toxav_basic_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions auto_tests/toxav_many_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions other/DHT_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
19 changes: 2 additions & 17 deletions other/bootstrap_daemon/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#include "global.h"

#include <assert.h>
#include <syslog.h>

#include <stdarg.h>
#include <stdio.h>

Expand Down Expand Up @@ -82,22 +82,7 @@ static int level_syslog(LOG_LEVEL level)

static void log_syslog(LOG_LEVEL level, const char *format, va_list args)
{
va_list args2;

va_copy(args2, args);
int size = vsnprintf(NULL, 0, format, args2);
va_end(args2);

assert(size >= 0);

if (size < 0) {
return;
}

char buf[size + 1];
vsnprintf(buf, size + 1, format, args);

syslog(level_syslog(level), "%s", buf);
vsyslog(level_syslog(level), format, args);
}

static FILE *level_stdout(LOG_LEVEL level)
Expand Down
2 changes: 0 additions & 2 deletions other/bootstrap_daemon/src/tox-bootstrapd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*
*/

#define _XOPEN_SOURCE 600

// system provided
#include <sys/stat.h>
#include <unistd.h>
Expand Down
2 changes: 0 additions & 2 deletions testing/DHT_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions testing/Messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions testing/av_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* -lopencv_highgui -lopencv_imgproc -lsndfile -pthread -lvpx -lopus -lsodium -lportaudio
*/

#define _XOPEN_SOURCE 600

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
9 changes: 4 additions & 5 deletions testing/irc_syncbot.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define _XOPEN_SOURCE 600

#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -35,8 +34,8 @@ static uint16_t port = 6667;

static int sock;

#define SERVER_CONNECT "NICK " IRC_NAME "\nUSER " IRC_NAME " 8 * :" IRC_NAME "\n"
#define CHANNEL_JOIN "JOIN " IRC_CHANNEL "\n"
#define SERVER_CONNECT "NICK "IRC_NAME"\nUSER "IRC_NAME" 8 * :"IRC_NAME"\n"
#define CHANNEL_JOIN "JOIN "IRC_CHANNEL"\n"

/* In toxcore/network.c */
uint64_t current_time_monotonic(void);
Expand Down Expand Up @@ -132,8 +131,8 @@ static void copy_groupmessage(Tox *tox, uint32_t groupnumber, uint32_t friendgro
uint8_t sendbuf[2048];
uint16_t send_len = 0;

memcpy(sendbuf, "PRIVMSG " IRC_CHANNEL " :", sizeof("PRIVMSG " IRC_CHANNEL " :"));
send_len += sizeof("PRIVMSG " IRC_CHANNEL " :") - 1;
memcpy(sendbuf, "PRIVMSG "IRC_CHANNEL" :", sizeof("PRIVMSG "IRC_CHANNEL" :"));
send_len += sizeof("PRIVMSG "IRC_CHANNEL" :") - 1;
memcpy(sendbuf + send_len, name, namelen);
send_len += namelen;
sendbuf[send_len] = ':';
Expand Down
1 change: 0 additions & 1 deletion testing/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#ifdef TOX_DEBUG
#include <assert.h>
Expand Down
2 changes: 0 additions & 2 deletions testing/tox_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
11 changes: 1 addition & 10 deletions testing/tox_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand All @@ -44,7 +42,6 @@
#include <dirent.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/stat.h>

#define NUM_FILE_SENDERS 256
typedef struct {
Expand Down Expand Up @@ -300,7 +297,6 @@ int main(int argc, char *argv[])
memcpy(path, argv[argvoffset + 4], strlen(argv[argvoffset + 4]));
DIR *d;
struct dirent *dir;
struct stat statbuf;
uint8_t notconnected = 1;

while (1) {
Expand All @@ -314,12 +310,7 @@ int main(int argc, char *argv[])

if (d) {
while ((dir = readdir(d)) != NULL) {
char filepath[strlen(path) + strlen(dir->d_name) + 1];
memcpy(filepath, path, strlen(path));
memcpy(filepath + strlen(path), dir->d_name, strlen(dir->d_name) + 1);
stat(filepath, &statbuf);

if (S_ISREG(statbuf.st_mode)) {
if (dir->d_type == DT_REG) {
char fullpath[1024];

if (path[strlen(path) - 1] == '/') {
Expand Down
4 changes: 2 additions & 2 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ static int send_routing_response(TCP_Secure_Connection *con, uint8_t rpid, const
*/
static int send_connect_notification(TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
uint8_t data[2] = {TCP_PACKET_CONNECTION_NOTIFICATION, id + NUM_RESERVED_PORTS};
return write_packet_TCP_secure_connection(con, data, sizeof(data), 1);
}

Expand All @@ -629,7 +629,7 @@ static int send_connect_notification(TCP_Secure_Connection *con, uint8_t id)
*/
static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id)
{
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, (uint8_t)(id + NUM_RESERVED_PORTS)};
uint8_t data[2] = {TCP_PACKET_DISCONNECT_NOTIFICATION, id + NUM_RESERVED_PORTS};
return write_packet_TCP_secure_connection(con, data, sizeof(data), 1);
}

Expand Down
2 changes: 0 additions & 2 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*
*/

#define _XOPEN_SOURCE 600

#if defined(_WIN32) && _WIN32_WINNT >= _WIN32_WINNT_WINXP
#define _WIN32_WINNT 0x501
#endif
Expand Down
2 changes: 0 additions & 2 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down
2 changes: 0 additions & 2 deletions toxcore/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/

#define _XOPEN_SOURCE 600

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down