Skip to content

Commit e07e1db

Browse files
committed
[Stdlib] Put $ at the end of the Swift module's generic class ObjC names.
This avoids name conflicts between generic classes in the Swift modules of the old and new stdlibs when loaded into the same process.
1 parent d3c2a29 commit e07e1db

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,9 +2204,24 @@ static void initGenericClassObjCName(ClassMetadata *theClass) {
22042204

22052205
auto string = Demangle::mangleNodeOld(globalNode);
22062206

2207-
auto fullNameBuf = (char*)swift_slowAlloc(string.size() + 1, 0);
2207+
// If the class is in the Swift module, add a $ to the end of the ObjC
2208+
// name. The old and new Swift libraries must be able to coexist in
2209+
// the same process, and this avoids warnings due to the ObjC names
2210+
// colliding.
2211+
bool addSuffix = strncmp(string.c_str(), "_TtGCs", 6) == 0;
2212+
2213+
size_t allocationSize = string.size() + 1;
2214+
if (addSuffix)
2215+
allocationSize += 1;
2216+
2217+
auto fullNameBuf = (char*)swift_slowAlloc(allocationSize, 0);
22082218
memcpy(fullNameBuf, string.c_str(), string.size() + 1);
22092219

2220+
if (addSuffix) {
2221+
fullNameBuf[string.size()] = '$';
2222+
fullNameBuf[string.size() + 1] = '\0';
2223+
}
2224+
22102225
auto theMetaclass = (ClassMetadata *)object_getClass((id)theClass);
22112226

22122227
getROData(theClass)->Name = fullNameBuf;

0 commit comments

Comments
 (0)