summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2020-04-28 23:48:25 +0200
committerJose <jose@zeroc.com>2020-04-28 23:51:32 +0200
commitf55c6c5062f37de53cc534e25f4dba4d5d0779fb (patch)
tree89a26b3a76e7f52e38a8a16a86aacf6c8d9abdc5 /cpp/src
parentFix for testing bindists (diff)
downloadice-f55c6c5062f37de53cc534e25f4dba4d5d0779fb.tar.bz2
ice-f55c6c5062f37de53cc534e25f4dba4d5d0779fb.tar.xz
ice-f55c6c5062f37de53cc534e25f4dba4d5d0779fb.zip
Fix swift dangling pointer warnings - Close #821
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/slice2swift/Gen.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/cpp/src/slice2swift/Gen.cpp b/cpp/src/slice2swift/Gen.cpp
index 45eb33c51e7..056786dee5d 100644
--- a/cpp/src/slice2swift/Gen.cpp
+++ b/cpp/src/slice2swift/Gen.cpp
@@ -888,15 +888,20 @@ Gen::TypesVisitor::visitDictionary(const DictionaryPtr& p)
string keyParam = "let key: " + keyType;
writeMarshalUnmarshalCode(out, p->keyType(), p, keyParam, false);
out << nl << "v[key] = nil as " << valueType;
+ out << nl << "Swift.withUnsafeMutablePointer(to: &v[key, default:nil])";
+ out << sb;
out << nl << "e.values[i] = Ice.DictEntry<" << keyType << ", " << valueType << ">("
<< "key: key, "
- << "value: UnsafeMutablePointer<" << valueType << ">(&v[key, default:nil]))";
+ << "value: $0)";
+ out << eb;
writeMarshalUnmarshalCode(out, p->valueType(), p, "e.values[i].value.pointee", false);
out << eb;
out << nl << "for i in 0..<sz" << sb;
- out << nl << "e.values[i].value = Swift.UnsafeMutablePointer<" << valueType
- << ">(&v[e.values[i].key, default:nil])";
+ out << nl << "Swift.withUnsafeMutablePointer(to: &v[e.values[i].key, default:nil])";
+ out << sb;
+ out << nl << "e.values[i].value = $0";
+ out << eb;
out << eb;
}
else