FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix crash when event does not have `Add` method and improve message for some other internal errors by lostmsu · Pull Request #2409 · pythonnet/pythonnet · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (3) .md  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
### Fixed

- Fixed RecursionError for reverse operators on C# operable types from python. See #2240
- Fixed crash when .NET event has no `AddMethod`
- Fixed probing for assemblies in `sys.path` failing when a path in `sys.path` has invalid characters. See #2376

## [3.0.3](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.3) - 2023-10-11
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/ClassManager.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p

internal static bool ShouldBindMethod(MethodBase mb)
{
if (mb is null) throw new ArgumentNullException(nameof(mb));
return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly);
}

internal static bool ShouldBindField(FieldInfo fi)
{
if (fi is null) throw new ArgumentNullException(nameof(fi));
return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly);
}

Expand Down Expand Up @@ -326,7 +328,7 @@ internal static bool ShouldBindProperty(PropertyInfo pi)

internal static bool ShouldBindEvent(EventInfo ei)
{
return ShouldBindMethod(ei.GetAddMethod(true));
return ei.GetAddMethod(true) is { } add && ShouldBindMethod(add);
}

private static ClassInfo GetClassInfo(Type type, ClassBase impl)
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/InternalPythonnetException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Python.Runtime;

public class InternalPythonnetException : Exception
{
public InternalPythonnetException(string message, Exception innerException)
: base(message, innerException) { }
}
31 changes: 19 additions & 12 deletions src/runtime/Types/ReflectedClrType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ public static ReflectedClrType GetOrCreate(Type type)
return pyType;
}

// Ensure, that matching Python type exists first.
// It is required for self-referential classes
// (e.g. with members, that refer to the same class)
pyType = AllocateClass(type);
ClassManager.cache.Add(type, pyType);
try
{
// Ensure, that matching Python type exists first.
// It is required for self-referential classes
// (e.g. with members, that refer to the same class)
pyType = AllocateClass(type);
ClassManager.cache.Add(type, pyType);

var impl = ClassManager.CreateClass(type);
var impl = ClassManager.CreateClass(type);

TypeManager.InitializeClassCore(type, pyType, impl);
TypeManager.InitializeClassCore(type, pyType, impl);

ClassManager.InitClassBase(type, impl, pyType);
ClassManager.InitClassBase(type, impl, pyType);

// Now we force initialize the Python type object to reflect the given
// managed type, filling the Python type slots with thunks that
// point to the managed methods providing the implementation.
TypeManager.InitializeClass(pyType, impl, type);
// Now we force initialize the Python type object to reflect the given
// managed type, filling the Python type slots with thunks that
// point to the managed methods providing the implementation.
TypeManager.InitializeClass(pyType, impl, type);
}
catch (Exception e)
{
throw new InternalPythonnetException($"Failed to create Python type for {type.FullName}", e);
}

return pyType;
}
Expand Down

Back | FazBrowse Home | New Git URL