]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/intrusive_shared_ptr_src/abi.caller.raw.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / abi.caller.raw.cpp
diff --git a/tests/intrusive_shared_ptr_src/abi.caller.raw.cpp b/tests/intrusive_shared_ptr_src/abi.caller.raw.cpp
new file mode 100644 (file)
index 0000000..b13f8bb
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// This tests that we can call functions implemented using shared pointers
+// from an API vending itself as returning raw pointers, because both are
+// ABI compatible.
+//
+// In this TU, SharedPtr<T> is just T*, since USE_SHARED_PTR is not defined.
+//
+
+#include <darwintest.h>
+#include "abi_helper.h"
+
+// Receive a raw pointer from a function that actually returns a smart pointer
+T_DECL(abi_caller_raw, "intrusive_shared_ptr.abi.caller.raw") {
+       T obj{10};
+       T* expected = &obj;
+       T* result = return_shared_as_raw(expected);
+       CHECK(result == expected);
+
+       // Sometimes the test above passes even though it should fail, if the
+       // right address happens to be on the stack in the right location. This
+       // can happen if abi.caller.smart is run just before this test. This
+       // second test makes sure it fails when it should.
+       CHECK(result->i == 10);
+}