[PyROOT] Fix hash collision in TemplateProxy dispatch for CPPOverload objects #20708
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #20526
Description
This PR addresses a hash collision issue in
CPyCppyy::HashSignaturethat caused incorrect template instantiation caching in PyROOT.Analysis
The
HashSignaturefunction previously calculated the signature hash forCPPOverloadobjects based solely onPy_TYPEandPy_REFCNT.gbl.plus_oneandgbl.add) are often wrapped asCPPOverloadobjects with identical reference counts.TemplateProxydispatch cache would then incorrectly return a cached instantiation for the wrong function (e.g:- executingplus_onelogic whenaddwas called), leading to runtime errors or incorrect results.The Fix
I updated
CPPOverload.hto incorporate the object identity (pointer address) into the hash calculation forCPPOverloadandTemplateProxytypes.Verification
I reproduced the issue using the script provided in #20526.
sighash=9088374328679265724.get_one:469779200852894291plus_one:469780645212860978Note on Overload Resolution
During debugging, I observed that the
tpp_vectorcallmechanism involves speculative execution of candidates during the overload resolution cascade. While this PR fixes the correctness issue (the hash collision), the architectural behavior of multiple invocations during resolution remains unchanged and is outside the scope of this fix.