From ab99eb5830ba521dd515808b0f880bd84f5b6281 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Mon, 19 Dec 2022 18:12:27 -0800 Subject: [PATCH 1/4] quote path in post-build event (issue #666 --- ide/vs2019/mimalloc-override.vcxproj | 8 ++++---- ide/vs2022/mimalloc-override.vcxproj | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ide/vs2019/mimalloc-override.vcxproj b/ide/vs2019/mimalloc-override.vcxproj index 182ddab1..5fa59569 100644 --- a/ide/vs2019/mimalloc-override.vcxproj +++ b/ide/vs2019/mimalloc-override.vcxproj @@ -110,7 +110,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -138,7 +138,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory @@ -170,7 +170,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -202,7 +202,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory diff --git a/ide/vs2022/mimalloc-override.vcxproj b/ide/vs2022/mimalloc-override.vcxproj index 87b0a1e4..e7133af4 100644 --- a/ide/vs2022/mimalloc-override.vcxproj +++ b/ide/vs2022/mimalloc-override.vcxproj @@ -110,7 +110,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -138,7 +138,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory @@ -170,7 +170,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -202,7 +202,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory From b701d4cbfa132fe6c79c3f5580842e0c46e9cfc3 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Mon, 19 Dec 2022 18:39:52 -0800 Subject: [PATCH 2/4] bump cmake minimal version to 3.13 to support CMAKE_INTERPROCEDURAL_OPTIMIZATION -- see PR 656. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97a4984a..0011b874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.13) project(libmimalloc C CXX) set(CMAKE_C_STANDARD 11) From 94b8cb870e1d459d4617d5f558e955fa48e6443c Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Mon, 19 Dec 2022 18:40:12 -0800 Subject: [PATCH 3/4] quote path in post-build event (issue #666 --- ide/vs2017/mimalloc-override.vcxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ide/vs2017/mimalloc-override.vcxproj b/ide/vs2017/mimalloc-override.vcxproj index a1266dc9..1c6a8fda 100644 --- a/ide/vs2017/mimalloc-override.vcxproj +++ b/ide/vs2017/mimalloc-override.vcxproj @@ -110,7 +110,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -138,7 +138,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory @@ -170,7 +170,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect32.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect32.dll" "$(OutputPath)" Copy mimalloc-redirect32.dll to the output directory @@ -202,7 +202,7 @@ false - COPY /Y $(ProjectDir)..\..\bin\mimalloc-redirect.dll $(OutputPath) + COPY /Y "$(ProjectDir)..\..\bin\mimalloc-redirect.dll" "$(OutputPath)" copy mimalloc-redirect.dll to the output directory From ef3f651f3faeb8a9dfd95b4a82a07e263a146c35 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Mon, 19 Dec 2022 18:59:33 -0800 Subject: [PATCH 4/4] change implementation of mi_realpath to be more robust; see issue #660 --- src/alloc.c | 22 ++++++++++++++++++---- test/main-override.cpp | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 6e468c85..554405f1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -781,7 +781,9 @@ mi_decl_nodiscard mi_decl_restrict char* mi_heap_strdup(mi_heap_t* heap, const c if (s == NULL) return NULL; size_t n = strlen(s); char* t = (char*)mi_heap_malloc(heap,n+1); - if (t != NULL) _mi_memcpy(t, s, n + 1); + if (t == NULL) return NULL; + _mi_memcpy(t, s, n); + t[n] = 0; return t; } @@ -832,6 +834,7 @@ mi_decl_nodiscard mi_decl_restrict char* mi_heap_realpath(mi_heap_t* heap, const } #else #include // pathconf +/* static size_t mi_path_max(void) { static size_t path_max = 0; if (path_max <= 0) { @@ -842,20 +845,31 @@ static size_t mi_path_max(void) { } return path_max; } - +*/ char* mi_heap_realpath(mi_heap_t* heap, const char* fname, char* resolved_name) mi_attr_noexcept { if (resolved_name != NULL) { return realpath(fname,resolved_name); } else { - size_t n = mi_path_max(); + char* rname = realpath(fname, NULL); + if (rname == NULL) return NULL; + char* result = mi_heap_strdup(heap, rname); + free(rname); // use regular free! (which may be redirected to our free but that's ok) + return result; + } + /* + const size_t n = mi_path_max(); char* buf = (char*)mi_malloc(n+1); - if (buf==NULL) return NULL; + if (buf == NULL) { + errno = ENOMEM; + return NULL; + } char* rname = realpath(fname,buf); char* result = mi_heap_strndup(heap,rname,n); // ok if `rname==NULL` mi_free(buf); return result; } + */ } #endif diff --git a/test/main-override.cpp b/test/main-override.cpp index 37d4daae..e63d605a 100644 --- a/test/main-override.cpp +++ b/test/main-override.cpp @@ -39,6 +39,7 @@ static void heap_thread_free_huge(); static void test_stl_allocators(); + int main() { mi_stats_reset(); // ignore earlier allocations