-
Notifications
You must be signed in to change notification settings - Fork 29
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
Make code a bit more NativeAOT friendly #468
Conversation
I update where can - `Marshal.SizeOf(Type)` replaced with `Marshal.SizeOt<T>()` - `Marshal.PtrToStructure(IntrPtr, Type)` replaced with `Marshal.PtrToStructure<T>(IntPtr)` - `Marshal.StructureToPtr(object, IntPtr, bool)` replaced with `Marshal.StructureToPtr<T>(T, IntPtr, bool)` This update change codegeneration piece and commented code, since in case somebody willing to make that code works, I would like that this part would not slip between cracks.
Thank you for your contribution, nice to see some interest from new faces 👍 . The code looks good to me. As I'm currently working on a rewrite of the generator (#437) I think I'm stalling the code a bit until I work next on it so I don't forget to merge your changes directly into the generator3 branch as you did change templates which get replaced in the coming version. |
@badcel I can re-target my changes to that branch if you like. |
@kant2002 thank you but it is not necessary as the template change you did is not yet transfered into the new codebase. |
Hey @badcel, Why do you use IntPtr, Marshal and Assembly for Net 7.0 and greater? 😒👎🤦♂️ Because some C# developers want pack into native executable ( native aot ) Please don't hesitate me! I already uploaded Cairo with I would like to help out with your Gir.Core without Marshal, Assembly and IntPtr. Kind regards |
Hi, I'm open for improvements in regard to AOT. If you plan to contribute please start with very small PRs as I need to understand the direction you want to move. Which feature of dotnet 7 do you mean which makes writing AOT friendly code easier? As far as I'm aware I'm aware that reflection is not very well supported in AOT scenarios. Removing reflection bit by bit is on the roadmap. See #919, #397. |
Yes you can check while you create simple console project for test with Marshal and Assembly. Look what's it going conflict with native aot? Please be careful, if you use Marshal then I cannot publish/deploy as native executable with clang process. I hope you understand me. |
Marshal is not inherently not friendly to AOT. Some methods are, but not whole class. Same for Assembly, but to greater degree. For example NativeAOT provides handling of Assembly.GetExecutingAssembly() I believe proper way to solve issues with NativeAOT is to solve all warnings from trim analyzers |
@kant2002 you can test my repository AppWithPluginForNativeAot or TestLoadingImagesFromAnything they are an example for net 7 or greater. Sorry for only Linux if you add There are my homemade testing examples. |
I opened #975 to track suggestions in regard to native AOT / trimming. So this PR can rest as it was merged long ago. |
I update where can
Marshal.SizeOf(Type)
replaced withMarshal.SizeOt<T>()
Marshal.PtrToStructure(IntrPtr, Type)
replaced withMarshal.PtrToStructure<T>(IntPtr)
Marshal.StructureToPtr(object, IntPtr, bool)
replaced withMarshal.StructureToPtr<T>(T, IntPtr, bool)
This update change codegeneration piece and commented code,
since in case somebody willing to make that code works,
I would like that this part would not slip between cracks.