aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/modern-go/reflect2/unsafe_field.go
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
committerLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
commit404aeae4545d2426c089a5f8d5e82dae56f5212b (patch)
tree2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/modern-go/reflect2/unsafe_field.go
parent209d8b0187ed025dec9ac149ebcced3462877bff (diff)
downloadgitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz
gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip
Make Nix builds work
Diffstat (limited to 'vendor/github.com/modern-go/reflect2/unsafe_field.go')
-rw-r--r--vendor/github.com/modern-go/reflect2/unsafe_field.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/github.com/modern-go/reflect2/unsafe_field.go b/vendor/github.com/modern-go/reflect2/unsafe_field.go
new file mode 100644
index 0000000..5eb5313
--- /dev/null
+++ b/vendor/github.com/modern-go/reflect2/unsafe_field.go
@@ -0,0 +1,74 @@
1package reflect2
2
3import (
4 "reflect"
5 "unsafe"
6)
7
8type UnsafeStructField struct {
9 reflect.StructField
10 structType *UnsafeStructType
11 rtype unsafe.Pointer
12 ptrRType unsafe.Pointer
13}
14
15func newUnsafeStructField(structType *UnsafeStructType, structField reflect.StructField) *UnsafeStructField {
16 return &UnsafeStructField{
17 StructField: structField,
18 rtype: unpackEFace(structField.Type).data,
19 ptrRType: unpackEFace(reflect.PtrTo(structField.Type)).data,
20 structType: structType,
21 }
22}
23
24func (field *UnsafeStructField) Offset() uintptr {
25 return field.StructField.Offset
26}
27
28func (field *UnsafeStructField) Name() string {
29 return field.StructField.Name
30}
31
32func (field *UnsafeStructField) PkgPath() string {
33 return field.StructField.PkgPath
34}
35
36func (field *UnsafeStructField) Type() Type {
37 return field.structType.cfg.Type2(field.StructField.Type)
38}
39
40func (field *UnsafeStructField) Tag() reflect.StructTag {
41 return field.StructField.Tag
42}
43
44func (field *UnsafeStructField) Index() []int {
45 return field.StructField.Index
46}
47
48func (field *UnsafeStructField) Anonymous() bool {
49 return field.StructField.Anonymous
50}
51
52func (field *UnsafeStructField) Set(obj interface{}, value interface{}) {
53 objEFace := unpackEFace(obj)
54 assertType("StructField.SetIndex argument 1", field.structType.ptrRType, objEFace.rtype)
55 valueEFace := unpackEFace(value)
56 assertType("StructField.SetIndex argument 2", field.ptrRType, valueEFace.rtype)
57 field.UnsafeSet(objEFace.data, valueEFace.data)
58}
59
60func (field *UnsafeStructField) UnsafeSet(obj unsafe.Pointer, value unsafe.Pointer) {
61 fieldPtr := add(obj, field.StructField.Offset, "same as non-reflect &v.field")
62 typedmemmove(field.rtype, fieldPtr, value)
63}
64
65func (field *UnsafeStructField) Get(obj interface{}) interface{} {
66 objEFace := unpackEFace(obj)
67 assertType("StructField.GetIndex argument 1", field.structType.ptrRType, objEFace.rtype)
68 value := field.UnsafeGet(objEFace.data)
69 return packEFace(field.ptrRType, value)
70}
71
72func (field *UnsafeStructField) UnsafeGet(obj unsafe.Pointer) unsafe.Pointer {
73 return add(obj, field.StructField.Offset, "same as non-reflect &v.field")
74}