Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[PyROOT] Disable automatic conversion of regular to smart pointers #15125

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,14 @@ bool CPyCppyy::SmartPtrConverter::SetArg(
return true;
}

// The automatic conversion of ordinary obejcts to smart pointers is disabled
// for PyROOT because it can cause trouble with overload resolution. If a
// function has overloads for both ordinary objects and smart pointers, then
// the implicit conversion to smart pointers can result in the smart pointer
// overload being hit, even though there would be an overload for the regular
// object. Since PyROOT didn't have this feature before 6.32 anyway, disabling
// it was the safest option.
#if 0
// for the case where we have an ordinary object to convert
if (!pyobj->IsSmart() && Cppyy::IsSubtype(oisa, fUnderlyingType)) {
// create the relevant smart pointer and make the pyobject "smart"
Expand All @@ -2852,6 +2860,7 @@ bool CPyCppyy::SmartPtrConverter::SetArg(

return true;
}
#endif

// final option, try mapping pointer types held (TODO: do not allow for non-const ref)
if (pyobj->IsSmart() && Cppyy::IsSubtype(oisa, fUnderlyingType)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 72df898c30db57c43d4cd3136435f36876596c6a Mon Sep 17 00:00:00 2001
From: Jonas Rembser <jonas.rembser@cern.ch>
Date: Thu, 4 Apr 2024 02:07:22 +0200
Subject: [PATCH] [CPyCppyy] Disable automatic conversion of regular to smart
pointers

The automatic conversion of ordinary obejcts to smart pointers is
disabled for PyROOT because it can cause trouble with overload
resolution. If a function has overloads for both ordinary objects and
smart pointers, then the implicit conversion to smart pointers can
result in the smart pointer overload being hit, even though there would
be an overload for the regular object. Since PyROOT didn't have this
feature before 6.32 anyway, disabling it was the safest option.

Closes #15117.
---
bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx b/bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx
index 4ac294745ca..830e504ba12 100644
--- a/bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx
+++ b/bindings/pyroot/cppyy/CPyCppyy/src/Converters.cxx
@@ -2834,6 +2834,14 @@ bool CPyCppyy::SmartPtrConverter::SetArg(
return true;
}

+// The automatic conversion of ordinary obejcts to smart pointers is disabled
+// for PyROOT because it can cause trouble with overload resolution. If a
+// function has overloads for both ordinary objects and smart pointers, then
+// the implicit conversion to smart pointers can result in the smart pointer
+// overload being hit, even though there would be an overload for the regular
+// object. Since PyROOT didn't have this feature before 6.32 anyway, disabling
+// it was the safest option.
+#if 0
// for the case where we have an ordinary object to convert
if (!pyobj->IsSmart() && Cppyy::IsSubtype(oisa, fUnderlyingType)) {
// create the relevant smart pointer and make the pyobject "smart"
@@ -2852,6 +2860,7 @@ bool CPyCppyy::SmartPtrConverter::SetArg(

return true;
}
+#endif

// final option, try mapping pointer types held (TODO: do not allow for non-const ref)
if (pyobj->IsSmart() && Cppyy::IsSubtype(oisa, fUnderlyingType)) {
--
2.44.0

1 change: 1 addition & 0 deletions bindings/pyroot/cppyy/sync-upstream
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ git apply patches/CPyCppyy-Add-converters-and-executors-for-ROOT-types.patch
git apply patches/CPyCppyy-TString_converter.patch
git apply patches/CPyCppyy-Adapt-to-no-std-in-ROOT.patch
git apply patches/CPyCppyy-Always-convert-returned-std-string.patch
git apply patches/CPyCppyy-Disable-implicit-conversion-to-smart-ptr.patch
git apply patches/cppyy-No-CppyyLegacy-namespace.patch
git apply patches/cppyy-Remove-Windows-workaround.patch
git apply patches/cppyy-Don-t-enable-cling-autoloading.patch
Loading