JFreegman / toxic

A Tox-based instant messaging and video chat client
GNU General Public License v3.0
1.19k stars 152 forks source link

Fix static_assert where undefined #659

Closed barracuda156 closed 6 months ago

barracuda156 commented 6 months ago

Current code does not build: tested on macOS 14.3.1 with Clang and macOS 10.6 with GCC.

On Sonoma it fails like:

--->  Building toxic
Executing:  cd "/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1" && /usr/bin/make -j4 -w CC="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/cc/usr/bin/clang" CXX="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/cxx/usr/bin/clang++" OBJC="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/objc/usr/bin/clang" OBJCXX="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/objcxx/usr/bin/clang++" INSTALL="/usr/bin/install -c" 
make: Entering directory `/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1'
  CC    autocomplete.o
  CC    avatars.o
  CC    bootstrap.o
  CC    chat.o
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/autocomplete.c:23:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/autocomplete.h:26:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/bootstrap.c:23:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/bootstrap.h:26:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/autocomplete.c:23:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/autocomplete.h:27:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/avatars.c:27:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/avatars.h:26:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/file_transfers.h:29:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/notify.h:27:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:38:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/avatars.c:27:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/avatars.h:26:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/file_transfers.h:29:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/notify.h:27:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/bootstrap.c:38:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/line_info.h:30:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
2 warnings generated.
2 warnings generated.
2 warnings generated.
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat.c:27:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat.h:26:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat.c:27:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat.h:27:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
2 warnings generated.
  CC    chat_commands.o
  CC    conference.o
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat_commands.c:23:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat_commands.h:26:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat_commands.c:23:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/chat_commands.h:27:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
2 warnings generated.
  CC    configdir.o
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:50:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/audio_device.h:37:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:38:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:50:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/audio_device.h:37:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:73:15: error: expected parameter declarator
static_assert(TOX_CONFERENCE_ID_SIZE == TOX_PUBLIC_KEY_SIZE, "TOX_CONFERENCE_ID_SIZE != TOX_PUBLIC_KEY_SIZE");
              ^
/opt/local/include/tox/tox.h:238:40: note: expanded from macro 'TOX_CONFERENCE_ID_SIZE'
#define TOX_CONFERENCE_ID_SIZE         32
                                       ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:73:15: error: expected ')'
/opt/local/include/tox/tox.h:238:40: note: expanded from macro 'TOX_CONFERENCE_ID_SIZE'
#define TOX_CONFERENCE_ID_SIZE         32
                                       ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:73:14: note: to match this '('
static_assert(TOX_CONFERENCE_ID_SIZE == TOX_PUBLIC_KEY_SIZE, "TOX_CONFERENCE_ID_SIZE != TOX_PUBLIC_KEY_SIZE");
             ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/conference.c:73:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
static_assert(TOX_CONFERENCE_ID_SIZE == TOX_PUBLIC_KEY_SIZE, "TOX_CONFERENCE_ID_SIZE != TOX_PUBLIC_KEY_SIZE");
^
int
3 warnings and 2 errors generated.
make: *** [/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/build/conference.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/configdir.c:33:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/misc_tools.h:28:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:64:28: warning: redefinition of typedef 'Run_Options' is a C11 feature [-Wtypedef-redefinition]
typedef struct Run_Options Run_Options;
                           ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/run_options.h:56:3: note: previous definition is here
} Run_Options;
  ^
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/configdir.c:33:
In file included from /opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/misc_tools.h:29:
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/windows.h:149:26: warning: redefinition of typedef 'ToxWindow' is a C11 feature [-Wtypedef-redefinition]
typedef struct ToxWindow ToxWindow;
                         ^
/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1/src/toxic.h:63:26: note: previous definition is here
typedef struct ToxWindow ToxWindow;
                         ^
2 warnings generated.
make: *** wait: No child processes.  Stop.
Command failed:  cd "/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/toxic-0.14.1" && /usr/bin/make -j4 -w CC="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/cc/usr/bin/clang" CXX="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/cxx/usr/bin/clang++" OBJC="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/objc/usr/bin/clang" OBJCXX="/opt/local/var/macports/build/_opt_svacchanda_SonomaPorts_net_toxic/toxic/work/compwrap/objcxx/usr/bin/clang++" INSTALL="/usr/bin/install -c" 
Exit code: 2

On macOS 10.6 static_assert is not defined in assert.h, so the build fails due to that.

_Static_assert works fine on both, however.

JFreegman commented 6 months ago

It looks like you're compiling with the c99 standard. Can you try compiling with the c11 or gnu11 standard and see if that fixes it?

Edit: If that's not possible or doesn't work, the _Static_assert macro is considered deprecated, so I'd prefer you to put those static asserts inside an #ifdef __APPLE__ clause (or create a custom wrapper macro if you're up to it).

barracuda156 commented 6 months ago

@JFreegman Thank you for responding.

Can you try compiling with the c11 or gnu11 standard and see if that fixes it?

Perhaps the build system should pass the required standard rather than a user being in need of guessing it? We used C99, because a higher standard was not asked for.

Edit: If that's not possible or doesn't work, the _Static_assert macro is considered deprecated,

This is not exactly the case; it is considered deprecated only in C23. C23 would be a rather radical requirement, given that otherwise this builds fine with C99.

so I'd prefer you to put those static asserts inside an #ifdef __APPLE__ clause (or create a custom wrapper macro if you're up to it).

Maybe this will work and satisfy everyone? https://github.com/python/cpython/blob/v3.12.1/Include/pymacro.h#L20-L24 I am unsure where it is better to place it though.

JFreegman commented 6 months ago

@barracuda156

Perhaps the build system should pass the required standard rather than a user being in need of guessing it? We used C99, because a higher standard was not asked for.

Toxic's build system is a simple Makefile, which uses c11 by default. It looks like the mac port is overriding the Makefile's settings, in which case there's nothing I can really about it. I can only strongly recommend compiling with the same flags that we have set in our Makefile, but I can't force it.

Maybe this will work and satisfy everyone? https://github.com/python/cpython/blob/v3.12.1/Include/pymacro.h#L20-L24 I am unsure where it is better to place it though.

That looks reasonable. You could put it in toxic.h. You'll need to include assert.h above the new macro, and remove the assert.h header from conference.c, settings.c and notify.c (edit: actually you can leave those)

barracuda156 commented 6 months ago

@JFreegman Sure, I will set it to C11 then, though I am not sure at the moment why flags were dropped. Normally compiler.c_standard value does not enforce the standard (and should not override anything), but merely affects compiler choice (I believe, with Xcode 3.x setting to 1999 will rule out gcc-4.0, so inconsequential otherwise). Both compilers used (which produced failures reported here) support at least up to C20 and likely C23.

JFreegman commented 6 months ago

Also, when you're ready to implement your changes, could you please close this PR and open it in the toktok repo?

barracuda156 commented 6 months ago

@JFreegman Ok, sure. I will get back to this soonish.

barracuda156 commented 6 months ago

UPD. Okay, I know why we had C99: it was needed for gcc-4.2 and previously inconsequential for newer compilers, so it was added unconditionally into Darwin config. Now that has to be changed, of course.

barracuda156 commented 6 months ago

Closing, since moved to https://github.com/TokTok/toxic/pull/358