Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgo: the type of export function is not expect. #42086

Closed
wangfakang opened this issue Oct 20, 2020 · 5 comments
Closed

cgo: the type of export function is not expect. #42086

wangfakang opened this issue Oct 20, 2020 · 5 comments

Comments

@wangfakang
Copy link

What version of Go are you using (go version)?

 go1.13.7

Does this issue reproduce with the latest release?

1.14.2 is ok.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

The type of export function process generated by the go build -o cgo.so -buildmode=c-shared cgo.go is not expect. It should be extern Response process(Request p0);, but got extern Response process(Response p0);.

cgo.go

package main

/*
typedef struct {
    char header[5];
    char *body;
}Request;

typedef struct {
    char header[5];
    char *body;
}Response;
*/
import "C"

//export process
func process(r C.Request) C.Response {
        return C.Response{}
}

func main() {
}

What did you expect to see?

cgo.h

/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package command-line-arguments */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments.  */


#line 3 "cgo.go"

typedef struct {
    char header[5];
    char *body;
}Response;
typedef struct {
    char header[5];
    char *body;
}Request;


#line 1 "cgo-generated-wrapper"


/* End of preamble from import "C" comments.  */


/* Start of boilerplate cgo prologue.  */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

/*
  static assertion to make sure the file is being used on architecture
  at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue.  */

#ifdef __cplusplus
extern "C" {
#endif


extern Response process(Response p0);

#ifdef __cplusplus
}
#endif

What did you see instead?

/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package command-line-arguments */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h> /* for ptrdiff_t below */

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments.  */


#line 3 "cgo.go"

typedef struct {
    char header[5];
    char *body;
}Response;
typedef struct {
    char header[5];
    char *body;
}Request;


#line 1 "cgo-generated-wrapper"


/* End of preamble from import "C" comments.  */


/* Start of boilerplate cgo prologue.  */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;

/*
  static assertion to make sure the file is being used on architecture
  at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue.  */

#ifdef __cplusplus
extern "C" {
#endif


extern Response process(Request p0);

#ifdef __cplusplus
}
#endif
@martisch
Copy link
Contributor

martisch commented Oct 20, 2020

go1.13 is not supported anymore and therefore wont get any fixes. Please upgrade to go1.14 or go1.15 if it works there.

Closing the issue for now. Please reopen if it is reproducable in the latest minor versions of go1.14 or go1.15.

@wangfakang
Copy link
Author

go1.13 is not supported anymore and therefore wont get any fixes. Please upgrade to go1.14 or go1.15 if it works there.

Closing the issue for now. Please reopen if it is reproducable in the latest minor versions of go1.14 or go1.15.

@martisch Could you paste the PR link on fixed this problem, thx.

@martisch
Copy link
Contributor

I do not have a PR link. From your report I understood its already fixed. Feel free to open the request if its unknown and important what fixed it so to bisect what fixed it or if you discover it needs a better test harness to have that as a feature request as it may have only been fixed accidentially.

@ianlancetaylor
Copy link
Contributor

This is probably #31891.

@wangfakang
Copy link
Author

This is probably #31891.

got it, thx.

@golang golang locked and limited conversation to collaborators Oct 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants