Skip to content

Commit 10d2450

Browse files
committed
TClassEdit::GetNameForIO now returns typename with trailing stars.
Since the function also strip the unique_ptr from the inside template parameters, we can not tell from 'just' a name 'update/change' whether the IO type is a pointer or a non-pointer template instance.
1 parent 2e5d653 commit 10d2450

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

core/foundation/src/TClassEdit.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ class NameCleanerForIO {
20622062
// ROOT-9933: we remove const if present.
20632063
TClassEdit::TSplitType tst(name.c_str());
20642064
tst.ShortType(name, 1);
2065+
name += "*";
20652066
fHasChanged = true;
20662067
return name;
20672068
}
@@ -2106,7 +2107,7 @@ std::string TClassEdit::GetNameForIO(const std::string& templateInstanceName,
21062107
auto nameForIO = node.ToString();
21072108
if (hasChanged) {
21082109
*hasChanged = node.HasChanged();
2109-
}
2110+
}
21102111
return nameForIO;
21112112
}
21122113

core/foundation/test/testClassEdit.cxx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ TEST(TClassEdit, SplitFuncErrors)
247247
// ROOT-9926
248248
TEST(TClassEdit, GetNameForIO)
249249
{
250-
const std::vector<std::pair<std::string, std::string>> names{{"T", "unique_ptr<const T>"},
251-
{"T", "unique_ptr<const T*>"},
252-
{"T", "unique_ptr<const T* const*>"},
253-
{"T", "unique_ptr<T * const>"},
254-
{"T", "unique_ptr<T * const**const**&* const>"}};
250+
const std::vector<std::pair<std::string, std::string>> names{{"T*", "unique_ptr<const T>"},
251+
{"T*", "unique_ptr<const T*>"},
252+
{"T*", "unique_ptr<const T* const*>"},
253+
{"T*", "unique_ptr<T * const>"},
254+
{"T*", "unique_ptr<T * const**const**&* const>"},
255+
{"vector<T*>", "vector<unique_ptr<T>>"},
256+
{"vector<const T*>", "vector<unique_ptr<const T>>"}};
255257
for (auto &&namesp : names) {
256258
EXPECT_EQ(namesp.first, TClassEdit::GetNameForIO(namesp.second.c_str()))
257259
<< "Failure in transforming typename " << namesp.first << " into " << namesp.second;

core/meta/src/TStreamerElement.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,13 +1743,12 @@ TStreamerSTL::TStreamerSTL(const char *name, const char *title, Int_t offset,
17431743
std::string inside = (inside_type.find("const ")==0) ? inside_type.substr(6) : inside_type;
17441744

17451745
// Let's treat the unique_ptr case
1746-
bool nameChanged = false;
1747-
std::string intype = TClassEdit::GetNameForIO(inside, TClassEdit::EModType::kNone, &nameChanged);
1746+
std::string intype = TClassEdit::GetNameForIO(inside, TClassEdit::EModType::kNone);
17481747

1749-
bool isPointer = nameChanged; // unique_ptr is considered a pointer
1748+
bool isPointer = false;
17501749
// The incoming name is normalized (it comes from splitting the name of a TClass),
17511750
// so all we need to do is drop the last trailing star (if any) and record that information.
1752-
while (!nameChanged && intype[intype.length()-1] == '*') {
1751+
while (intype[intype.length()-1] == '*') {
17531752
isPointer = true;
17541753
intype.pop_back();
17551754
}

io/io/src/TGenCollectionProxy.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,12 @@ TGenCollectionProxy::Value::Value(const std::string& inside_type, Bool_t silent,
325325
fKind = kNoType_t;
326326

327327
// Let's treat the unique_ptr case
328-
bool nameChanged = false;
329-
std::string intype = TClassEdit::GetNameForIO(inside, TClassEdit::EModType::kNone, &nameChanged);
328+
std::string intype = TClassEdit::GetNameForIO(inside, TClassEdit::EModType::kNone);
330329

331-
bool isPointer = nameChanged; // unique_ptr is considered a pointer
330+
bool isPointer = false;
332331
// The incoming name is normalized (it comes from splitting the name of a TClass),
333332
// so all we need to do is drop the last trailing star (if any) and record that information.
334-
if (!nameChanged && intype[intype.length()-1] == '*') {
333+
if (intype[intype.length()-1] == '*') {
335334
isPointer = true;
336335
intype.pop_back();
337336
if (intype[intype.length()-1] == '*') {

io/io/src/TStreamerInfo.cxx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,11 @@ void TStreamerInfo::Build(Bool_t isTransient)
437437
bool nameChanged;
438438
trueTypeNameBuf = typeNameBuf = TClassEdit::GetNameForIO(dmFull, TClassEdit::EModType::kNone, &nameChanged);
439439
if (nameChanged) {
440-
if (TClassEdit::IsUniquePtr(dmFull)) {
440+
if (trueTypeNameBuf.back() == '*') {
441441
dmIsPtr = true;
442+
typeNameBuf.pop_back();
443+
while(typeNameBuf.back() == '*') typeNameBuf.pop_back();
442444
}
443-
while(typeNameBuf.back() == '*') typeNameBuf.pop_back();
444445
dmFull = trueTypeNameBuf.c_str();
445446
dmType = typeNameBuf.c_str();
446447
}
@@ -2044,7 +2045,7 @@ void TStreamerInfo::BuildOld()
20442045

20452046
TDataMember* dm = 0;
20462047

2047-
std::string typeNameBuf;
2048+
std::string typeNameBuf; // Keep underlying buffer alive until actually used.
20482049
const char* dmType = nullptr;
20492050
Bool_t dmIsPtr = false;
20502051
TDataType* dt(nullptr);
@@ -2082,7 +2083,11 @@ void TStreamerInfo::BuildOld()
20822083
Bool_t nameChanged;
20832084
typeNameBuf = TClassEdit::GetNameForIO(dmType, TClassEdit::EModType::kNone, &nameChanged);
20842085
if (nameChanged) {
2085-
dmIsPtr = TClassEdit::IsUniquePtr(dmType);
2086+
if (typeNameBuf.back() == '*') {
2087+
dmIsPtr = true;
2088+
typeNameBuf.pop_back();
2089+
while(typeNameBuf.back() == '*') typeNameBuf.pop_back();
2090+
}
20862091
dmType = typeNameBuf.c_str();
20872092
}
20882093
if ((isStdArray = TClassEdit::IsStdArray(dmType))){ // We tackle the std array case

0 commit comments

Comments
 (0)