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

Don't merge until publication of Golang v1.16: GtkAccelKey v1.16 issue fix #687

Closed
wants to merge 2 commits into from

Conversation

hfmrow
Copy link
Contributor

@hfmrow hfmrow commented Dec 18, 2020

Please do not merge this PR until the official release of the public version of Golang 1.16.

As the current version of Golang 1.16 is still in beta (until February), further changes can be added until its public release.

This PR fixes the problem with the GtkAccelKey declaration described below.
Its purpose is to help users, like me, who want to test future v1.16 functionality, while using the gotk3 library, and to facilitate discussion about this to make this solution the best it can be for everyone.

GtkAccelKey and Golang 1.16 issue

altered file: 'accel.go'

Golang 1.16 - Cgo changes Go 1.16 Release Notes - The Go Programming Language:
The cgo tool will no longer try to translate C struct bitfields into Go struct fields, even if their size can be represented in Go. The order in which C bitfields appear in memory is implementation dependent, so in some cases the cgo tool produced results that were silently incorrect.

'C' struct definition:

struct GtkAccelKey {
  guint           accel_key;
  GdkModifierType accel_mods;
  guint           accel_flags : 16;
};

Cgo compilation errors:

../../gotk3/gotk3/gtk/accel.go:264:5: val.accel_flags undefined (type _Ctype_struct__GtkAccelKey has no field or method accel_flags)
../../gotk3/gotk3/gtk/accel.go:273:22: obj.accel_flags undefined (type *_Ctype_struct__GtkAccelKey has no field or method accel_flags)

Solution:
Need new declaration for GtkAccelKey structure that does not explicitly access to 'accel_flags'.
'accel_flags' value remain accessible using bitwise operations.

Please do not merge this PR before Golang 1.16 public version release.

This PR fixes the issue with the GtkAccelKey declaration described below, its purpose is to help users like me who want to test v1.16 using the gotk3 library and to facilitate discussion about this subject to make this solution as better as possible.

_As the current version of Golang 1.16 is still in beta (until February), further changes can be added until its public release._

#### GtkAccelKey and Golang 1.16 issue

altered file: 'accel.go'

Golang 1.16 - Cgo changes [Go 1.16 Release Notes - The Go Programming Language](https://tip.golang.org/doc/go1.16#cgo):
The cgo tool will no longer try to translate C struct bitfields into Go struct fields, even if their size can be represented in Go. The order in which C bitfields appear in memory is implementation dependent, so in some cases the cgo tool produced results that were silently incorrect.

'C' struct definition:

```c
struct GtkAccelKey {
  guint           accel_key;
  GdkModifierType accel_mods;
  guint           accel_flags : 16;
};
```

Cgo compilation errors:

```bash
../../gotk3/gotk3/gtk/accel.go:264:5: val.accel_flags undefined (type _Ctype_struct__GtkAccelKey has no field or method accel_flags)
../../gotk3/gotk3/gtk/accel.go:273:22: obj.accel_flags undefined (type *_Ctype_struct__GtkAccelKey has no field or method accel_flags)
```

Solution:
Need new declaration for GtkAccelKey structure that does not explicitly access to 'accel_flags'.
'accel_flags' value remain accessible using bitwise operations.
@rubiojr
Copy link

rubiojr commented Dec 18, 2020

I just hit this, thanks for documenting it.

@andre-hub andre-hub modified the milestones: V0.7.0, V0.5.2, V0.6.0 Dec 19, 2020
rubiojr added a commit to rubiojr/xkcd-gtk that referenced this pull request Jan 14, 2021
Go 1.16 will make it harder to not use modules by default.

* Adds Go modules support
* Bumped gotk3 and added required fixes

The rest of the changes are related

Note that gotk3 will need to be bumped again for Go 1.16, to include
gotk3/gotk3#687
@rubiojr
Copy link

rubiojr commented Feb 14, 2021

@hfmrow doesn't seem 1.16rc1 changed anything that would affect this. What would be the downside (if any) of merging this now before 1.16 GM is released?

@hfmrow hfmrow closed this Feb 16, 2021
@hfmrow hfmrow deleted the GtkAccelKey-and-Golang-1.16-issue branch February 16, 2021 21:05
@hfmrow
Copy link
Contributor Author

hfmrow commented Feb 23, 2021

dropped and re-post
Sorry for the inconvenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants