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
Move native code into posixlib and clib respectively #1885
Conversation
Eric, Thank you for stepping into this swamp and encouraging a healthy ecosystem. Did you find a good decision rule for what should be in posixlib and what in clib. I seem to remember that I could find no clear separation of the two. That is I ran aground because I did not want to duplicate implementations and could not find a way I think the same chaotic boundary exists in the .rst documentation. It would be nice to have (read: IMHO, essential) to have a clearly stated That is, which library is more primitive and can the less primitive be implemented in terms Pardon me if such exists and I missed it or was not clever enough to suss it out. |
I believe there are at least 4 PRs in the queue which reference posixlib and which might Not to hold up the base PR, but I think it would ease the overall effort if those earlier PRs |
There are basically three parts to the situation.
It can be very confusing as looking back and forth between the specs and the code and between the C and POSIX specs can get dizzying but it can be separated as far as I know. If we move the code to the |
@sjrd and others. Do we want the We would need to |
I concur that sorts based on experience gained and current knowledge & directions is the way to go. |
beddb43
to
412d6e6
Compare
412d6e6
to
e672a80
Compare
@sjrd Do you think we could add this PR and a follow on for The dependency chain currently The small dependency between |
I changed this to draft to address |
af133fe
to
bbfdba0
Compare
This now contains potential breaking changes to downstream applications.
Overall, we want to strive for correctness so I see no way around this as macro defs can only be in defined one place so deprecation is not possible. C is a flat name space. |
TODO - determine what should be in [X] Determine package for SocketHelpers, maybe My recommendation is that this gets moved to [X] Do we want This should be determined by future PRs because how we segregate and organize code is a bigger issue and everything related to Overall, as a rule, as long as the runtime does not depend on the code then the code should not be in
|
96bbd88
to
537350b
Compare
#define MICROS_PER_MILLI 1000LL | ||
|
||
struct timeval tv; | ||
gettimeofday(&tv, NULL); |
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.
I created issue #1948 to report that the error code for gettimeofday() is never checked.
I am not suggesting a change for this PR, just wanted to note that it had been detected.
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.
Good idea. An error in C is like an error of death.
@@ -0,0 +1,11 @@ | |||
#include <errno.h> | |||
|
|||
int scalanative_errno() { return errno; } |
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.
float.c and math.c below seem to use the scalanative_libc_ prefix. That seems to be a useful convention. If not relevant here, to keep changes to a minimum, perhaps in a spin-off PR?
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.
I think the scalanative
prefix is good and we may need a libc
too but this obviously is not totally agreed upon territory.
@@ -41,13 +41,13 @@ class File(_path: String) extends Serializable with Comparable[File] { | |||
} | |||
|
|||
def canExecute(): Boolean = | |||
Zone { implicit z => access(toCString(path), fcntl.X_OK) == 0 } | |||
Zone { implicit z => access(toCString(path), unistd.X_OK) == 0 } |
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.
The change from fcntl.mumble to unistd.mumble in a number of places is a long overdue correction. Thank you!
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.
I fixed everything I saw that was just wrong especially if I had to because of a dependency.
// get the values out of those in a portable manner. | ||
|
||
// Omitting EDOM EILSEQ and ERANGE since they are duplicated in wrap.c | ||
// Omitting EDOM EILSEQ and ERANGE since they are in clib |
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.
I think that the comment and omission was (questionably) appropriate when the code was in nativelib but I believe it is wrong now. To my thinking, either you are posix complete (where that is another discussion altogether) or you are not. Those three are defined in posix, why make someone hare off to clib? Perhaps there could be defined
here as a call to the required clib version rather than duplicating code?
At the very least, I think this is worth a spin-off issue, to be corrected in detail and not hold up the overall PR.
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.
I did not duplicate but if they have to be one place then they should be in clib
. For certain clib
should be complete but how we handle the overlap with POSIX in unanswered at this time.
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.
This too was just moving things around to get them in the logical place. The code basically has a C file that is named the same as the Scala file except the extension when macros are needed. We didn't always early on have a plan - stuff was thrown wherever.
@@ -1,6 +1,8 @@ | |||
#ifndef __TYPES_H | |||
#define __TYPES_H | |||
|
|||
// types used in pwd.c and sys/stat.c |
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.
OK, why? I know the answer but that is surely the question that a new reader will ask.
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.
I put that there so the reader could know it is used only. Edit: also I am hoping we can have named struct members so we can avoid most of this additional code.
@@ -9,6 +13,16 @@ int scalanative_w_ok() { return W_OK; } | |||
|
|||
int scalanative_x_ok() { return X_OK; } | |||
|
|||
// SEEK_CUR, SEEK_END, SEEK_SET in clib stdio |
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.
Again, IMO, those three should be defined here, probably as calls to the clib version.
Independent duplication is also possible, if you/we want to avoid a dependency of posixlib on clib.
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.
There is not specific dependency but I get the point - some of this discussed later.
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.
I looked at this and they were suppose to be in POSIX stdio.scala
or stdio.c
and there isn't one at all so this was the minimal fix that was actually correct.
@@ -1,6 +1,10 @@ | |||
#include <unistd.h> | |||
#include "types.h" | |||
|
|||
extern char **environ; |
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.
I did not check this file against the posix standard, but it looks better than what it
replaces.
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.
Yes, this is better.
Signed-off-by: ekrich <ekrichardson@gmail.com>
…iles Add some missing macro constants
537350b
to
7be6f0f
Compare
…ative#1885)" This reverts commit 39ef208.
…ative#1885)" This reverts commit 39ef208.
The overall goal here is to move the C code into the corresponding library. We want to consider supporting Windows so allowing POSIX to be only available on UNIX like platforms makes sense.
This is just a first cut. We need to add
pthread.c
and a little more possibly that does not belong in thenativelib
. Also, this will need to be repeated forclib
. Most of the POSIX code has axxx.scala
file and a correspondingxxx.c
file.clib
was coded earlier before better conventions came along.There is a question whether
posixlib
and thenativelib
shouldexportJars := true
in sbt. Removing this will still work fine and maybe build a little faster but to use theSNAPSHOT
locally,publishLocal
would have to be run. Let me know what you think about this.