Skip to content

Fix compilation warnings#1711

Open
brainy wants to merge 1 commit into
lz4:devfrom
brainy:compilation-warnings
Open

Fix compilation warnings#1711
brainy wants to merge 1 commit into
lz4:devfrom
brainy:compilation-warnings

Conversation

@brainy
Copy link
Copy Markdown

@brainy brainy commented Jan 31, 2026

In a custom amalgamated build of LZ4 with XXH_PRIVATE_API defined, -std=c90 and stricter compilation warnings, three classes of warnings were emitted. This is a trivial fix with no functional change.

lz4.c:1590:5: warning: no previous prototype for function 'LZ4_loadDict_internal' [-Wmissing-prototypes]
 1590 | int LZ4_loadDict_internal(LZ4_stream_t* LZ4_dict,
lz4frame.c:180:31: warning: redefinition of typedef 'BYTE' is a C11 feature [-Wtypedef-redefinition]
  182 |   typedef unsigned char       BYTE;
xxhash.c:864:54: warning: cast from function call of type 'int' to non-matching type 'XXH_endianness' [-Wbad-function-cast]
  864 |     XXH_endianness endian_detected = (XXH_endianness)XXH_CPU_LITTLE_ENDIAN;

@brainy brainy force-pushed the compilation-warnings branch from 3af066a to b787139 Compare January 31, 2026 18:12
Comment thread lib/lz4.c
typedef enum { _ld_fast, _ld_slow } LoadDict_mode_e;
#define HASH_UNIT sizeof(reg_t)
int LZ4_loadDict_internal(LZ4_stream_t* LZ4_dict,
static int LZ4_loadDict_internal(LZ4_stream_t* LZ4_dict,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sidenote: I'm really surprised this was not caught before. We may be missing a compilation flag to catch that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Clearly, we are missing -Wmissing-prototypes. This should be added. I would have caught these issues.

@Cyan4973 Cyan4973 self-assigned this Feb 12, 2026
@Cyan4973
Copy link
Copy Markdown
Member

Do you have a reproduction scenario, that would produce the warnings without this fix?

Comment thread lib/lz4frame.c Outdated
**************************************/
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
# include <stdint.h>
# ifndef XXH_PRIVATE_API
Copy link
Copy Markdown
Member

@Cyan4973 Cyan4973 Feb 12, 2026

Choose a reason for hiding this comment

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

This one feels weird. Like a misplaced responsibility, or a fragile coupling.
But, it's not immediately obvious which better solution exists out there...

Copy link
Copy Markdown
Member

@Cyan4973 Cyan4973 Feb 12, 2026

Choose a reason for hiding this comment

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

I think some proper solutions are:

  • update xxhash to a newer version that doesn't use U32 / U16 (it moved to xxh_u32 / xxh_u16 since)
  • if using the xxhash version bundled in lz4, #define MEM_MODULE, this will disable the typedef U32 part within xxhash.
  • rely on C11 to make typedef redefinition valid
  • silence the specific warning

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Apologies for the late reply. I found these while upgrading the optionally used LZ4 amalgamation that ships with Subversion.

This code already implements my proposed patch.

Notes:

  • lz4.h was renamed to lz4internal.h to avoid header name clashes, since Subversion can be compiled with the included amalgamated LZ4 even when an external library is available.
  • The entry point for compiling LZ4 is svnlz4.c.
  • svnlz4.h defines some Subversion-specific options, like changing the visibility of the LZ4 API.

As for relying on C11 – Subversion compiles with -std=c90 and it would make including LZ4 in our source a bit easier if C11 constructs could be avoided.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This #ifdef isn't needed any more.

@Cyan4973
Copy link
Copy Markdown
Member

Cyan4973 commented Mar 8, 2026

-Wmissing-prototypes compilation warnings are now fixed and verified in latest dev commits.

@brainy brainy force-pushed the compilation-warnings branch from b787139 to 77aa8bf Compare April 30, 2026 14:27
@brainy
Copy link
Copy Markdown
Author

brainy commented Apr 30, 2026

I just resolved the conflicts and there's only one commit left. The changes you already made seem to work now in my environment.

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.

2 participants