merge from dev

This commit is contained in:
daanx 2025-05-02 16:28:57 -07:00
commit 90da648b08
7 changed files with 67 additions and 19 deletions

View file

@ -1,6 +1,7 @@
// Issue #981: test overriding allocation in a DLL that is compiled independent of mimalloc.
// 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 <iostream>
#include "main-override-dep.h"
std::string TestAllocInDll::GetString()
@ -10,6 +11,7 @@ std::string TestAllocInDll::GetString()
const char* t = "test";
memcpy(test, t, 4);
std::string r = test;
std::cout << "override-dep: GetString: " << r << "\n";
delete[] test;
return r;
}
@ -22,4 +24,37 @@ void TestAllocInDll::TestHeapAlloc()
int* p = (int*)HeapAlloc(heap, 0, sizeof(int));
*p = 42;
HeapFree(heap, 0, p);
}
}
class Static {
private:
void* p;
public:
Static() {
printf("override-dep: static constructor\n");
p = malloc(64);
return;
}
~Static() {
free(p);
printf("override-dep: static destructor\n");
return;
}
};
static Static s = Static();
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID reserved) {
(void)(reserved);
(void)(module);
if (reason==DLL_PROCESS_ATTACH) {
printf("override-dep: dll attach\n");
}
else if (reason==DLL_PROCESS_DETACH) {
printf("override-dep: dll detach\n");
}
return TRUE;
}