]>
git.saurik.com Git - apple/dyld.git/blob - testing/test-cases/weak-coalesce-inserted-dylibs.dtest/main.cpp
2 // BUILD: $CXX foo.cpp -dynamiclib -install_name $RUN_DIR/libfoo.dylib -o $BUILD_DIR/libfoo.dylib -fno-exceptions
3 // BUILD: $CXX bar.cpp -dynamiclib -install_name $RUN_DIR/libbar.dylib -o $BUILD_DIR/libbar.dylib -fno-exceptions
4 // BUILD: $CXX main.cpp $BUILD_DIR/libfoo.dylib -o $BUILD_DIR/weak-coalesce-inserted-dylibs.exe -fno-exceptions
5 // BUILD: $DYLD_ENV_VARS_ENABLE $BUILD_DIR/weak-coalesce-inserted-dylibs.exe
7 // RUN: DYLD_INSERT_LIBRARIES=libbar.dylib ./weak-coalesce-inserted-dylibs.exe
13 #include "test_support.h"
17 // We have our own copy of operator new. Make sure that we call our version, but that foo calls the one from the inserted bar dylib
18 static bool calledMainNew
= false;
19 static bool calledMainDelete
= false;
20 static bool enableTracking
= false;
22 void* operator new(size_t size
)
26 void* ptr
= malloc(size
);
30 void operator delete(void* ptr
)
33 calledMainDelete
= true;
37 int main(int argc
, const char* argv
[], const char* envp
[], const char* apple
[]) {
38 // First make sure we do use our versions of new and delete.
39 enableTracking
= true;
43 FAIL("Didn't call executable operator new");
47 if (!calledMainDelete
) {
48 FAIL("Didn't call executable operator delete");
51 // Now make foo do the same and make sure we got the new/delete from bar
52 calledMainNew
= false;
53 calledMainDelete
= false;
57 FAIL("Didn't call bar operator new");
60 if (calledMainDelete
) {
61 FAIL("Didn't call bar operator delete");