Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
reflection-based remoting support
  • Loading branch information
koubaa committed Jun 24, 2020
commit 82bdb9ab8f8c91c6e6edcc99bbd0369c273b404d
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 19 additions & 1 deletion src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ internal static IntPtr ToPython<T>(T value)
return ToPython(value, typeof(T));
}

private static readonly Func<object, bool> IsTransparentProxy = GetIsTransparentProxy();

private static bool Never(object _) => false;

private static Func<object, bool> 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<object, bool>)Delegate.CreateDelegate(
typeof(Func<object, bool>), isProxy,
throwOnBindFailure: true);
}

internal static IntPtr ToPython(object value, Type type)
{
if (value is PyObject)
Expand Down Expand Up @@ -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
Expand Down