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

godefs makes EPOLLET constant negative #835

Closed
alberts opened this issue Jun 4, 2010 · 3 comments
Closed

godefs makes EPOLLET constant negative #835

alberts opened this issue Jun 4, 2010 · 3 comments
Assignees

Comments

@alberts
Copy link
Contributor

@alberts alberts commented Jun 4, 2010

issue #832 was closed as WorkingAsIntended so I guess this means the problem 
is more of a godefs issue.

What steps will reproduce the problem?

This code:

var epevent syscall.EpollEvent  
epevent.Events |= syscall.EPOLLET

fails to compile:

constant -2147483648 overflows uint32

This is happening because godefs is making EPOLLET a negative value.

If I manually change the generated code so that EPOLLET is positive, it can 
be used in the bitwise-or operation, but then this code:

fmt.Printf("%v\n", syscall.EPOLLET);

fails to compile with:

constant 2147483648 overflows int

What is your $GOOS?  $GOARCH?

GOARCH="amd64"
GOOS="linux"

Which revision are you using?  (hg identify)

e712aba3277f+ tip
@adg
Copy link
Contributor

@adg adg commented Jun 25, 2010

Comment 1:

If this is an issue with godefs, the following change:
diff -r 1c0adc2fd1d7 src/cmd/godefs/main.c
--- a/src/cmd/godefs/main.c Wed Jun 23 15:27:51 2010 +0100
+++ b/src/cmd/godefs/main.c Fri Jun 25 12:26:32 2010 +0100
@@ -295,12 +295,7 @@
    if(ncon > 0) {
        Bprint(bout, lang->constbegin);
        for(i=0; i<ncon; i++) {
-           // Go can handle negative constants,
-           // but C enums may not be able to.
-           if(lang == &go)
-               Bprint(bout, lang->constfmt, con[i].name, con[i].value);
-           else
-               Bprint(bout, lang->constfmt, con[i].name, con[i].value & 0xFFFFFFFF);
+           Bprint(bout, lang->constfmt, con[i].name, con[i].value & 0xFFFFFFFF);
        }
        Bprint(bout, lang->constend);
    }
Changes this:
adg:~/go/src/pkg/syscall$ ./mkerrors.sh | grep EPOLLET
        EPOLLET = -0x80000000;
to this:
adg:~/go/src/pkg/syscall$ ./mkerrors.sh | grep EPOLLET
        EPOLLET = 0x80000000;
This would appear to fix the problem (please confirm), but I'm not sure if this would
introduce other issues.
Russ?

Owner changed to r...@golang.org.

@rsc
Copy link
Contributor

@rsc rsc commented Oct 11, 2010

Comment 2:

If you dig through the history here we've gone back
and forth a few times.  There are some negative
constants (like -1) that make more sense as -1 
than as 0xffffffff (which assumes 32-bit uses,
among other things).  It's not really clear what to do here.
The problem is C being imprecise and not being able
to translate that easily into Go.

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Nov 11, 2011

Comment 3:

This issue was closed by revision 879a1c6.

Status changed to Fixed.

@alberts alberts added fixed labels Nov 11, 2011
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.