From 1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 11 Dec 2017 15:07:18 +0100 Subject: Remove references to malloc.h and use posix_memalign --- configure.ac | 3 +-- src/Buffer.cpp | 12 ++++-------- src/DabMod.cpp | 7 ------- src/Flowgraph.cpp | 6 ------ src/FormatConverter.cpp | 1 - src/FrequencyInterleaver.cpp | 8 ++++++-- src/Resampler.cpp | 7 +++++-- 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 23369c9..d260f9e 100644 --- a/configure.ac +++ b/configure.ac @@ -154,8 +154,7 @@ AS_IF([test "x$enable_debug" != "xno"], )]) # Checks for header files. -AC_CHECK_HEADERS([fcntl.h limits.h malloc.h memory.h netinet/in.h stdint.h stdlib.h string.h sys/time.h sys/timeb.h unistd.h]) -AC_CHECK_DECLS([_mm_malloc], [], [], [#include ]) +AC_CHECK_HEADERS([fcntl.h limits.h memory.h netinet/in.h stdint.h stdlib.h string.h sys/time.h sys/timeb.h unistd.h]) AC_HEADER_STDC # Checks for typedefs, structures, and compiler characteristics. diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 8631c42..6b14561 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -30,13 +30,6 @@ #include #include -#include -#if HAVE_DECL__MM_MALLOC -# include -#else -# define memalign(a, b) malloc(b) -#endif - Buffer::Buffer(size_t len, const void *data) @@ -92,7 +85,10 @@ void Buffer::setLength(size_t len) void *tmp = data; /* Align to 32-byte boundary for AVX. */ - data = memalign(32, len); + const int ret = posix_memalign(&data, 32, len); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } if (tmp != NULL) { memcpy(data, tmp, this->len); diff --git a/src/DabMod.cpp b/src/DabMod.cpp index af3adde..1625a82 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -64,13 +64,6 @@ # include #endif -#if HAVE_DECL__MM_MALLOC -# include -#else -# define memalign(a, b) malloc(b) -#endif - - /* UHD requires the input I and Q samples to be in the interval * [-1.0,1.0], otherwise they get truncated, which creates very * wide-spectrum spikes. Depending on the Transmission Mode, the diff --git a/src/Flowgraph.cpp b/src/Flowgraph.cpp index 6ee7b81..4870534 100644 --- a/src/Flowgraph.cpp +++ b/src/Flowgraph.cpp @@ -29,12 +29,6 @@ #include #include #include - -#if HAVE_DECL__MM_MALLOC -# include -#else -# define memalign(a, b) malloc(b) -#endif #include #include #include diff --git a/src/FormatConverter.cpp b/src/FormatConverter.cpp index 6826972..60c0545 100644 --- a/src/FormatConverter.cpp +++ b/src/FormatConverter.cpp @@ -29,7 +29,6 @@ #include "FormatConverter.h" #include "PcDebug.h" -#include #include #include #include diff --git a/src/FrequencyInterleaver.cpp b/src/FrequencyInterleaver.cpp index 29d54bb..bd5042c 100644 --- a/src/FrequencyInterleaver.cpp +++ b/src/FrequencyInterleaver.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include typedef std::complex complexf; @@ -68,7 +68,11 @@ FrequencyInterleaver::FrequencyInterleaver(size_t mode) : break; } - d_indexes = (size_t*)memalign(16, d_carriers * sizeof(size_t)); + const int ret = posix_memalign((void**)(&d_indexes), 16, d_carriers * sizeof(size_t)); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } + size_t* index = d_indexes; size_t perm = 0; PDEBUG("i: %4u, R: %4u\n", 0, 0); diff --git a/src/Resampler.cpp b/src/Resampler.cpp index 8069a61..2be753e 100644 --- a/src/Resampler.cpp +++ b/src/Resampler.cpp @@ -27,7 +27,7 @@ #include "Resampler.h" #include "PcDebug.h" -#include +#include #include #include #include @@ -81,7 +81,10 @@ Resampler::Resampler(size_t inputRate, size_t outputRate, size_t resolution) : myFactor = 1.0f / myFftSizeOut * outputRate / inputRate; } - myWindow = (float*)memalign(16, myFftSizeIn * sizeof(float)); + const int ret = posix_memalign((void**)(&myWindow), 16, myFftSizeIn * sizeof(float)); + if (ret != 0) { + throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + } for (size_t i = 0; i < myFftSizeIn; ++i) { myWindow[i] = (float)(0.5 * (1.0 - cos(2.0 * M_PI * i / (myFftSizeIn - 1)))); PDEBUG("Window[%zu] = %f\n", i, myWindow[i]); -- cgit v1.2.3