Skip to content

cmake: remove unused macros from config.h template - #231

Open
chrisdebian wants to merge 3 commits into
libsndfile:masterfrom
chrisdebian:remove-unused-config-macros
Open

cmake: remove unused macros from config.h template#231
chrisdebian wants to merge 3 commits into
libsndfile:masterfrom
chrisdebian:remove-unused-config-macros

Conversation

@chrisdebian

Copy link
Copy Markdown

Summary

Six macros defined in config.h.cmake are never referenced in any C or header file in the library:

  • CPU_IS_LITTLE_ENDIAN
  • HAVE_LRINT
  • HAVE_LRINTF
  • HAVE_STDINT_H
  • SIZEOF_INT
  • SIZEOF_LONG

These appear to be remnants from when libsamplerate provided its own lrint/lrintf fallbacks and portability shims for older compilers. That code was removed, but the corresponding config.h entries were not.

The if(CPU_IS_BIG_ENDIAN)/set(CPU_IS_LITTLE_ENDIAN) block in CMakeLists.txt is also removed, as it existed solely to populate the now-removed CPU_IS_LITTLE_ENDIAN entry.

Verification

Grepped all .c and .h files under src/ and include/ — none of the six symbols appear anywhere.

$ grep -r "CPU_IS_LITTLE_ENDIAN\|HAVE_LRINT\|HAVE_LRINTF\|HAVE_STDINT_H\|SIZEOF_INT\|SIZEOF_LONG" src/ include/
(no output)

Spotted while using libsamplerate as a vendored CMake submodule in an Android project; the Android Studio C/C++ unused-macro inspection flagged these in the generated config.h.

Six macros defined in config.h.cmake are never referenced in any C or
header file in the library:

  CPU_IS_LITTLE_ENDIAN, HAVE_LRINT, HAVE_LRINTF,
  HAVE_STDINT_H, SIZEOF_INT, SIZEOF_LONG

These appear to be remnants from a time when libsamplerate provided its
own lrint/lrintf fallbacks and portability shims for older compilers.
That code was removed, but the corresponding config.h entries were not.

Also remove the if(CPU_IS_BIG_ENDIAN)/set(CPU_IS_LITTLE_ENDIAN) block
from CMakeLists.txt, which existed solely to populate the now-removed
CPU_IS_LITTLE_ENDIAN entry.

Verified by grepping all .c and .h files under src/ and include/:
none of the six symbols appear.
@chrisdebian

Copy link
Copy Markdown
Author

Hi, a gentle bump on this one after a few months. It's a small, self-contained change (removing unused macros from the config.h.cmake template), so happy to adjust if you'd like anything different, or let me know if it's not a priority.

@erikd

erikd commented Aug 2, 2026

Copy link
Copy Markdown
Member

Sorry, just checked the first one (CPU_IS_LITTLE_ENDIAN) and found many of uses.

> grep CPU_IS_LITTLE_ENDIAN src/*.c
src/aiff.c:	if (CPU_IS_LITTLE_ENDIAN && endian == SF_ENDIAN_CPU)
src/au.c:		if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)
src/caf.c:	else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == SF_ENDIAN_LITTLE || psf->endian == SF_ENDIAN_CPU))
src/common.c:					if (CPU_IS_LITTLE_ENDIAN)
src/common.c:#elif (CPU_IS_LITTLE_ENDIAN == 1)
src/common.c:#elif (CPU_IS_LITTLE_ENDIAN == 1)
src/double64.c:#if CPU_IS_LITTLE_ENDIAN
src/double64.c:	return (CPU_IS_LITTLE_ENDIAN) ? DOUBLE_BROKEN_LE : DOUBLE_BROKEN_BE ;
src/dwd.c:		if (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU)
src/float32.c:#if CPU_IS_LITTLE_ENDIAN
src/float32.c:	return (CPU_IS_LITTLE_ENDIAN) ? FLOAT_BROKEN_LE : FLOAT_BROKEN_BE ;
src/mat4.c:		if (CPU_IS_LITTLE_ENDIAN && (psf->endian == SF_ENDIAN_CPU || psf->endian == 0))
src/mat5.c:		if (CPU_IS_LITTLE_ENDIAN && (psf->endian == SF_ENDIAN_CPU || psf->endian == 0))
src/mat5.c:		if (CPU_IS_LITTLE_ENDIAN) version = ENDSWAP_16 (version) ;
src/mat5.c:	if ((CPU_IS_LITTLE_ENDIAN && endian == IM_MARKER) ||
src/paf.c:		if (endian == SF_ENDIAN_LITTLE || (CPU_IS_LITTLE_ENDIAN && (endian == SF_ENDIAN_CPU)))
src/paf.c:	if ((CPU_IS_BIG_ENDIAN && psf->endian == SF_ENDIAN_LITTLE) || (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_BIG))
src/paf.c:	if (CPU_IS_LITTLE_ENDIAN)
src/pcm.c:#if CPU_IS_LITTLE_ENDIAN
src/pcm.c:#if CPU_IS_LITTLE_ENDIAN
src/pcm.c:#if CPU_IS_LITTLE_ENDIAN
src/pcm.c:#if CPU_IS_LITTLE_ENDIAN
src/raw.c:	else if (CPU_IS_LITTLE_ENDIAN && (psf->endian == 0 || psf->endian == SF_ENDIAN_CPU))
src/sd2.c:	if (CPU_IS_LITTLE_ENDIAN)
src/sndfile.c:		#if (CPU_IS_LITTLE_ENDIAN == 1)
src/svx.c:		if (psf->endian == SF_ENDIAN_LITTLE || (CPU_IS_LITTLE_ENDIAN && psf->endian == SF_ENDIAN_CPU))

@erikd erikd left a comment

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.

Does not seem correct.

erikd pointed out CPU_IS_LITTLE_ENDIAN is referenced across src/*.c
(aiff.c, au.c, caf.c, common.c, double64.c, dwd.c, float32.c, mat4.c,
mat5.c, paf.c, pcm.c, raw.c, sd2.c, sndfile.c, svx.c) - removing it
would have broken the build. Confirmed the other five macros removed
in this PR (HAVE_LRINT, HAVE_LRINTF, HAVE_STDINT_H, SIZEOF_INT,
SIZEOF_LONG) have no remaining references anywhere else in the repo,
so those stay removed.
@chrisdebian

Copy link
Copy Markdown
Author

You're right, sorry — I checked CPU_IS_LITTLE_ENDIAN more carefully and it's genuinely used across src/*.c (aiff.c, au.c, caf.c, common.c, double64.c, dwd.c, float32.c, mat4.c, mat5.c, paf.c, pcm.c, raw.c, sd2.c, sndfile.c, svx.c). Pushed a fix restoring its definition in both CMakeLists.txt and config.h.cmake. I also double-checked the other five macros this PR removes (HAVE_LRINT, HAVE_LRINTF, HAVE_STDINT_H, SIZEOF_INT, SIZEOF_LONG) and confirmed none of them have any remaining references anywhere else in the repo, so those stay removed.

@erikd

erikd commented Aug 4, 2026

Copy link
Copy Markdown
Member

I am also a little concerned that before you restored CPU_IS_LITTLE_ENDIAN CI passed with flying colors.

Any idea why this was not caught by any of the cmake CI builds?

@chrisdebian

Copy link
Copy Markdown
Author

Hi Erik, thanks for checking, and sorry for the confusion.

I think this is a mix-up between the two repos. I just grepped libsndfile's own source tree, and all 15 of those files (aiff.c, au.c, caf.c, etc.) do use CPU_IS_LITTLE_ENDIAN there. But this PR is against libsamplerate, and I can't find CPU_IS_LITTLE_ENDIAN (or any of the other five removed macros) anywhere in libsamplerate's own src/ or include/ files. That also answers your CI question: the macro genuinely isn't referenced in this codebase, so nothing broke when it was removed.

I've reverted my earlier restore commit so the PR is back to the original clean removal. Let me know if you'd like me to double-check anything else.

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