1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 07:13:02 +04:00

3rdparty(mlas): fix MinGW build of aligned scratch buffer

MlasThreadedBufAlloc() and its ThreadedBufHolder guarded the
_aligned_malloc / _aligned_free path on _MSC_VER. Non-MSVC Windows
toolchains (MinGW, clang) therefore fell through to posix_memalign(),
which the Windows CRT does not provide, so the build failed with
"'posix_memalign' was not declared in this scope".

Guard the aligned-allocation path on _WIN32 instead, in both the holder
declaration (mlasi.h) and definition (platform.cpp) so the unique_ptr
deleter type stays consistent across translation units, and include
<malloc.h> on Windows since MinGW only declares the _aligned_* functions
there. The non-Windows posix_memalign / aligned_alloc fallback is
unchanged.

Fixes #29350
This commit is contained in:
ShivaPriyanShanmuga
2026-06-20 22:32:07 -04:00
parent 6d2cd14bb2
commit f831c94309
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -48,6 +48,7 @@ Abstract:
#endif
#include <windows.h>
#include <intrin.h>
#include <malloc.h>
#else
#if defined(__arm__) || defined(__aarch64__)
#include <arm_neon.h>
@@ -3014,7 +3015,7 @@ MlasReadTimeStampCounter(void)
constexpr size_t ThreadedBufAlignment = 64;
extern thread_local size_t ThreadedBufSize;
#ifdef _MSC_VER
#ifdef _WIN32
extern thread_local std::unique_ptr<uint8_t, decltype(&_aligned_free)> ThreadedBufHolder;
#else
extern thread_local std::unique_ptr<uint8_t, decltype(&free)> ThreadedBufHolder;
@@ -3034,7 +3035,7 @@ void
MlasThreadedBufAlloc(size_t size)
{
if (size > ThreadedBufSize) {
#ifdef _MSC_VER
#ifdef _WIN32
ThreadedBufHolder.reset(
reinterpret_cast<uint8_t*>(_aligned_malloc(size, ThreadedBufAlignment)));
#elif (__STDC_VERSION__ >= 201112L) && !defined(__APPLE__)
+1 -1
View File
@@ -1088,7 +1088,7 @@ MlasPlatformU8S8Overflow(
#endif
thread_local size_t ThreadedBufSize = 0;
#ifdef _MSC_VER
#ifdef _WIN32
thread_local std::unique_ptr<uint8_t, decltype(&_aligned_free)> ThreadedBufHolder(nullptr, &_aligned_free);
#else
thread_local std::unique_ptr<uint8_t, decltype(&free)> ThreadedBufHolder(nullptr, &free);