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 arrays passed have some elements referring to a large number (~250 digits), prolly due to wrong address reference. #40474

Closed
priyanshudon opened this issue Jul 29, 2020 · 2 comments

Comments

@priyanshudon
Copy link

@priyanshudon priyanshudon commented Jul 29, 2020

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

$ go version
go version go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/priyanshu/.cache/go-build"
GOENV="/home/priyanshu/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/priyanshu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build725303804=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm running a Go server in which I'm using CGo to call my C functions. The parameters are being passed correctly.
A 'weights' array was assigned in the golang part and sent to the C function as parameter as a pointer in the following way:

result := *C.myFxn( (*C.double)(&myWeights[0]) )

I've checked the array is passed correctly as expected.

Now whenever I start the server, mostly for the first request everything works fine. But for the 2nd and succeeding requests, there comes these issue in the C code.

The weights[i] values are equal to 0. So I check if they are not equal to zero in the 'if' condition.(See the img):
image

What did you expect to see?

(i) The code shouldn't have entered the if condition, so no lines would've printed for any times i make requests.

What did you see instead?

(i) The code enters the if condition and the print statement is executed. Infact, The weights[i] in the print statement print out as 0. Again if they're zero, these shouldn't have entered the if condition.
Also some of the weights[i] which are 0 are printed out as a very large number(~250 digits).

I feel like this is some address reference issue in CGo (that's why that large number sometimes). I guess many others must have faced a similar issue in CGo as well.

@randall77
Copy link
Contributor

@randall77 randall77 commented Jul 29, 2020

Could you give us a complete runnable example? It's going to be hard to figure out what is going on without a runnable example.

Please also post code as text, not as images (using the insert code widget). That way we can copy-paste it. Attach it if it is large.

@gopherbot
Copy link

@gopherbot gopherbot commented Aug 29, 2020

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.