1
0
mirror of https://github.com/golang/go synced 2024-11-12 07:00:21 -07:00

misc/cgo/testcarchive: avoid bad pointer passing

Change-Id: Ifbcc0eb24834f2f7d3b160d1dc911209723d9797
Reviewed-on: https://go-review.googlesource.com/8863
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
David Crawshaw 2015-04-13 14:54:36 -04:00
parent 4345a9fc5d
commit 8543cc5635
2 changed files with 5 additions and 7 deletions

View File

@ -4,15 +4,13 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
typedef struct { char *p; intmax_t n; } GoString;
extern signed char DidInitRun();
extern signed char DidMainRun();
extern GoString FromPkg();
extern int32_t FromPkg();
int main(void) {
GoString res;
int32_t res;
if (DidMainRun()) {
fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
@ -25,8 +23,8 @@ int main(void) {
}
res = FromPkg();
if (strcmp(res.p, "str")) {
fprintf(stderr, "ERROR: FromPkg()='%s', want 'str'\n", res.p);
if (res != 1024) {
fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
return 2;
}

View File

@ -7,4 +7,4 @@ package p
import "C"
//export FromPkg
func FromPkg() string { return "str" }
func FromPkg() int32 { return 1024 }