8000 disabled ability to register encoders for `System.Type` · chubbyerror/pythonnet@957a3cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 957a3cb

Browse files
committed
disabled ability to register encoders for System.Type
Without this restriction encoders created in Python cause stack overflow due to repeated attempts to pass `System.Type` instance to `CanDecode`, which requires encoding the instance of `System.Type`, et. cetera fixes pythonnet#1427
1 parent a157fb4 commit 957a3cb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
4444
- Sign Runtime DLL with a strong name
4545
- Implement loading through `clr_loader` instead of the included `ClrModule`, enables
4646
support for .NET Core
47+
- BREAKING: custom encoders are no longer called for instances of `System.Type`
4748

4849
### Fixed
4950

src/runtime/converter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,11 @@ internal static IntPtr ToPython(object value, Type type)
146146
return result;
147147
}
148148

149-
if (Type.GetTypeCode(type) == TypeCode.Object && value.GetType() != typeof(object)
150-
|| type.IsEnum) {
149+
if (Type.GetTypeCode(type) == TypeCode.Object
150+
&& value.GetType() != typeof(object)
151+
&& value is not Type
152+
|| type.IsEnum
153+
) {
151154
var encoded = PyObjectConversions.TryEncode(value, type);
152155
if (encoded != null) {
153156
result = encoded.Handle;

0 commit comments

Comments
 (0)
0