-
Notifications
You must be signed in to change notification settings - Fork 10
Last line of defense, best effort serialization #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
there are only a few errors left in runtime.cs, but plenty outside of it
…ss-domain context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome.
Should we backport to the 3.0 alpha tag as well?
[System.Serializable] | ||
public sealed class NotSerializedException: SerializationException | ||
{ | ||
static string _message = "The underlying C# object has been deleted."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even the right message? This is a twisted joke I made to trigger PTSD of all the poor souls who had to work with PyQT/PySide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a perfect message.
|
||
private static void CreateMethod(TypeBuilder tb, MethodInfo minfo) | ||
{ | ||
Console.WriteLine($"overimplementing method for: {minfo} {minfo.IsVirtual} {minfo.IsFinal} "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably meant to remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
|
||
MaybeType type = obj.GetType(); | ||
|
||
var hasAttr = (from attr in obj.GetType().CustomAttributes select attr.AttributeType == typeof(PyNet_NotSerializedAttribute)).Count() != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe type.CustomAttributes.Any(attr => attr.AttributeType == typeof(...))
?
I don't know the fancy way to write it, but you don't need to count it, you can stop at the first.
(And you already got obj.GetType())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's better
if (hasAttr) | ||
{ | ||
// Don't serialize a _NotSerialized. Serialize the base type, and deserialize as a _NotSerialized | ||
type = type.Value.BaseType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it we know that a NotSerialized always derives from a serializable object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it always derives from a non-serializable object. That's why we end up here. We don't serialize the object; only it's type so we can re-create it in the next domain.
object nameObj = null!; | ||
try | ||
{ | ||
nameObj = info.GetValue($"notSerialized_tp", typeof(object)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to interpolate this string, there's no fields inside
} | ||
else | ||
{ | ||
selector = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both branches do it so you could do it before the if/else
Considering that RC.1 has been declared the other day, I'll have to take a look to see if we can use it instead of the alpha |
fixed unhandled Python errors during comparison attempts fixes pythonnet#1848
Additionally, fixes a type hint and makes sure that the new default behaviour is to use the environment variable if given.
- Only include src/runtime, no other .NET subproject - In particular, tests are not contained anymore in the sdist - Fix accidentally including obj and bin directories in the sdist
* Add unit tests for (U)IntPtr conversions * Special-case construction of (U)IntPtr * Check (U)IntPtr size explicitly
…e now callable from Python
Fixed a leak in `NewReference.Move`
…onnet#1878) also fixed issues with xml docs in the code implements pythonnet#1876
This commit adds a "last line of defense, best effort serialization" to serialize types not marked as Serializable. Such objects are deserialized as derived classes with all methods and properties overriden to throw a "Not Serialized" Exception. Fields are not initialized and may be null. Sealed classes and implemented interface methods are still a problem to be solved.
plus guard rails for private classes and review fixes
don't try to derive from sealed types
Allows the project to be referenced in other .NET projects without adjusting its project file (pythonnet#1853).
There are small typos in: - pythonnet/__init__.py - tests/test_import.py Fixes: - Should read `splitted` rather than `splited`. - Should read `loaded` rather than `laoded`. Signed-off-by: Tim Gates <[email protected]>
6a88bd5
to
7ffad42
Compare
latest clr_loader version breaks the python tests otherwise
What does this implement/fix? Explain your changes.
This commit adds a "last line of defense, best effort serialization"
to serialize types not marked as Serializable. Such objects are
deserialized as derived classes with all methods and properties
overriden to throw a "Not Serialized" Exception.
Fields are not initialized and may be null.
Private classes and other non-inheritable instances are set to null on deserialization
Does this close any currently open issues?
...
Any other comments?
...
Checklist
Check all those that are applicable and complete.
AUTHORS
CHANGELOG