Skip to content
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

C long / unsigned long should be 4-byte int instead of 8-byte long / ulong? #1735

Closed
SuRGeoNix opened this issue May 19, 2023 · 4 comments
Closed

Comments

@SuRGeoNix
Copy link

SuRGeoNix commented May 19, 2023

Hi, there is an open issue for FFmpeg.AutoGen bindings here which I think should be handled from CppSharp.

The issue is with C long / unsigned long data types that are converted to C# as long / ulong. At least for Windows systems that I've tested the size it should be 4-bytes instead of 8-bytes.

@tritao
Copy link
Collaborator

tritao commented May 19, 2023

Hey @SuRGeoNix, we get those sizes from Clang using the TargetInfo abstraction:

public static (uint Width, uint Alignment) GetInfo(this PrimitiveType primitive, ParserTargetInfo targetInfo, out bool signed)

We could have a bug but I think its more likely you may be missing a call to setup the correct TargetTriple in ParserOptions, as that's what generally affects those sizes.

To get to the bottom of this, please paste which target triple you are parsing with, and the C line from FFmpeg you are trying to bind, and what CppSharp is outputting. It could be a 32-bit vs. 64-bit setup issue for instance.

@SuRGeoNix
Copy link
Author

SuRGeoNix commented May 19, 2023

Hi @tritao and thanks for the quick reply.

The C input is a struct with a field of 'unsigned long field' and the result is a C# struct with a 'ulong field' in windows 64 system.

Just to clarify I'm just using FFmpeg.AutoGen so I can't really tell you much but what I see is that the nuget is multi platform and it does not specify those as I can see here.
However, I tried to specify TargetTriple to "win64" and I still get the same results.

The thing is that FFmpeg.AutoGen in any case is a single NuGet package for all platforms (with the already generated code) so it might need to split to different platforms? (But still the issue remains when specifying TargetTriple)

@SuRGeoNix
Copy link
Author

SuRGeoNix commented May 19, 2023

Looking a bit deeper into it, I've noticed that FFmpeg.AutoGen uses the ParserOptions.SetupMSVC(VisualStudioVersion.VS2019) which produces this Triple "x86_64-pc-windows-msvc".

In the debug folder I see the LLVM C14 libs/headers which they have (stdint.h/limits.h). When it parses the source files I see that includes (except the clang debug libs/headers) also the MSVC headers (another stdint.h/limits.h). I'm not sure how it does affect CppSharp afterwards. A funny comment in LLVM limits.h : -

/* Many system headers try to "help us out" by defining these.  No really, we
   know how big each datatype is. */
#undef  SCHAR_MIN
#undef  SCHAR_MAX
#undef  UCHAR_MAX
#undef  SHRT_MIN
#undef  SHRT_MAX
#undef  USHRT_MAX
#undef  INT_MIN
#undef  INT_MAX
#undef  UINT_MAX
#undef  LONG_MIN
#undef  LONG_MAX
#undef  ULONG_MAX

(Possible MSVC vs GCC differences?)

@SuRGeoNix
Copy link
Author

Closing this as it can be resolved by CLong / CULong types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants