Skip to content

Commit d6c8456

Browse files
committed
Minor corrections
1 parent 073633f commit d6c8456

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

documentation/cxx-interop/index.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,21 +1256,9 @@ object.doSomething()
12561256
```
12571257

12581258
### 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 as +0 and there is no transfer of ownership.
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.
12601260
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.
12611261

1262-
If the argument is an inout (non-const reference) as shown below:
1263-
```c++
1264-
void takeSharedObjectAsInout(SharedObject *& x) { ... }
1265-
```
1266-
1267-
which would be imported in Swift as
1268-
```swift
1269-
func takeSharedObjectAsInout(_ x: inout SharedObject) { ... }
1270-
```
1271-
1272-
If the C++ function overwrites the value of the argument with the new value, it 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.
1273-
12741262
```swift
12751263
var obj = SharedObject.create()
12761264
receiveSharedObject(obj) // Swift guarantees that obj is alive
@@ -1283,6 +1271,18 @@ void receiveSharedObject(SharedObject *sobj) {
12831271
}
12841272
```
12851273
1274+
Note that if the argument is an inout (non-const reference) as shown below:
1275+
```c++
1276+
void takeSharedObjectAsInout(SharedObject *& x) { ... }
1277+
```
1278+
1279+
which would be imported in Swift as
1280+
```swift
1281+
func takeSharedObjectAsInout(_ x: inout SharedObject) { ... }
1282+
```
1283+
1284+
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.
1285+
12861286
### Inheritance and Virtual Member Functions
12871287

12881288
Similar to value types, casting an instance of a derived reference type to a

0 commit comments

Comments
 (0)