mirror of
https://github.com/golang/go
synced 2024-11-27 04:41:33 -07:00
f7a8adbd51
Instead of including <sys/types.h> to get size_t, instead include the ISO C standard <stddef.h> header, which defines fewer additional types at risk of colliding with the user code. In particular, this prevents collisions between <sys/types.h>'s userspace definitions with the kernel definitions needed by defs_linux.go. Also, -cdefs mode uses #pragma pack, so we can keep misaligned fields. Fixes #8477. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://golang.org/cl/120610043
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
// Copyright 2013 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.
|
|
//
|
|
// +build ignore
|
|
|
|
package cgotest
|
|
|
|
/*
|
|
// This file tests a bug found in the cgo -cdefs tool that incorrectly
|
|
// translated Go pointer arrays generated by the cgo godefs tool back into C
|
|
// pointer arrays.
|
|
//
|
|
// The comments below show how the type is translated from gcc-style C into Go
|
|
// and back into C for both the buggy version and the correct version
|
|
|
|
struct cdefsTest {
|
|
// This was already being handled correctly
|
|
// Correct: -> Array [20]int8 -> int8 array[20]
|
|
char array1[20];
|
|
|
|
// Buggy: -> Array [20][20]int8 -> [20]int8 array[20]
|
|
// Correct: -> Array [20][20]int8 -> int8 array[20][20]
|
|
char array2[20][20];
|
|
|
|
// Buggy: -> Array [20]*int8 -> *int8 array[20]
|
|
// Correct: -> Array [20]*int8 -> int8 *array[20]
|
|
char *array3[20];
|
|
|
|
// Buggy: -> Array [20][20]*int8 -> [20]*int8 array[20]
|
|
// Correct: -> Array [20]**int8 -> int8 *array[20][20]
|
|
char *array4[20][20];
|
|
|
|
// Buggy: -> Array [20][20]**int8 -> [20]**int8 array[20]
|
|
// Correct: -> Array [20][20]**int8 -> int8 **array[20][20]
|
|
char **array5[20][20];
|
|
};
|
|
|
|
// Test that packed structures can be translated to C correctly too.
|
|
// See issue 8477.
|
|
|
|
struct packedTest {
|
|
char first;
|
|
int second;
|
|
long long third;
|
|
} __attribute__((packed));
|
|
|
|
// Test that conflicting type definitions don't cause problems with cgo.
|
|
// See issue 8477.
|
|
|
|
typedef struct timespec {
|
|
double bogus;
|
|
} pid_t;
|
|
|
|
*/
|
|
import "C"
|
|
|
|
type CdefsTest C.struct_cdefsTest
|
|
type PackedTest C.struct_packedTest
|