-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Undefined behavior? Marshalling native non-PODs yield different results depending on their size #2357
Comments
This should likely be filed on dotnet/coreclr since it looks like a runtime question rather than a language issue. |
@tannergooding oh hey there 😃. |
Interop is not a function of the language but a function of the runtime. The runtime team in dotnet/coreclr should be better suited at answering your interop related questions (and it is likely worthwhile to continue the discussion there rather than causing noise here in csharplang). There are a lot of things that come into play for interop including the target calling convention, what platform you are running against, various attributes, etc. Almost all the documentation for this can be found under: https://docs.microsoft.com/en-us/dotnet/framework/interop/ |
OK. Thank you. |
Hello there.
I was marshaling some data from C++ and I came across a strange inconsistent behavior, here's a repro project:
https://github.com/Alan-FGR/PinvokeDebug
here's the native code:
https://github.com/Alan-FGR/PinvokeDebug/blob/c63b8e1b310ab6ad0316e1044580789aa7348b2f/Dll/Dll.cpp#L9-L44
here's the C# code:
https://github.com/Alan-FGR/PinvokeDebug/blob/c63b8e1b310ab6ad0316e1044580789aa7348b2f/PinvokeProblemDebug/Program.cs#L8-L46
(github should be displaying the lines here, that isn't working on my end though)
Note how the only difference is that single extra float. The version with 3 floats works fine, with 2 it doesn't, but if I cast it into a POD it works fine.
Is marshaling non-PODs undefined behavior or something? I can see why that doesn't work since the destructor is called when exiting the scope, but what I don't understand is the inconsistency there.
I couldn't find anything regarding that behavior. I don't really understand why that varies according to data size and I think that should be at least documented.
Thank you in advance.
The text was updated successfully, but these errors were encountered: