Kevin Klues | f7dfeea | 2013-07-24 17:27:42 -0700 | [diff] [blame] | 1 | // Copyright 2013 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | // |
| 5 | // +build ignore |
| 6 | |
| 7 | package cgotest |
| 8 | |
| 9 | /* |
| 10 | // This file tests a bug found in the cgo -cdefs tool that incorrectly |
| 11 | // translated Go pointer arrays generated by the cgo godefs tool back into C |
| 12 | // pointer arrays. |
| 13 | // |
| 14 | // The comments below show how the type is translated from gcc-style C into Go |
| 15 | // and back into C for both the buggy version and the correct version |
| 16 | |
| 17 | struct cdefsTest { |
| 18 | // This was already being handled correctly |
| 19 | // Correct: -> Array [20]int8 -> int8 array[20] |
| 20 | char array1[20]; |
| 21 | |
| 22 | // Buggy: -> Array [20][20]int8 -> [20]int8 array[20] |
| 23 | // Correct: -> Array [20][20]int8 -> int8 array[20][20] |
| 24 | char array2[20][20]; |
| 25 | |
| 26 | // Buggy: -> Array [20]*int8 -> *int8 array[20] |
| 27 | // Correct: -> Array [20]*int8 -> int8 *array[20] |
| 28 | char *array3[20]; |
| 29 | |
| 30 | // Buggy: -> Array [20][20]*int8 -> [20]*int8 array[20] |
| 31 | // Correct: -> Array [20]**int8 -> int8 *array[20][20] |
| 32 | char *array4[20][20]; |
| 33 | |
| 34 | // Buggy: -> Array [20][20]**int8 -> [20]**int8 array[20] |
| 35 | // Correct: -> Array [20][20]**int8 -> int8 **array[20][20] |
| 36 | char **array5[20][20]; |
| 37 | }; |
Matthew Dempsky | f7a8adb | 2014-08-05 18:12:32 -0700 | [diff] [blame] | 38 | |
| 39 | // Test that packed structures can be translated to C correctly too. |
| 40 | // See issue 8477. |
| 41 | |
| 42 | struct packedTest { |
| 43 | char first; |
| 44 | int second; |
| 45 | long long third; |
| 46 | } __attribute__((packed)); |
| 47 | |
| 48 | // Test that conflicting type definitions don't cause problems with cgo. |
| 49 | // See issue 8477. |
| 50 | |
| 51 | typedef struct timespec { |
| 52 | double bogus; |
| 53 | } pid_t; |
| 54 | |
Kevin Klues | f7dfeea | 2013-07-24 17:27:42 -0700 | [diff] [blame] | 55 | */ |
| 56 | import "C" |
| 57 | |
| 58 | type CdefsTest C.struct_cdefsTest |
Ian Lance Taylor | 709096f | 2014-08-31 22:59:43 -0400 | [diff] [blame] | 59 | |
| 60 | //type PackedTest C.struct_packedTest |