mirror of https://github.com/golang/go.git
cmd/cgo, misc/cgo/test: make -Wdeclaration-after-statement clean
I got a complaint that cgo output triggers warnings with -Wdeclaration-after-statement. I don't think it's worth testing for this--C has permitted declarations after statements since C99--but it is easy enough to fix. It may break again; so it goes. This CL also fixes errno handling to avoid getting confused if the tsan functions happen to change the global errno variable. Change-Id: I0ec7c63a6be5653ef44799d134c8d27cb5efa441 Reviewed-on: https://go-review.googlesource.com/22686 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
45f39fb467
commit
e50346d26a
|
|
@ -13,9 +13,9 @@ package cgotest
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static void *thread(void *p) {
|
static void *thread(void *p) {
|
||||||
(void)p;
|
|
||||||
const int M = 100;
|
const int M = 100;
|
||||||
int i;
|
int i;
|
||||||
|
(void)p;
|
||||||
for (i = 0; i < M; i++) {
|
for (i = 0; i < M; i++) {
|
||||||
pthread_kill(pthread_self(), SIGCHLD);
|
pthread_kill(pthread_self(), SIGCHLD);
|
||||||
usleep(rand() % 20 + 5);
|
usleep(rand() % 20 + 5);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ static void output5986()
|
||||||
{
|
{
|
||||||
int current_row = 0, row_count = 0;
|
int current_row = 0, row_count = 0;
|
||||||
double sum_squares = 0;
|
double sum_squares = 0;
|
||||||
|
double d;
|
||||||
do {
|
do {
|
||||||
if (current_row == 10) {
|
if (current_row == 10) {
|
||||||
current_row = 0;
|
current_row = 0;
|
||||||
|
|
@ -20,7 +21,7 @@ static void output5986()
|
||||||
++row_count;
|
++row_count;
|
||||||
}
|
}
|
||||||
while (current_row++ != 1);
|
while (current_row++ != 1);
|
||||||
double d = sqrt(sum_squares / row_count);
|
d = sqrt(sum_squares / row_count);
|
||||||
printf("sqrt is: %g\n", d);
|
printf("sqrt is: %g\n", d);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||||
fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle)
|
fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle)
|
||||||
fmt.Fprintf(fgcc, "{\n")
|
fmt.Fprintf(fgcc, "{\n")
|
||||||
if n.AddError {
|
if n.AddError {
|
||||||
fmt.Fprintf(fgcc, "\terrno = 0;\n")
|
fmt.Fprintf(fgcc, "\tint _cgo_errno;\n")
|
||||||
}
|
}
|
||||||
// We're trying to write a gcc struct that matches gc's layout.
|
// We're trying to write a gcc struct that matches gc's layout.
|
||||||
// Use packed attribute to force no padding in this struct in case
|
// Use packed attribute to force no padding in this struct in case
|
||||||
|
|
@ -578,11 +578,18 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||||
// Save the stack top for use below.
|
// Save the stack top for use below.
|
||||||
fmt.Fprintf(fgcc, "\tchar *stktop = _cgo_topofstack();\n")
|
fmt.Fprintf(fgcc, "\tchar *stktop = _cgo_topofstack();\n")
|
||||||
}
|
}
|
||||||
|
tr := n.FuncType.Result
|
||||||
|
if tr != nil {
|
||||||
|
fmt.Fprintf(fgcc, "\t__typeof__(a->r) r;\n")
|
||||||
|
}
|
||||||
fmt.Fprintf(fgcc, "\t_cgo_tsan_acquire();\n")
|
fmt.Fprintf(fgcc, "\t_cgo_tsan_acquire();\n")
|
||||||
|
if n.AddError {
|
||||||
|
fmt.Fprintf(fgcc, "\terrno = 0;\n")
|
||||||
|
}
|
||||||
fmt.Fprintf(fgcc, "\t")
|
fmt.Fprintf(fgcc, "\t")
|
||||||
if t := n.FuncType.Result; t != nil {
|
if tr != nil {
|
||||||
fmt.Fprintf(fgcc, "__typeof__(a->r) r = ")
|
fmt.Fprintf(fgcc, "r = ")
|
||||||
if c := t.C.String(); c[len(c)-1] == '*' {
|
if c := tr.C.String(); c[len(c)-1] == '*' {
|
||||||
fmt.Fprint(fgcc, "(__typeof__(a->r)) ")
|
fmt.Fprint(fgcc, "(__typeof__(a->r)) ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -604,6 +611,9 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||||
fmt.Fprintf(fgcc, "a->p%d", i)
|
fmt.Fprintf(fgcc, "a->p%d", i)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fgcc, ");\n")
|
fmt.Fprintf(fgcc, ");\n")
|
||||||
|
if n.AddError {
|
||||||
|
fmt.Fprintf(fgcc, "\t_cgo_errno = errno;\n")
|
||||||
|
}
|
||||||
fmt.Fprintf(fgcc, "\t_cgo_tsan_release();\n")
|
fmt.Fprintf(fgcc, "\t_cgo_tsan_release();\n")
|
||||||
if n.FuncType.Result != nil {
|
if n.FuncType.Result != nil {
|
||||||
// The cgo call may have caused a stack copy (via a callback).
|
// The cgo call may have caused a stack copy (via a callback).
|
||||||
|
|
@ -613,7 +623,7 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
|
||||||
fmt.Fprintf(fgcc, "\ta->r = r;\n")
|
fmt.Fprintf(fgcc, "\ta->r = r;\n")
|
||||||
}
|
}
|
||||||
if n.AddError {
|
if n.AddError {
|
||||||
fmt.Fprintf(fgcc, "\treturn errno;\n")
|
fmt.Fprintf(fgcc, "\treturn _cgo_errno;\n")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fgcc, "}\n")
|
fmt.Fprintf(fgcc, "}\n")
|
||||||
fmt.Fprintf(fgcc, "\n")
|
fmt.Fprintf(fgcc, "\n")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue