-
Notifications
You must be signed in to change notification settings - Fork 552
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
Plugged System.Activator.CreateInstance
methods for types with parameterless constructors.
#2997
Conversation
@Guillermo-Santos if it has not already been done could you make a issue for this so we can track it |
} | ||
|
||
// nonPublic is ignored since, at the moment, we cannot know if a ctor is public or not | ||
// and we would get a Stack Corruption or Null reference exception if the ctor is not present either way. |
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 there a way to prevent the Stack Corruption and just throw an exception (we should try and match what .net does whti what exception is thrown)
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.
The problem is, we do not have method info, we do not know what method is a ctor and what method is not (and their parameters) at runtime. To make it all work as intended the Vtable should be reworked.
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.
What i mean for stack corruption or null reference, is that a method other than the ctor was called or for some reason the null check of the ctor throws (happened while testing but should not happend now). This could happend either because there is no parameterless constructor or that ctor is not the address at index 0 (till now, it always have been at index 0, but the possibility of it changing is still there).
Will do |
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.
Great work!
This PR add the plugs for
System.Activator.CreateInstance<T>()
andSystem.Activator.CreateInstance(Type T, bool, bool)
two methods that are used to create generic types.With
System.Activator.CreateInstance<T>()
the following start to work on cosmos:Limitations
To avoid this, you would need to add a
dummy
variable somewhere (BeforeRun
recommended) to make IL2CPU include the ctor on the compilation.ref struct
should not be supported: If the type you are trying to instantiate is aref struct
these methods should throw aNotSupportedException
(as far as I know, is becauseref struct
should never be boxed), but since, at the moment, we cannot check if a type is aref struct
(System.Type.IsByRefLike
field not plugged) we just process theref struct
and return it as a normal struct or class.