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
syscall: NewCallback panics when given a callback function with no return type #30070
Comments
/cc @alexbrainman |
@odeke-em I was able to reproduce the issue with Go1.12beta2. |
@MShoaei thanks for the confirmation. I had asked a generic question to help determine the triaging stage.
Anyways, I don't think that this is a bug at all, because syscall.NewCallback documents in go/src/syscall/syscall_windows.go Lines 126 to 127 in 8f85424
which says
It'll panic as you've seen :) Let's close this issue as it is working as intended, but thank you for keeping vigilant and being a part of the Go community @MShoaei! |
@odeke-em Thanks for your reply var a uintptr = 0
var b = nil
a == b |
Yes, that is how syscallback.NewCallback was designed. All callbacks we required in our code had return value.
Yes, I can see WINEVENTPROC callback function returns void. Like I said before, we have never encountered callback function that returned no value. Until now. I am not sure we need to change anything, because return value is returned in AX register for both 386 and amd64, so Windows will just ignore whatever value you will return. Alternatively we could remove syscall.NewCallback panic, when callback return no value. I am not fussed either way. Alex |
@alexbrainman But I guess relying on how Windows will treat our return value and hoping it won't break isn't so convenient, don't you think? |
You won't rely on Windows for anything. Windows will ignore whatever is in AX register when WINEVENTPROC returns. So it does not matter, if your syscall.NewCallback parameter function return value or not.
I disagree. Nearly all callback functions return values. I want my program to panic, if I forget to return value from my callback function. Alex |
@alexbrainman Maybe a little documentation for such situations? 😞 |
I will let others decide what to do here.
No worries. Alex |
Technically speaking, you can't "return void" in C/C++, since all the ABI's that I'm aware of return results in EAX. So even if your function is defined with a void return type, there is still a "return value" in EAX, even if it's utterly undefined as to what it is. It's basically how the Aren't high-level/low-level language interfaces fun? |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
just copy this code, try to run it and it will panic
What did you expect to see?
code compile and execute sucessfully
What did you see instead?
PANIC!
The text was updated successfully, but these errors were encountered: