merge from dev

This commit is contained in:
daanx 2025-01-06 12:11:06 -08:00
commit d7c273e5cd
10 changed files with 456 additions and 33 deletions

View file

@ -0,0 +1,15 @@
// Issue #981: test overriding allocation in a DLL that is compiled independent of mimalloc.
// This is imported by the `mimalloc-test-override` project.
#include <string>
#include "main-override-dep.h"
std::string TestAllocInDll::GetString()
{
char* test = new char[128];
memset(test, 0, 128);
const char* t = "test";
memcpy(test, t, 4);
std::string r = test;
delete[] test;
return r;
}

11
test/main-override-dep.h Normal file
View file

@ -0,0 +1,11 @@
#pragma once
// Issue #981: test overriding allocation in a DLL that is compiled independent of mimalloc.
// This is imported by the `mimalloc-test-override` project.
#include <string>
class TestAllocInDll
{
public:
__declspec(dllexport) std::string GetString();
};

View file

@ -9,16 +9,11 @@
#include <vector>
#include <future>
#include <iostream>
#include <thread>
//#include <mimalloc.h>
#include <assert.h>
#ifdef _WIN32
#include <mimalloc-new-delete.h>
#endif
#ifdef _WIN32
#include <windows.h>
static void msleep(unsigned long msecs) { Sleep(msecs); }
#else
@ -42,11 +37,19 @@ static void test_thread_local(); // issue #944
static void test_mixed1(); // issue #942
static void test_stl_allocators();
#if _WIN32
#include "main-override-dep.h"
static void test_dep(); // issue #981: test overriding in another DLL
#else
static void test_dep() { };
#endif
int main() {
mi_stats_reset(); // ignore earlier allocations
various_tests();
test_mixed1();
test_dep();
//test_std_string();
//test_thread_local();
@ -139,6 +142,16 @@ static bool test_stl_allocator1() {
struct some_struct { int i; int j; double z; };
#if _WIN32
static void test_dep()
{
TestAllocInDll t;
std::string s = t.GetString();
}
#endif
static bool test_stl_allocator2() {
std::vector<some_struct, mi_stl_allocator<some_struct> > vec;
vec.push_back(some_struct());