]> Cypherpunks repositories - gostls13.git/commitdiff
godefs: do not assume forward type references are enums
authorRobert Hencke <robert.hencke@gmail.com>
Tue, 7 Jun 2011 18:28:10 +0000 (14:28 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 7 Jun 2011 18:28:10 +0000 (14:28 -0400)
Fixes #1466.

R=mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/4564043

src/cmd/godefs/a.h
src/cmd/godefs/main.c
src/cmd/godefs/stabs.c
src/pkg/syscall/ztypes_darwin_386.go
src/pkg/syscall/ztypes_darwin_amd64.go

index 03ab91f6599adcf785b8c1fc4fd840851b12ba46..9b495746719aedcad2db577fffd00a164ff6bbb7 100644 (file)
@@ -75,6 +75,7 @@ extern Const *con;
 extern int ncon;
 extern Type **typ;
 extern int ntyp;
+extern int kindsize[];
 
 // Language output
 typedef struct Lang Lang;
index d4163421d1ab9bee51e007e268ba458d0553269c..6a863017951a92f2db77fc47ef74e39fe7991084 100644 (file)
@@ -181,7 +181,7 @@ main(int argc, char **argv)
        char **av, *q, *r, *tofree, *name;
        char nambuf[100];
        Biobuf *bin, *bout;
-       Type *t;
+       Type *t, *tt;
        Field *f;
        int orig_output_fd;
 
@@ -373,8 +373,16 @@ Continue:
                                prefix = prefixlen(t);
                        for(j=0; j<t->nf; j++) {
                                f = &t->f[j];
-                               if(f->type->kind == 0)
-                                       continue;
+                               if(f->type->kind == 0 && f->size <= 64 && (f->size&(f->size-1)) == 0) {
+                                       // unknown type but <= 64 bits and bit size is a power of two.
+                                       // could be enum - make Uint64 and then let it reduce
+                                       tt = emalloc(sizeof *tt);
+                                       *tt = *f->type;
+                                       f->type = tt;
+                                       tt->kind = Uint64;
+                                       while(tt->kind > Uint8 && kindsize[tt->kind] > f->size)
+                                               tt->kind -= 2;
+                               }
                                // padding
                                if(t->kind == Struct || lang == &go) {
                                        if(f->offset%8 != 0 || f->size%8 != 0) {
index 30a05fc700226560db530c7bd336d54ee8442054..2c3d431b8a07ce07cf27d2c8b2612826b32cf351 100644 (file)
@@ -149,7 +149,7 @@ Intrange intranges[] = {
        16, 0, Void,
 };
 
-static int kindsize[] = {
+int kindsize[] = {
        0,
        0,
        8,
@@ -381,14 +381,6 @@ parsedef(char **pp, char *name)
 
                        while(f->type->kind == Typedef)
                                f->type = f->type->type;
-                       if(f->type->kind == 0 && f->size <= 64 && (f->size&(f->size-1)) == 0) {
-                               // unknown type but <= 64 bits and bit size is a power of two.
-                               // could be enum - make Uint64 and then let it reduce
-                               tt = emalloc(sizeof *tt);
-                               *tt = *f->type;
-                               f->type = tt;
-                               tt->kind = Uint64;
-                       }
 
                        // rewrite
                        //      uint32 x : 8;
index 2dec0178731c184cb539fe83e353f049fe3ecede..ba6e590c4f5e6d272b33dbd1ac1111035cf1cad5 100644 (file)
@@ -2,10 +2,6 @@
 
 // MACHINE GENERATED - DO NOT EDIT.
 
-// Manual corrections: TODO: need to fix godefs (issue 1466)
-//     change Msghdr field to Iov *Iovec (was uint32/64)
-//     change BpfProgram field to Insns *BpfInsn (was uint32/64)
-
 package syscall
 
 // Constants
index 96500d73272c6898aaa27afb30a28d71b194083c..59c832812b83f5d0a8f20faf6053c6d55e67c9ed 100644 (file)
@@ -2,10 +2,6 @@
 
 // MACHINE GENERATED - DO NOT EDIT.
 
-// Manual corrections: TODO: need to fix godefs (issue 1466)
-//     change Msghdr field to Iov *Iovec (was uint32/64)
-//     change BpfProgram field to Insns *BpfInsn (was uint32/64)
-
 package syscall
 
 // Constants