]>
git.saurik.com Git - apple/xnu.git/blob - tests/intrusive_shared_ptr_src/abi.caller.smart.cpp
2 // This tests that we can call functions implemented using raw pointers from
3 // an API vending itself as returning shared pointers, because both are ABI
6 // In this TU, SharedPtr<T> is intrusive_shared_ptr<T>, since USE_SHARED_PTR
10 #define USE_SHARED_PTR
12 #include <libkern/c++/intrusive_shared_ptr.h>
13 #include <darwintest.h>
14 #include "abi_helper.h"
16 static_assert(sizeof(SharedPtr
<T
>) == sizeof(T
*));
17 static_assert(alignof(SharedPtr
<T
>) == alignof(T
*));
19 // Receive a shared pointer from a function that actually returns a raw pointer
20 T_DECL(abi_caller_smart
, "intrusive_shared_ptr.abi.caller.smart") {
23 SharedPtr
<T
> result
= return_raw_as_shared(expected
);
24 CHECK(result
.get() == expected
);
26 // Sometimes the test above passes even though it should fail, if the
27 // right address happens to be on the stack in the right location. This
28 // can happen if abi.caller.raw is run just before this test. This second
29 // test makes sure it fails when it should.
30 CHECK(result
->i
== 3);