Skip to content

Commit

Permalink
cmd/cue: support unsafe pointer in get go
Browse files Browse the repository at this point in the history
Fixes #2641

Change-Id: Ie77cc7d326cdcc5980d0432e0caf3a6bb0de2c8e
Signed-off-by: Thomas Way <thomas@6f.io>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1171292
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
uhthomas authored and mvdan committed Oct 27, 2023
1 parent 200a8ec commit 05ceba6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,13 +1139,13 @@ func (e *extractor) makeType(expr types.Type) (result cueast.Expr) {
}

case *types.Basic:
switch t := x.String(); t {
case "uintptr":
switch x.Kind() {
case types.Uintptr, types.UnsafePointer:
return e.ident("uint64", false)
case "byte":
case types.Byte:
return e.ident("uint8", false)
default:
return e.ident(t, false)
return e.ident(x.String(), false)
}

case *types.Interface:
Expand Down
19 changes: 19 additions & 0 deletions cmd/cue/cmd/testdata/script/get_go_types.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cmp ./pkg3/pkg3_go_gen.cue ./pkg3/pkg3_go_gen.cue.golden
cmp ./pkg1/file1_go_gen.cue ./pkg1/file1_go_gen.cue.golden
cmp ./pkg1/alias_go_gen.cue ./pkg1/alias_go_gen.cue.golden
cmp ./pkg2/pkg2_go_gen.cue ./pkg2/pkg2_go_gen.cue.golden
cmp ./pkg4/pkg4_go_gen.cue ./pkg4/pkg4_go_gen.cue.golden

# Verify dependencies did not change
cmp go.mod go.mod.golden
Expand Down Expand Up @@ -414,3 +415,21 @@ package pkg3
import "mod.test/pkg2:pkgtwo"

#Barzer: pkgtwo.#Barzer
-- pkg4/pkg4.go --
package pkg4

import "unsafe"

type A struct {
UnsafePointer unsafe.Pointer
}
-- pkg4/pkg4_go_gen.cue.golden --
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go mod.test/pkg4

package pkg4

#A: {
UnsafePointer: uint64 @go(,unsafe.Pointer)
}

0 comments on commit 05ceba6

Please sign in to comment.