#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <new>
#include "test_support.h"
extern void* foo();
void* lastAllocatedValue = NULL;
void* operator new(size_t size) {
lastAllocatedValue = malloc(size);
return lastAllocatedValue;
}
int main()
{
int* value1 = new int(1);
if ( value1 != lastAllocatedValue ) {
FAIL("value1 (%p) != lastAllocatedValue (%p)", value1, lastAllocatedValue);
}
void* handle = dlopen(RUN_DIR "/libfoo.dylib", RTLD_FIRST);
if ( handle == NULL ) {
FAIL("dlopen(\"%s\") failed with: %s", RUN_DIR "/libfoo.dylib", dlerror());
}
const void* symFoo = dlsym(handle, "foo");
if ( symFoo == NULL ) {
FAIL("dlsym(handle, foo) failed");
}
void* value2 = ((__typeof(&foo))symFoo)();
if ( value2 != lastAllocatedValue ) {
FAIL("value2 (%p) != lastAllocatedValue (%p)", value2, lastAllocatedValue);
}
PASS("weak-coalesce-dlopen");
}