-
Notifications
You must be signed in to change notification settings - Fork 18
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
Initial more managed #40
Conversation
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.
Looks more CSharpish and much more concise.
What do you mean?
public readonly int SizeOf; | ||
public readonly int AlignOf; | ||
public readonly int ArraySize; | ||
public readonly struct CSharpType |
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 tab vs spaces thing going on here?
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. I work on Windows and couldn't figure out how to work with analyzers and fix indents.
It is not immediately clear to me what is meant be making the code "more managed". Could you please elaborate? Possibly with an example? |
Yeah. I didn't know what to come up with the name for this difference in behavior, so I used more managed. test.h
test.cs (generated with -mm)
test.cs (generate without -mm)
|
I also recently discovered Microsoft convertor too : ClangSharpPInvokeGenerator
Less lines compared to both of us. |
Between all these 3 I would still choose "more managed" one :D |
The thing about this project, C2CS, is that it was not intended to generate bindings that are necessarily "safe" or standard C#. Rather, the goal was to generate bindings that are exactly to C functions which can be called from C# with little or no overhead including memory allocations. The context is that I created and used C2CS for interoperability with C libraries for real-time applications by specifically avoiding the garbage collector. Now, the project you were previously using for C2CS was probably not real-time, at least not the same class of real-time applications as I was thinking originally. For this type of application, you are okay with string marshalling, array marshalling, and other non-pass through marshalling between C types and C# types that involve the garbage collector. Concern for allocating memory or speed of executing the C functions in these applications is apparently not that much of concern; what appears to be of larger value is easy to use C# API that wraps the native functions from C. Can you confirm this? If this is the case then we can base this as the context for the "user story" ("epic" type in this case). #27 Now there is obviously some low hanging fruit such as using |
It's because the way I programmed the |
You would have two different One alternative for structs would have to be using However the
char *p;
char c;
long x; For 32-bit the layout be like so: char *p; // 4 bytes
char c; // 1 bytes
char pad[3] // padding of 3 bytes
long x; // 4 bytes For 64-bit the layout be like so: char *p; // 8 bytes
char c; // 1 bytes
char pad[7] // padding of 7 bytes
long x; // 8 bytes Now the problem could be mitigated by using Now combine problem 2 and 3 together, and you have a mess. It's not much fun to do manual checking of structs size/alignment by hand. I think it's reasonable though when it's automated. So, to be conservative for the effort of being clear and precise I have all structs use explicit layout. |
Less lines is not always best. This point is moot when a human does not have to write the code manually and when the code is guaranteed to be correct via automation. |
@roozbehid Thanks for the PR and bringing up the discussion. I captured the bulk of the idea in two issues:
|
Initial commit of more managed argument.
I am not expecting this to be merged any time soon.
But overall I think I am good with this version. Looks more CSharpish and much more concise.
I tried to separate the logic of more managed in different files, but I think I broke some parts that were related to
const
in regular mode.