mirror of
https://github.com/golang/go
synced 2024-11-23 05:00:07 -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:
parent
4345a9fc5d
commit
8543cc5635
@ -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;
|
||||
}
|
||||
|
||||
|
@ -7,4 +7,4 @@ package p
|
||||
import "C"
|
||||
|
||||
//export FromPkg
|
||||
func FromPkg() string { return "str" }
|
||||
func FromPkg() int32 { return 1024 }
|
||||
|
Loading…
Reference in New Issue
Block a user