Commit Graph
5 Commits
Author SHA1 Message Date
Davide FacontiandClaude Opus 5.5 f519878387 allocators: route all library allocations through KISS_FFT_MALLOC/FREE
Users can override KISS_FFT_MALLOC and KISS_FFT_FREE, but several
places bypassed them:

- kiss_fftnd_alloc and kiss_fftndr_alloc called malloc() directly,
  so their configs (released with kiss_fft_free / kiss_fftndr_free)
  went to a different allocator than the one that freed them.
- kiss_fftndr_free was defined as plain free.
- kfc_cleanup released KISS_FFT_MALLOC'd cache entries with free().
- Under USE_SIMD, KISS_FFT_ALIGN_CHECK and KISS_FFT_ALIGN_SIZE_UP were
  defined only inside "#ifndef KISS_FFT_MALLOC", so overriding the
  allocator broke the build. Define them unconditionally.

Note that under USE_SIMD the nd/ndr configs now come from the SIMD
default allocator (_mm_malloc / aligned_alloc) instead of malloc, so
they must be released with kiss_fft_free / kiss_fftndr_free.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
2026-11-15 20:03:51 +01:00
Davide FacontiandClaude Opus 5.5 c2f367e286 kiss_fftnd, kiss_fftndr: align every object packed into the state block
kiss_fftnd_alloc and kiss_fftndr_alloc carve several objects out of one
allocation, advancing by KISS_FFT_ALIGN_SIZE_UP(size), which is the
identity outside SIMD builds. So objects started at whatever offset the
previous one ended:

- kiss_fftnd: after an odd number of int dims, tmpbuf and the
  per-dimension kiss_fft_state objects were 4 bytes off, misaligned for
  double.
- kiss_fftndr: the nd state (which holds pointers) followed the real-FFT
  state, whose size is only a multiple of 4 for int16_t.

These are misaligned accesses (undefined behavior; SIGBUS on strict
platforms, silent on x86). Add KISS_FFT_PACK_SIZE_UP to
_kiss_fft_guts.h, which rounds a size up to a multiple of the size of a
union of pointer, int and kiss_fft_cpx (a multiple of each of their
alignments, and of the SIMD vector alignment), and use it for every
object in both layouts. The reported sizes grow by a few bytes of padding.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
2026-11-15 20:03:51 +01:00
Davide FacontiandClaude Opus 5.5 933c235c1c kiss_fftndr: fix allocation size check, odd sizes and ndims == 1
kiss_fftndr_alloc had three problems:

- Its overflow check divided the required size (truncated to an int) by
  every dimension and failed when fewer than sizeof(kiss_fft_scalar)
  bytes per element remained. The buffers only need slightly more than
  that per element, so valid sizes were rejected: 230 of the even NxN
  sizes from 2 to 512 (starting at 54x54) returned NULL. Replace it with
  a direct check that dimOther*(dimReal+2) scalars fit in size_t with a
  margin and that dimOther fits the int that kiss_fftnd counts it in,
  and make prod() saturate instead of wrapping.

- An odd last dimension is not supported by kiss_fftr, but the failure
  of the kiss_fftr_alloc size query was ignored and a config with a
  NULL kiss_fftr state was returned. Now kiss_fftndr_alloc returns NULL.

- With ndims == 1 the inner kiss_fftnd has zero dimensions, and
  kiss_fftnd never wrote its output in that case (the even-ndims path
  leaves the result in tmpbuf and the loop body never runs), so
  kiss_fftndr/kiss_fftndri returned garbage. Make a zero-dimensional
  kiss_fftnd the identity, which fixes both directions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ME1hnNaoD3ZcMj9H8TSYkZ
2026-11-15 20:02:21 +01:00
Mark Borgerdingandvulgraph aea492e132 kiss_fftndr_alloc: check for overflow (and _perhaps_ let combined dims > INT_MAX)
(cherry picked from commit 8a8e66e33d)
2026-04-22 19:27:18 +08:00
Vasyl Gello 2e2747c129 Overhaul Make makefiles
* Header files and correspondent C sources that define
    functions recently added to public API moved from
    'tools' directory to root

  * By default, install prefix is '/usr/local/', and header
    install path is '${PREFIX}/include/kissfft'

  * Added detection of external libraries like FFTW or libPNG

Signed-off-by: Vasyl Gello <[email protected]>
2021-02-05 13:34:16 +02:00