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

Improve C99 compliance. #182

Merged
merged 15 commits into from Nov 30, 2019
Merged

Improve C99 compliance. #182

merged 15 commits into from Nov 30, 2019

Conversation

dbaarda
Copy link
Member

@dbaarda dbaarda commented Nov 26, 2019

Add "-pedantic" to CMAKE_C_FLAGS for gcc and clang, and fix all the C99 warnings this produces.

In CMakeLists.txt remove all checks for includes and functions that are unused and/or are standard for C99. Add checks for __func__ and __FUNCTION__. Remove explicit disable of non-standard HAVE_PROGRAM_INVOCATION_NAME. Update config.h.cmake to remove all cmakedefines that have never worked or have been removed, and re-order them to reflect the order in CMakeLists.txt.

Update checksum.h, version.c, and trace.[ch] to be C99 compliant. In trace.c remove support for compilers without varags macro support, and remove non-standard use of program_invocation_short_name. Note program_invocation_short_name was disabled in cmake anyway. Use C99 fputs() instead of Posix write(). Use RS_LOG_NONAME format when func is an empty string. Use func and attribute selectively based on platform support.

Tidy up all #includes, removing unnecessary ones and re-arranging them into more consistent order. This includes no longer importing sys/types.h in librsync.h

Tidy indents/tabs in netint.c

dbaarda added 12 commits Nov 25, 2019
It looks like some tabs crept in at some point.
C99 doesn't like anonymous unions or returning void function calls.
C99 doesn't like initializing char arrays from expressions. Brackets around a
string literal make it into an expression, so they had to go.
In CMakeLists.txt add "-pedantic" to CMAKE_C_FLAGS for gcc/clang to enable
stricter C99 compiling. Add checks for symbols __func__ and __FUNCTION__.

In src/config.h.cmake add cmakedefine's for HAVE___FUNC__ and
HAVE___FUNCTION__. Remove unimplemented FIXME defines for C99 standards const,
off_t, and size_t.

In src/trace.[ch] remove all support for compilers without C99's macro varargs
support. Add support for platforms with __FUNCTION__ instead of __func__. Use
C99 macro varargs instead of GNU named varargs and simplify macros.
In CMakeList.txt and src/config.h.cmake remove support for unused alloca
function, including HAVE_ALLOCA_H, HAVE_ALLOCA, CRAY_STACKSEG_END, C_ALLOCA,
and STACK_DIRECTION.

In src/config.h.cmake remove unused and unchecked or not working cmakedefines
for HAVE_LIBBZ2, HAVE_LIBPOPT, HAVE_LIBZ, HAVE_SNPRINTF, HAVE_VARARG_MACROS,
HAVE_VSNPRINTF, HAVE__SNPRINTF, and HAVE__VSNPRINTF. The HAVE_LIB* ones were
just broken and unused. The others were unchecked, unused, and for standard
C99 features we assume exist in the code.
In CMakeLists.txt and src/config.h.cmake remove HAVE_PROGRAM_INVOCATION_NAME.

In src/trace.c remove conditional use of program_invocation_short_name. This
was unused because we never checked/set HAVE_PROGRAM_INVOCATION_NAME.
We never used these HAVE_* defines and just assumed the features existed
anyway. Also put the checks and cmakedefines into the same order.
This makes the cmakedefines in src/config.h.cmake reflect the order of checks
in CMakeLists.txt. It also removes the obsolete STDC_HEADERS define.
For non-GNUC compatible compilers #define away __attribute__. For compilers
without __func__ or __FUNCTION__ use an empty string. Make logging use
RS_LOG_NONAME format when __func__ is an empty string. Use C99 fputs() instead
of Unix/Posix write(). Prune and tidy imports to only what's needed.
The docs for some of the stat() variants suggest sys/types.h is needed, so
best to import it incase it's actually needed on some platforms.
This removes all not-required #include statements, including some non-C99
headers, and re-arranges them into more consistent order.
@dbaarda
Copy link
Member Author

@dbaarda dbaarda commented Nov 29, 2019

This prunes nearly 300 lines of old cruft. It should be fine on all the different platforms, but it would be good if anyone could test this on windows and/or BSD platforms to be sure.

dbaarda added 3 commits Nov 30, 2019
…VE_UINT64.

We have not been setting HAVE_UINT64 which means we've not been using 64bit
support for calculating md4sums. Checking that the C99 stdint.h's UINT64_MAX
is defined is the best way of checking that the uint64_t type exists on the
target platform.
@dbaarda
Copy link
Member Author

@dbaarda dbaarda commented Nov 30, 2019

I also found/fixed that we've not been using 64bit support for calculating mdfour checksums! It seems at some point we stopped correctly setting HAVE_UINT64 which means we've been using only 32bit stuff for calculating md4sums. Doh! Ah well, we've mostly switched to blake2 now anyway.

@dbaarda dbaarda merged commit 23938bc into librsync:master Nov 30, 2019
1 check passed
@dbaarda dbaarda deleted the fix/c99 branch Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant