-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2018, The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE.md file. | ||
|
||
// +build purego | ||
|
||
// Package pointer provides an abstraction over opaque pointers. | ||
package pointer | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
// P is a typed pointer and is guaranteed to be comparable. | ||
type P struct { | ||
p uintptr | ||
t reflect.Type | ||
} | ||
|
||
// New returns a typed pointer P from v, which must be a Ptr, Slice, or Map. | ||
func New(v reflect.Value) P { | ||
// NOTE: Storing a pointer as an uintptr is technically incorrect as it | ||
// assumes that the GC implementation does not use a moving collector. | ||
return P{v.Pointer(), v.Type()} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018, The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE.md file. | ||
|
||
// +build !purego | ||
|
||
// Package pointer provides an abstraction over opaque pointers. | ||
package pointer | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
) | ||
|
||
// P is a typed pointer and is guaranteed to be comparable. | ||
type P struct { | ||
p unsafe.Pointer | ||
t reflect.Type | ||
} | ||
|
||
// New returns a typed pointer P from v, which must be a Ptr, Slice, or Map. | ||
func New(v reflect.Value) P { | ||
// The proper representation of a pointer is unsafe.Pointer, | ||
// which is necessary if the GC ever uses a moving collector. | ||
return P{unsafe.Pointer(v.Pointer()), v.Type()} | ||
} |
Oops, something went wrong.