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
Next Next commit
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 #1427
  • Loading branch information
lostmsu committed Mar 31, 2021
commit ae3477d63a0a6b6c20974b9a60d8a8fe4e7fd70e
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
- Sign Runtime DLL with a strong name
- Implement loading through `clr_loader` instead of the included `ClrModule`, enables
support for .NET Core
- BREAKING: custom encoders are no longer called for instances of `System.Type`

### Fixed

Expand Down
7 changes: 5 additions & 2 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ internal static IntPtr ToPython(object value, Type type)
return result;
}

if (Type.GetTypeCode(type) == TypeCode.Object && value.GetType() != typeof(object)
|| type.IsEnum) {
if (Type.GetTypeCode(type) == TypeCode.Object
&& value.GetType() != typeof(object)
&& value is not Type
|| type.IsEnum
) {
var encoded = PyObjectConversions.TryEncode(value, type);
if (encoded != null) {
result = encoded.Handle;
Expand Down