http urls monitor.

unsafe_type.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package reflect2
  2. import (
  3. "reflect"
  4. "unsafe"
  5. )
  6. type unsafeType struct {
  7. safeType
  8. rtype unsafe.Pointer
  9. ptrRType unsafe.Pointer
  10. }
  11. func newUnsafeType(cfg *frozenConfig, type1 reflect.Type) *unsafeType {
  12. return &unsafeType{
  13. safeType: safeType{
  14. Type: type1,
  15. cfg: cfg,
  16. },
  17. rtype: unpackEFace(type1).data,
  18. ptrRType: unpackEFace(reflect.PtrTo(type1)).data,
  19. }
  20. }
  21. func (type2 *unsafeType) Set(obj interface{}, val interface{}) {
  22. objEFace := unpackEFace(obj)
  23. assertType("Type.Set argument 1", type2.ptrRType, objEFace.rtype)
  24. valEFace := unpackEFace(val)
  25. assertType("Type.Set argument 2", type2.ptrRType, valEFace.rtype)
  26. type2.UnsafeSet(objEFace.data, valEFace.data)
  27. }
  28. func (type2 *unsafeType) UnsafeSet(ptr unsafe.Pointer, val unsafe.Pointer) {
  29. typedmemmove(type2.rtype, ptr, val)
  30. }
  31. func (type2 *unsafeType) IsNil(obj interface{}) bool {
  32. objEFace := unpackEFace(obj)
  33. assertType("Type.IsNil argument 1", type2.ptrRType, objEFace.rtype)
  34. return type2.UnsafeIsNil(objEFace.data)
  35. }
  36. func (type2 *unsafeType) UnsafeIsNil(ptr unsafe.Pointer) bool {
  37. return ptr == nil
  38. }
  39. func (type2 *unsafeType) UnsafeNew() unsafe.Pointer {
  40. return unsafe_New(type2.rtype)
  41. }
  42. func (type2 *unsafeType) New() interface{} {
  43. return packEFace(type2.ptrRType, type2.UnsafeNew())
  44. }
  45. func (type2 *unsafeType) PackEFace(ptr unsafe.Pointer) interface{} {
  46. return packEFace(type2.ptrRType, ptr)
  47. }
  48. func (type2 *unsafeType) RType() uintptr {
  49. return uintptr(type2.rtype)
  50. }
  51. func (type2 *unsafeType) Indirect(obj interface{}) interface{} {
  52. objEFace := unpackEFace(obj)
  53. assertType("Type.Indirect argument 1", type2.ptrRType, objEFace.rtype)
  54. return type2.UnsafeIndirect(objEFace.data)
  55. }
  56. func (type2 *unsafeType) UnsafeIndirect(obj unsafe.Pointer) interface{} {
  57. return packEFace(type2.rtype, obj)
  58. }
  59. func (type2 *unsafeType) LikePtr() bool {
  60. return false
  61. }
  62. func assertType(where string, expectRType unsafe.Pointer, actualRType unsafe.Pointer) {
  63. if expectRType != actualRType {
  64. expectType := reflect.TypeOf(0)
  65. (*iface)(unsafe.Pointer(&expectType)).data = expectRType
  66. actualType := reflect.TypeOf(0)
  67. (*iface)(unsafe.Pointer(&actualType)).data = actualRType
  68. panic(where + ": expect " + expectType.String() + ", actual " + actualType.String())
  69. }
  70. }