You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/cxx-interop/index.md
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1255,9 +1255,12 @@ object.doSomething()
1255
1255
// `object` will be released here.
1256
1256
```
1257
1257
1258
-
### Calling conventions when passing shared reference types from Swift to C++
1259
-
If a C++ shared reference type is passed as an argument to a C++ API from Swift, the Swift compiler guarantees that the passed value would be alive, and retains the ownership of the value. In other words, the argument is passed at `+0` and there is no transfer of ownership.
1260
-
The C++ function is responsible for ensuring that the value pointed to by the parameter is alive during and at the end of the call. The C++ function should not assume it has ownership of the value and should do necessary retain operations if it is needs to take ownership.
1258
+
### Calling conventions when passing Shared Reference Types from Swift to C++
1259
+
1260
+
If a C++ shared reference type is passed as an argument to a C++ API from Swift, the Swift compiler guarantees that the passed value would be alive, and retains the ownership of the value.
1261
+
In other words, the argument is passed at `+0` and there is no transfer of ownership.
1262
+
The C++ function is responsible for ensuring that the value pointed to by the parameter is alive during and at the end of the call.
1263
+
The C++ function should not assume it has ownership of the value and should do necessary retain operations if it is needs to take ownership.
the C++ function can overwrite the value of the argument with the new value. However, the C++ function is responsible for releasing the old value, and ensuring that the new value is properly retained so that the Swift caller has ownership of the new value when the function returns. Adhering to these rules is necessary to safely and correctly pass around `SWIFT_SHARED_REFERENCE` between Swift and C++. These rules are also generally recommended conventions to manage shared objects that use reference counting.
1289
+
The C++ function can overwrite the value of the argument with the new value.
1290
+
However, the C++ function is responsible for releasing the old value, and ensuring that the new value is properly retained so that the Swift caller has ownership of the new value when the function returns.
1291
+
Adhering to these rules is necessary to safely and correctly pass around `SWIFT_SHARED_REFERENCE` between Swift and C++.
1292
+
These rules are also generally recommended conventions to manage shared objects that use reference counting.
0 commit comments