-
-
Notifications
You must be signed in to change notification settings - Fork 303
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
Allow to be built with CGO_ENABLE=0 #345
Conversation
Signed-off-by: xchenan <xchenan@gmail.com>
1665a79
to
a4dddc9
Compare
Hi, thanks for the PR. I am pretty busy ATM and will try to get to you this weekend. |
First of all, thank you for doing this! We are using sqlite which also requires cgo, but it's good to get rid of cgo for the rest of the code. Read below for comments.
|
9a5d5a4
to
7d432ae
Compare
…d issues on MacOS Signed-off-by: xchenan <xchenan@gmail.com>
7d432ae
to
18041b0
Compare
@xiaq Just a kind reminder that the PR works for both linux and macOS now. |
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.
Sorry for the delay, and thanks again.
Overall the PR is in a good shape; see comments.
sys/select_bsd.go
Outdated
@@ -4,6 +4,13 @@ package sys | |||
|
|||
import "syscall" | |||
|
|||
const NFDBits = 32 |
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 hardcoding seems unnecessary. Please use unsafe.Sizeof to find out the size. You wouldn't need to split select_bsd.go and select_linux.go either.
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.
On MacOS, FdSet.Bits is []int32 whereas on linux FdSet.Bits is []int64. Therefore IMHO the return type of func index() shall be different based on the types of FdSet.Bits on different OS. Is there an alternative to solve this without splitting the code?
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 overlooked the difficulty here. Let's leave it separated.
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.
unsafe.Sizeof(u) returns 8 on both Linux and MacOS. But NFDBits needs to be 64 on Linux and 32 on MacOS. Since we have to separate the impl anyway I just left NFDBits hard-coded.
sys/termios_bsd.go
Outdated
TCIOFF = 3 | ||
TCION = 4 | ||
) | ||
|
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.
Only consonants in the const block below and setFlag are used.
Please stripe the file and (termios_linux.go) to include only these consonants (see setFlag for why it should also be removed). Since these codes are forked instead of vendored, developers of Elvish will be maintaining these code, and we should maintain as little code as possible. :)
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.
Done.
sys/termios_bsd.go
Outdated
// } | ||
//} | ||
|
||
func setFlag(flag *uint64, mask uint64, v bool) { |
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 seems to unnecessarily rely on the actual type of term.LFlag.
If you inline the function manually, Go's type inference will do the correct thing.
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 problem of inlining the function is that, we are not able to negate constants (unix.ICANON and unix.ECHO) in Go. A possible way of doing this is to valuate a variable with value of the constant, then use the variable instead. However the types of such variable needs to be defined differently on MacOS and Linux. I suppose a better way of doing this is to define setFlag() separately for different OS.
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.
You are right. Let's leave this one separated too.
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 just left them separated.
sys/winsize.go
Outdated
|
||
// GetWinsize queries the size of the terminal referenced by the given file | ||
// descriptor. | ||
// | ||
type winSize struct { |
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.
Please move this struct above GetWinsize's docstring.
Also, this is one of the few places where we have to rely on the size of the fields. Please include a comment like this:
// winSize mirrors struct winsize in the C header. The following declaration matches struct winsize in the headers of Linux and FreeBSD.
(I've verified that.)
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.
Done.
sys/errors.go
Outdated
@@ -0,0 +1,8 @@ | |||
package sys |
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.
Please remove this file. ErrNotImplemented is not used, and ErrInvalidAction will not be used if you remove other unused code (see below).
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.
Done.
Also, please remove your vim swap file from the 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 have some concerns on your kind suggestions. I may need further clarification.
sys/select_bsd.go
Outdated
@@ -4,6 +4,13 @@ package sys | |||
|
|||
import "syscall" | |||
|
|||
const NFDBits = 32 |
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.
On MacOS, FdSet.Bits is []int32 whereas on linux FdSet.Bits is []int64. Therefore IMHO the return type of func index() shall be different based on the types of FdSet.Bits on different OS. Is there an alternative to solve this without splitting the code?
sys/termios_bsd.go
Outdated
// } | ||
//} | ||
|
||
func setFlag(flag *uint64, mask uint64, v bool) { |
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 problem of inlining the function is that, we are not able to negate constants (unix.ICANON and unix.ECHO) in Go. A possible way of doing this is to valuate a variable with value of the constant, then use the variable instead. However the types of such variable needs to be defined differently on MacOS and Linux. I suppose a better way of doing this is to define setFlag() separately for different OS.
I left comments, in case GitHub didn't send an email. You are right in the two comments, I overlooked the problems. |
6835461
to
83b84c1
Compare
…in termios_linux.go and termios_bsd.go; Signed-off-by: xchenan <xchenan@gmail.com>
83b84c1
to
519b7e5
Compare
@xiaq I fixed the code based on your comments. Hopefully good to go now. |
The story of NFDBits is more complex than I thought. Linux doesn't always have 64-bit Bits arrays in FdSet; nor does BSDs have 32-bit ones. In your I think the solution would be that for this function, you need to have two files, For you convenience, among the arch/kernel combinations that I care about now, the following have 32-bit Bits:
The following have 64-bit Bits:
In those two files you can hardcode NFDBits. Please also leave comments in those two files explaining the reason we are doing this. |
sys/winsize.go
Outdated
type winSize struct { | ||
row uint16 | ||
col uint16 | ||
Xpixel uint16 | ||
Ypixel uint16 | ||
} | ||
|
||
// GetWinsize queries the size of the terminal referenced by | ||
// the given file descriptor. | ||
|
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.
Remove this blank line, that is how Go docstrings should be.
sys/select_32.go
Outdated
@@ -1,4 +1,4 @@ | |||
// +build darwin dragonfly freebsd netbsd openbsd | |||
// +build darwin 386,freebsd arm,freebsd 386,linux arm,linux netbsd openbsd |
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.
You need both select_{bsd,linux}.go and select_{32,64}.go. The first pair is due to the fact that Select has different signatures on BSD and Linux.
Remember to remove your vim swap file. |
different architectures. Signed-off-by: xchenan <xchenan@gmail.com>
7f685c0
to
0b87620
Compare
Sorry about the back and forth. Please let me know if there's more I need to modify. |
Aargh... The implementation of Apparently, for what we care about, only I'll merge your PR though, the process is taking longer than I like and I will fix that in a later commit. |
And thanks again for doing this! |
Appreciations. I am truly glad for all the kind comments and, of course, the approval. |
Re-implemented the parts that included codes in C. Now the projects should be in pure golang.
The re-implementation of termios refers to go-termios: https://github.com/go-termios/termios.