Skip to content

Commit

Permalink
Merge pull request #11 from mythi/nolegacy
Browse files Browse the repository at this point in the history
drop legacy Go support
  • Loading branch information
taowen authored Jan 9, 2021
2 parents 7e6ae53 + bb009fe commit 333559e
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.8.x
- 1.9.x
- 1.x

before_install:
Expand Down
8 changes: 1 addition & 7 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

ignored = []

[[constraint]]
name = "github.com/modern-go/concurrent"
version = "1.0.0"

[prune]
go-tests = true
unused-packages = true
8 changes: 0 additions & 8 deletions go_above_17.go

This file was deleted.

3 changes: 3 additions & 0 deletions go_above_19.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"unsafe"
)

//go:linkname resolveTypeOff reflect.resolveTypeOff
func resolveTypeOff(rtype unsafe.Pointer, off int32) unsafe.Pointer

//go:linkname makemap reflect.makemap
func makemap(rtype unsafe.Pointer, cap int) (m unsafe.Pointer)

Expand Down
9 changes: 0 additions & 9 deletions go_below_17.go

This file was deleted.

14 changes: 0 additions & 14 deletions go_below_19.go

This file was deleted.

6 changes: 3 additions & 3 deletions reflect2.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package reflect2

import (
"github.com/modern-go/concurrent"
"reflect"
"runtime"
"sync"
"unsafe"
)

Expand Down Expand Up @@ -131,13 +131,13 @@ var ConfigSafe = Config{UseSafeImplementation: true}.Froze()

type frozenConfig struct {
useSafeImplementation bool
cache *concurrent.Map
cache *sync.Map
}

func (cfg Config) Froze() *frozenConfig {
return &frozenConfig{
useSafeImplementation: cfg.UseSafeImplementation,
cache: concurrent.NewMap(),
cache: new(sync.Map),
}
}

Expand Down
49 changes: 2 additions & 47 deletions type_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ package reflect2

import (
"reflect"
"runtime"
"strings"
"sync"
"unsafe"
)

// typelinks1 for 1.5 ~ 1.6
//go:linkname typelinks1 reflect.typelinks
func typelinks1() [][]unsafe.Pointer

// typelinks2 for 1.7 ~
//go:linkname typelinks2 reflect.typelinks
func typelinks2() (sections []unsafe.Pointer, offset [][]int32)
Expand All @@ -29,49 +23,10 @@ func discoverTypes() {
types = make(map[string]reflect.Type)
packages = make(map[string]map[string]reflect.Type)

ver := runtime.Version()
if ver == "go1.5" || strings.HasPrefix(ver, "go1.5.") {
loadGo15Types()
} else if ver == "go1.6" || strings.HasPrefix(ver, "go1.6.") {
loadGo15Types()
} else {
loadGo17Types()
}
}

func loadGo15Types() {
var obj interface{} = reflect.TypeOf(0)
typePtrss := typelinks1()
for _, typePtrs := range typePtrss {
for _, typePtr := range typePtrs {
(*emptyInterface)(unsafe.Pointer(&obj)).word = typePtr
typ := obj.(reflect.Type)
if typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Struct {
loadedType := typ.Elem()
pkgTypes := packages[loadedType.PkgPath()]
if pkgTypes == nil {
pkgTypes = map[string]reflect.Type{}
packages[loadedType.PkgPath()] = pkgTypes
}
types[loadedType.String()] = loadedType
pkgTypes[loadedType.Name()] = loadedType
}
if typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Ptr &&
typ.Elem().Elem().Kind() == reflect.Struct {
loadedType := typ.Elem().Elem()
pkgTypes := packages[loadedType.PkgPath()]
if pkgTypes == nil {
pkgTypes = map[string]reflect.Type{}
packages[loadedType.PkgPath()] = pkgTypes
}
types[loadedType.String()] = loadedType
pkgTypes[loadedType.Name()] = loadedType
}
}
}
loadGoTypes()
}

func loadGo17Types() {
func loadGoTypes() {
var obj interface{} = reflect.TypeOf(0)
sections, offset := typelinks2()
for i, offs := range offset {
Expand Down

0 comments on commit 333559e

Please sign in to comment.