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

bind: pass &v[0] in direct call to C #267

Merged
merged 1 commit into from
Feb 1, 2016
Merged

Conversation

ianlancetaylor
Copy link
Contributor

In Go 1.6, the cgo checking rules are more precise when they see an
address operation as an argument to the C function. When you pass &v[0]
to a C function, the cgo check just verifies that v itself does not
contain any pointers. When you write p := &v[0] and then pass p to
the C function, the cgo check is conservative: it verifies that the
entire memory block to which p points does not contain any pointers.
When the bind function is called by code that passes a slice that is
part of a larger struct, this means that the cgo check will look at the
entire larger struct, not just the slice. This can cause a surprising
run time failure.

Avoid this problem by rewriting the code slightly to pass &v[0] in the
call to the C function itself.

In particular this fixes the tests of github.com/jmoiron/sqlx when using
Go 1.6.

In Go 1.6, the cgo checking rules are more precise when they see an
address operation as an argument to the C function.  When you pass &v[0]
to a C function, the cgo check just verifies that v itself does not
contain any pointers.  When you write `p := &v[0]` and then pass p to
the C function, the cgo check is conservative: it verifies that the
entire memory block to which p points does not contain any pointers.
When the bind function is called by code that passes a slice that is
part of a larger struct, this means that the cgo check will look at the
entire larger struct, not just the slice.  This can cause a surprising
run time failure.

Avoid this problem by rewriting the code slightly to pass &v[0] in the
call to the C function itself.

In particular this fixes the tests of github.com/jmoiron/sqlx when using
Go 1.6.
mattn added a commit that referenced this pull request Feb 1, 2016
bind: pass &v[0] in direct call to C
@mattn mattn merged commit c5aee96 into mattn:master Feb 1, 2016
@mattn
Copy link
Owner

mattn commented Feb 1, 2016

I see. Thank you.

vanadium-bot pushed a commit to vanadium-archive/third_party that referenced this pull request Mar 14, 2016
Motivation: To make things work with Go 1.6
Specifically to get this mattn/go-sqlite3#267
and mattn/go-sqlite3#268

Change-Id: I66daa419daebfddf1382ade56af4d1806eebf409
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants