Skip to content

Commit

Permalink
fix go1.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Tao Wen committed Sep 11, 2021
1 parent 9f87197 commit 8358028
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/modern-go/reflect2

go 1.18
go 1.12
23 changes: 23 additions & 0 deletions go_above_118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//+build go1.18

package reflect2

import (
"unsafe"
)

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//go:noescape
//go:linkname mapiterinit reflect.mapiterinit
func mapiterinit(rtype unsafe.Pointer, m unsafe.Pointer, it *hiter)

func (type2 *UnsafeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
var it hiter
mapiterinit(type2.rtype, *(*unsafe.Pointer)(obj), &it)
return &UnsafeMapIterator{
hiter: &it,
pKeyRType: type2.pKeyRType,
pElemRType: type2.pElemRType,
}
}
21 changes: 21 additions & 0 deletions go_below_118.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//+build !go1.18

package reflect2

import (
"unsafe"
)

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//go:noescape
//go:linkname mapiterinit reflect.mapiterinit
func mapiterinit(rtype unsafe.Pointer, m unsafe.Pointer) (val *hiter)

func (type2 *UnsafeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
return &UnsafeMapIterator{
hiter: mapiterinit(type2.rtype, *(*unsafe.Pointer)(obj)),
pKeyRType: type2.pKeyRType,
pElemRType: type2.pElemRType,
}
}
12 changes: 0 additions & 12 deletions test.sh

This file was deleted.

6 changes: 0 additions & 6 deletions unsafe_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ func mapassign(rtype unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer, val u
//go:noescape
func mapaccess(rtype unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer)

// m escapes into the return value, but the caller of mapiterinit
// doesn't let the return value escape.
//go:noescape
//go:linkname mapiterinit reflect.mapiterinit
func mapiterinit(rtype unsafe.Pointer, m unsafe.Pointer, it *hiter)

//go:noescape
//go:linkname mapiternext reflect.mapiternext
func mapiternext(it *hiter)
Expand Down
10 changes: 0 additions & 10 deletions unsafe_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ func (type2 *UnsafeMapType) Iterate(obj interface{}) MapIterator {
return type2.UnsafeIterate(objEFace.data)
}

func (type2 *UnsafeMapType) UnsafeIterate(obj unsafe.Pointer) MapIterator {
var it hiter
mapiterinit(type2.rtype, *(*unsafe.Pointer)(obj), &it)
return &UnsafeMapIterator{
hiter: &it,
pKeyRType: type2.pKeyRType,
pElemRType: type2.pElemRType,
}
}

type UnsafeMapIterator struct {
*hiter
pKeyRType unsafe.Pointer
Expand Down

0 comments on commit 8358028

Please sign in to comment.