mirror of
https://github.com/golang/go
synced 2024-11-15 02:50:31 -07:00
7061dc3f6e
The top-level qualifiers are unimportant for our purposes. If a C function is defined as `const int f(const int i)`, the `const`s are meaningless to C, and we want to avoid using them in the struct we create where the `const` has a completely different meaning. This unwinds https://golang.org/cl/33097 with regard to top-level qualifiers. Change-Id: I3d66b0eb43b6d9a586d9cdedfae5a2306b46d96c Reviewed-on: https://go-review.googlesource.com/33325 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
43 lines
887 B
Go
43 lines
887 B
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Issue 17537. The void* cast introduced by cgo to avoid problems
|
|
// with const/volatile qualifiers breaks C preprocessor macros that
|
|
// emulate functions.
|
|
|
|
package cgotest
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
|
|
typedef struct {
|
|
int i;
|
|
} S17537;
|
|
|
|
int I17537(S17537 *p);
|
|
|
|
#define I17537(p) ((p)->i)
|
|
|
|
// Calling this function used to fail without the cast.
|
|
const int F17537(const char **p) {
|
|
return **p;
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
import "testing"
|
|
|
|
func test17537(t *testing.T) {
|
|
v := C.S17537{i: 17537}
|
|
if got, want := C.I17537(&v), C.int(17537); got != want {
|
|
t.Errorf("got %d, want %d", got, want)
|
|
}
|
|
|
|
p := (*C.char)(C.malloc(1))
|
|
*p = 17
|
|
if got, want := C.F17537(&p), C.int(17); got != want {
|
|
t.Errorf("got %d, want %d", got, want)
|
|
}
|
|
}
|