From dfea6bb7b953487b99fa345f8ee50c3d0d08bf4b Mon Sep 17 00:00:00 2001 From: stakx Date: Sat, 2 Jan 2021 20:57:04 +0100 Subject: [PATCH 1/3] `UIntPtr` out / default return values not supported --- .../Interfaces/IFooWithOutUIntPtr.cs | 23 +++++++++++++++++++ .../Interfaces/IFooWithUIntPtr.cs | 23 +++++++++++++++++++ .../NonProxiedMethodsNoTargetTestCase.cs | 18 +++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithOutUIntPtr.cs create mode 100644 src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithUIntPtr.cs diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithOutUIntPtr.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithOutUIntPtr.cs new file mode 100644 index 0000000000..0b87b5a2db --- /dev/null +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithOutUIntPtr.cs @@ -0,0 +1,23 @@ +// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.DynamicProxy.Tests.Interfaces +{ + using System; + + public interface IFooWithOutUIntPtr + { + int Bar(out UIntPtr i); + } +} \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithUIntPtr.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithUIntPtr.cs new file mode 100644 index 0000000000..501cc83fa5 --- /dev/null +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/Interfaces/IFooWithUIntPtr.cs @@ -0,0 +1,23 @@ +// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Castle.DynamicProxy.Tests.Interfaces +{ + using System; + + public interface IFooWithUIntPtr + { + UIntPtr Buffer(UInt32 index); + } +} \ No newline at end of file diff --git a/src/Castle.Core.Tests/DynamicProxy.Tests/NonProxiedMethodsNoTargetTestCase.cs b/src/Castle.Core.Tests/DynamicProxy.Tests/NonProxiedMethodsNoTargetTestCase.cs index b5f138fba5..be75e53c59 100644 --- a/src/Castle.Core.Tests/DynamicProxy.Tests/NonProxiedMethodsNoTargetTestCase.cs +++ b/src/Castle.Core.Tests/DynamicProxy.Tests/NonProxiedMethodsNoTargetTestCase.cs @@ -158,6 +158,15 @@ public void Target_method_IntPtr() Assert.AreEqual(IntPtr.Zero, result); } + [Test] + public void Target_method_UIntPtr() + { + var proxy = CreateProxy(); + var result = new UIntPtr(123); + Assert.DoesNotThrow(() => result = proxy.Buffer(1u)); + Assert.AreEqual(UIntPtr.Zero, result); + } + [Test] public void Target_method_Nullable_parameters() { @@ -192,6 +201,15 @@ public void Target_method_out_IntPtr() Assert.AreEqual(IntPtr.Zero, result); } + [Test] + public void Target_method_out_UIntPtr() + { + var proxy = CreateProxy(); + var result = new UIntPtr(123); + Assert.DoesNotThrow(() => proxy.Bar(out result)); + Assert.AreEqual(UIntPtr.Zero, result); + } + [Test] public void Target_method_out_ref_parameters() { From ecfff7a1327e0af580b958e7442c8acc1d5b5367 Mon Sep 17 00:00:00 2001 From: stakx Date: Sat, 2 Jan 2021 21:17:05 +0100 Subject: [PATCH 2/3] Add support for `UIntPtr` out / default return values DynamicProxy will now produce the same IL sequences for `UIntPtr` as it already does for `IntPtr`: * For default return values: ldloca.s initobj [mscorlib]System.UIntPtr ldloc. ret * For out parameters: ldarg. initobj [mscorlib]System.UIntPtr (For comparison, the C# compiler wouldn't emit `initobj`, but instead `ldc.i4.0` followed by `conv.i`.) --- .../Generators/Emitters/SimpleAST/DefaultValueExpression.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs index 6476313eb5..bab0c40f59 100644 --- a/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs +++ b/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs @@ -72,7 +72,7 @@ private void EmitByRef(ILGenerator gen) private bool IsPrimitiveOrClass(Type type) { - if ((type.IsPrimitive && type != typeof(IntPtr))) + if (type.IsPrimitive && type != typeof(IntPtr) && type != typeof(UIntPtr)) { return true; } From adcc3dd9c3b0d0879bc066073be7bd9d3c225bac Mon Sep 17 00:00:00 2001 From: stakx Date: Sat, 2 Jan 2021 22:09:39 +0100 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df1a77782..7e5ef208fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Enhancements: - .NET Standard 2.0 and 2.1 support (@lg2de, #485) +Bugfixes: +- `System.UIntPtr` unsupported (@stakx, #546) + Deprecations: - Removed support for the .NET Framework < 4.5 and .NET Standard 1.x. (@stakx, #495, #496) - Removed support for Code Access Security (CAS). (@stakx, #502)