You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
forgejo/vendor/github.com/modern-go/reflect2/unsafe_type.go

86 lines
2.2 KiB
Go

Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
4 years ago
package reflect2
import (
"reflect"
"unsafe"
)
type unsafeType struct {
safeType
rtype unsafe.Pointer
ptrRType unsafe.Pointer
}
func newUnsafeType(cfg *frozenConfig, type1 reflect.Type) *unsafeType {
return &unsafeType{
safeType: safeType{
Type: type1,
cfg: cfg,
},
rtype: unpackEFace(type1).data,
ptrRType: unpackEFace(reflect.PtrTo(type1)).data,
}
}
func (type2 *unsafeType) Set(obj interface{}, val interface{}) {
objEFace := unpackEFace(obj)
assertType("Type.Set argument 1", type2.ptrRType, objEFace.rtype)
valEFace := unpackEFace(val)
assertType("Type.Set argument 2", type2.ptrRType, valEFace.rtype)
type2.UnsafeSet(objEFace.data, valEFace.data)
}
func (type2 *unsafeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) {
typedmemmove(type2.rtype, ptr, val)
}
func (type2 *unsafeType) IsNil(obj interface{}) bool {
objEFace := unpackEFace(obj)
assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype)
return type2.UnsafeIsNil(objEFace.data)
}
func (type2 *unsafeType) UnsafeIsNil(ptr unsafe.Pointer) bool {
return ptr == nil
}
func (type2 *unsafeType) UnsafeNew() unsafe.Pointer {
return unsafe_New(type2.rtype)
}
func (type2 *unsafeType) New() interface{} {
return packEFace(type2.ptrRType, type2.UnsafeNew())
}
func (type2 *unsafeType) PackEFace(ptr unsafe.Pointer) interface{} {
return packEFace(type2.ptrRType, ptr)
}
func (type2 *unsafeType) RType() uintptr {
return uintptr(type2.rtype)
}
func (type2 *unsafeType) Indirect(obj interface{}) interface{} {
objEFace := unpackEFace(obj)
assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype)
return type2.UnsafeIndirect(objEFace.data)
}
func (type2 *unsafeType) UnsafeIndirect(obj unsafe.Pointer) interface{} {
return packEFace(type2.rtype, obj)
}
func (type2 *unsafeType) LikePtr() bool {
return false
}
func assertType(where string, expectRType unsafe.Pointer, actualRType unsafe.Pointer) {
if expectRType != actualRType {
expectType := reflect.TypeOf(0)
(*iface)(unsafe.Pointer(&expectType)).data = expectRType
actualType := reflect.TypeOf(0)
(*iface)(unsafe.Pointer(&actualType)).data = actualRType
panic(where + ": expect " + expectType.String() + ", actual " + actualType.String())
}
}