Repository navigation
[core] Fix TDataMember::GetOffsetCint interference with GetOffset - #23844
ravindra-RKB wants to merge 1 commit into
Conversation
| if (dm->IsValid()) { | ||
| if (dm->fInfo) return gCling->DataMemberInfo_Offset(dm->fInfo); | ||
| if (fOffset >= 0) return fOffset; | ||
| } | ||
| return -1; |
There was a problem hiding this comment.
I am not sure this is the right solution. A priori the value can be as well cached for these call as for the previous call. It is not clear whether there is really a need for both functions to be distinct. However this need a deep analysis of the usage pattern in ROOT and in user codes.
There was a problem hiding this comment.
Thanks @pcanal. Should we cache this into a dedicated fOffsetCint member instead, or do you prefer consolidating both functions? Happy to adapt based on what fits best.
There was a problem hiding this comment.
The firsts step is to do an analysis of whether it makes sense or not to merge the 2 or to protect them from being called in the wrong context.
There was a problem hiding this comment.
Looking through the codebase usages:
GetOffset()is used for instance byte offsets (TStreamerInfo,RFieldMeta,TTree). For non-static data members, both functions yield the same offset.- For static variables and enum constants,
GetOffset()returns 0 becauseBuildRealData()does not track them, whereasGetOffsetCint()queries Cling, which returns the address/value. - If called on an enum or static member,
GetOffset()is technically the "wrong context" (no instance offset exists) and erroneously caches 0 intofOffset.
Would it make sense to protect GetOffset() so it returns -1 (or avoids setting fOffset = 0) when Property() & (kIsStatic | kIsEnum), or should GetOffset() delegate to Cling for static/enum members as well?
Test Results 23 files 23 suites 3d 17h 15m 4s ⏱️ Results for commit 5538730. |
Description
Fixes #23777
TDataMember::GetOffsetCint()previously returned early iffOffset >= 0. However, whenTDataMember::GetOffset()is invoked first on a data member (such as an enum constant or members wherefOffsetis computed as0), it cachesfOffset = 0. Consequently, subsequent calls toGetOffsetCint()would return the cached0instead of querying the Cling interpreter for the actual offset/address.This change updates
GetOffsetCint()to prefergCling->DataMemberInfo_Offset(dm->fInfo)wheneverfInfois available and valid, and only fall back tofOffsetwhenfInfois not available. A regression unit test covering #23777 has also been added toroottest/root/meta/unit/datamem.cxx.Checklist