From 1df75ea010627b39c2d866d85c49029bc50a5f47 Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Tue, 23 Jun 2020 09:15:11 -0500 Subject: [PATCH 1/2] remove remoting --- CHANGELOG.md | 1 + src/runtime/converter.cs | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e82f40e3..69c44acb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ This version improves performance on benchmarks significantly compared to 2.3. `Obsolete`, should never have been `public` in the first place. They also don't necessarily return a result that matches the `platform` module's. - Unconditionally depend on `pycparser` for the interop module generation +- Removed .NET remoting support ### Fixed diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index 2b92ca994..a20774f07 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -162,15 +162,7 @@ internal static IntPtr ToPython(object value, Type type) var pyderived = value as IPythonDerivedType; if (null != pyderived) { - #if NETSTANDARD return ClassDerivedObject.ToPython(pyderived); - #else - // if object is remote don't do this - if (!System.Runtime.Remoting.RemotingServices.IsTransparentProxy(pyderived)) - { - return ClassDerivedObject.ToPython(pyderived); - } - #endif } // hmm - from Python, we almost never care what the declared From 82bdb9ab8f8c91c6e6edcc99bbd0369c273b404d Mon Sep 17 00:00:00 2001 From: Mohamed Koubaa Date: Wed, 24 Jun 2020 15:41:01 -0500 Subject: [PATCH 2/2] reflection-based remoting support --- CHANGELOG.md | 1 - src/runtime/converter.cs | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c44acb3..3e82f40e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,6 @@ This version improves performance on benchmarks significantly compared to 2.3. `Obsolete`, should never have been `public` in the first place. They also don't necessarily return a result that matches the `platform` module's. - Unconditionally depend on `pycparser` for the interop module generation -- Removed .NET remoting support ### Fixed diff --git a/src/runtime/converter.cs b/src/runtime/converter.cs index a20774f07..734422ed0 100644 --- a/src/runtime/converter.cs +++ b/src/runtime/converter.cs @@ -113,6 +113,23 @@ internal static IntPtr ToPython(T value) return ToPython(value, typeof(T)); } + private static readonly Func IsTransparentProxy = GetIsTransparentProxy(); + + private static bool Never(object _) => false; + + private static Func GetIsTransparentProxy() + { + var remoting = typeof(int).Assembly.GetType("System.Runtime.Remoting.RemotingServices"); + if (remoting is null) return Never; + + var isProxy = remoting.GetMethod("IsTransparentProxy", new[] { typeof(object) }); + if (isProxy is null) return Never; + + return (Func)Delegate.CreateDelegate( + typeof(Func), isProxy, + throwOnBindFailure: true); + } + internal static IntPtr ToPython(object value, Type type) { if (value is PyObject) @@ -162,7 +179,8 @@ internal static IntPtr ToPython(object value, Type type) var pyderived = value as IPythonDerivedType; if (null != pyderived) { - return ClassDerivedObject.ToPython(pyderived); + if (!IsTransparentProxy(pyderived)) + return ClassDerivedObject.ToPython(pyderived); } // hmm - from Python, we almost never care what the declared