-
Notifications
You must be signed in to change notification settings - Fork 361
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
Hide/deal with posix.sys.stat as it's not binary compatible with POSIX standard #3902
Comments
The code should match the spec for sure. In general, there are problems with structs because we do not have named structs and posix does not specify the order so there can be OS dependent ordering and alignment - @LeeTibbert has talked extensively about this - sure you are aware. We started by having native adapters to use names in the C as we know the order/size of elements in the Scala but Lee didn't like the copying so then I sort of lost what the state of the art is. I think longer term we need the |
keynmol. Sorry that these "features" took you time. Some of them long pre-date me and we have been "binary compatible with POSIX Standard" is not a real thing. Reasonably recent Open Group One can do at least two things
I think the bottom line is that one must be exceedingly careful when passing a Scala Native My goal is to be helpful. Please suggest any ways forward. A number of us have been trying |
Personal opinion. I believe that fixing up operating system differences should be kept out of the mainline compiler, Yes, posixlib is of finite size and yes the number of operating systems Scala Native supports is of finite There are probably more people who either have the expertise to write and evaluate "glue" code or who can be Agreed, "glue" code is ugly and expensive at runtime. In a number of cases we have been able to change it to It would be wonderful to never have to read or write "glue" code but that wonder may preclude greater wonders, |
Re: Bookkeeping I recommend that this Issue stay open for a week to allow comments and then be closed as "economically untractable". |
I've just noticed that stat structure in posix seems to be incorrect: https://github.com/scala-native/scala-native/blob/main/posixlib/src/main/scala/scala/scalanative/posix/sys/stat.scala#L45-L60
It doesn't match the layout in posix docs: https://www.man7.org/linux/man-pages/man3/stat.3type.html
And there seems to be special handling: https://github.com/scala-native/scala-native/blob/main/posixlib/src/main/resources/scala-native/sys/stat.c#L7-L36
Seems like it's making this stat structure indeed not useful for passing to any extern function that actually expects stat.
I stumbled on it because of cryptic errors, caused by passing a function pointer (implemented in Scala) to a C library, which invokes it with actual POSIX
stat*
, expecting mutation in place.That mutation corrupts the result because of incorrect alignment and sizes and all hell breaks loose.
The text was updated successfully, but these errors were encountered: