diff mbox

Go patch committed: Implement new syscall package

Message ID mcrvcrb3ucs.fsf@dhcp-172-18-216-180.mtv.corp.google.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 27, 2011, 4:56 a.m. UTC
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> the problem is another one: using /usr/xpg4/bin/awk, I find:
>
> /usr/xpg4/bin/awk: line 47 (NR=32): wrong number of arguments to function "m"
>
> nawk(1) only documents match(s,ere) (i.e. two args), and the gawk docs
> state:
>
> `match(STRING, REGEXP [, ARRAY])'
> [...]
>      The ARRAY argument to `match' is a `gawk' extension.  In
>      compatibility mode (*note Options::), using a third argument is a
>      fatal error.

I committed this patch which should fix this problem.  Bootstrapped and
ran Go testsuite on x86_64-unknown-linux-gnu.

Ian

Comments

Rainer Orth Oct. 27, 2011, 11:07 a.m. UTC | #1
Ian,

> I committed this patch which should fix this problem.  Bootstrapped and
> ran Go testsuite on x86_64-unknown-linux-gnu.

thanks, but this is not enough:

nawk: syntax error at source line 173
 context is
         ([^ >>>  ]*)$", <<<  cparam) == 0) {
nawk: illegal statement at source line 173
nawk: syntax error at source line 179

and there is another instance on l.210.  I haven't tried fixing this
myself since I'm fighting with other issues.

	Rainer
Rainer Orth Oct. 28, 2011, 4:59 p.m. UTC | #2
Ian,

>> I committed this patch which should fix this problem.  Bootstrapped and
>> ran Go testsuite on x86_64-unknown-linux-gnu.
>
> thanks, but this is not enough:
>
> nawk: syntax error at source line 173
>  context is
>          ([^ >>>  ]*)$", <<<  cparam) == 0) {
> nawk: illegal statement at source line 173
> nawk: syntax error at source line 179
>
> and there is another instance on l.210.  I haven't tried fixing this
> myself since I'm fighting with other issues.

even if I work around this by installing gawk 4.0.0 on Solaris 8/9, I
run into another issue:

/vol/gcc/src/hg/trunk/local/libgo/go/syscall/errstr_nor.go:22:8: error: referenc
e to undefined name 'libc_strerror'
make[4]: *** [syscall/syscall.lo] Error 1

Replacing libc_strerror (which doesn't exist anywhere) by strerror isn't
enough, though:

/vol/gcc/src/hg/trunk/local/libgo/go/syscall/errstr_nor.go:22:2: error: variable has no type
/vol/gcc/src/hg/trunk/local/libgo/go/syscall/errstr_nor.go:22:2: error: incompatible type in initialization (non-value used as value)
make[2]: *** [syscall/syscall.lo] Error 1

I couldn't figure out what's wrong here; I'll need considerable more
time with the Go tutorial etc.

	Rainer
diff mbox

Patch

diff -r 5f4f4eae5cd9 libgo/go/syscall/mksyscall.awk
--- a/libgo/go/syscall/mksyscall.awk	Wed Oct 26 16:19:57 2011 -0700
+++ b/libgo/go/syscall/mksyscall.awk	Wed Oct 26 21:53:05 2011 -0700
@@ -44,33 +44,63 @@ 
 	blocking = 1
     }
 
-    if (match($0, "//sys(nb)?[ 	]*([a-zA-Z0-9_]+)\\(([^()]*)\\) *(\\(([^()]+)\\))?", gosig) == 0) {
+    line = $0
+
+    if (match(line, "//sys(nb)?[ 	]*[a-zA-Z0-9_]+\\([^()]*\\) *(\\(([^()]+)\\))?") == 0) {
 	print "unmatched line:", $0 | "cat 1>&2"
 	status = 1
 	next
     }
 
-    gofnname = gosig[2]
-    gofnparams = gosig[3]
-    gofnresults = gosig[5]
+    # Sets a[1] = //sysnb, a[2] == function name.
+    split(line, a, "[ 	(]*")
+    gofnname = a[2]
+
+    off = match(line, "\\([^()]*\\)")
+    end = index(substr(line, off, length(line) - off + 1), ")")
+    gofnparams = substr(line, off + 1, end - 2)
+
+    line = substr(line, off + end, length(line) - (off + end) + 1)
+    off = match(line, "\\([^()]*\\)")
+    if (off == 0) {
+	gofnresults = ""
+    } else {
+	end = index(substr(line, off, length(line) - off + 1), ")")
+	gofnresults = substr(line, off + 1, end - 2)
+    }
 
     getline
+    line = $0
 
-    if (match($0, "//([a-zA-Z0-9_]+)\\(([^()]*)\\) *(.*)$", csig) == 0) {
+    if (match(line, "//[a-zA-Z0-9_]+\\([^()]*\\)") == 0) {
 	print "unmatched C line", $0, "after", gofnname | "cat 1>&2"
 	status = 1
 	next
     }
 
-    cfnname = csig[1]
-    cfnparams = csig[2]
-    cfnresult = csig[3]
+    split(line, a, "[ 	(]*")
+    cfnname = substr(a[1], 3, length(a[1]) - 2)
+
+    off = match(line, "\\([^()]*\\)")
+    end = index(substr(line, off, length(line) - off + 1), ")")
+    cfnparams = substr(line, off + 1, end - 2)
+
+    line = substr(line, off + end + 1, length(line) - (off + end) + 1)
+    while (substr(line, 1, 1) == " ") {
+	line = substr(line, 2, length(line) - 1)
+    }
+    end = index(line, " ")
+    if (end != 0) {
+	line = substr(line, 1, end)
+    }
+    cfnresult = line
 
     printf("// Automatically generated wrapper for %s/%s\n", gofnname, cfnname)
     printf("func c_%s(%s) %s%s__asm__(\"%s\")\n",
 	   cfnname, cfnparams, cfnresult, cfnresult == "" ? "" : " ", cfnname)
-    printf("func %s(%s) %s%s{\n",
-	   gofnname, gofnparams, gosig[4], gosig[4] == "" ? "" : " ")
+    printf("func %s(%s) %s%s%s%s{\n",
+	   gofnname, gofnparams, gofnresults == "" ? "" : "(", gofnresults,
+	   gofnresults == "" ? "" : ")", gofnresults == "" ? "" : " ")
 
     if (blocking) {
 	print "\tentersyscall()"
@@ -91,22 +121,22 @@ 
 	    args = args ", "
 	}
 
-	if (match(goargs[goarg], "^([^ ]*) ([^ ]*)$", goparam) == 0) {
+	if (split(goargs[goarg], a) != 2) {
 	    print loc, "bad parameter:", goargs[goarg] | "cat 1>&2"
 	    status = 1
 	    next
 	}
 
-	goname = goparam[1]
-	gotype = goparam[2]
+	goname = a[1]
+	gotype = a[2]
 
-	if (match(cargs[carg], "^([^ ]*) ([^ ]*)$", cparam) == 0) {
+	if (split(cargs[carg], a) != 2) {
 	    print loc, "bad C parameter:", cargs[carg] | "cat 1>&2"
 	    status = 1
 	    next
 	}
 
-	ctype = cparam[2]
+	ctype = a[2]
 
 	if (gotype ~ /^\*/) {
 	    if (gotype != ctype) {