message.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package impl
  5. import (
  6. "fmt"
  7. "reflect"
  8. "sort"
  9. "strconv"
  10. "strings"
  11. "sync"
  12. "sync/atomic"
  13. pvalue "google.golang.org/protobuf/internal/value"
  14. pref "google.golang.org/protobuf/reflect/protoreflect"
  15. piface "google.golang.org/protobuf/runtime/protoiface"
  16. )
  17. // MessageInfo provides protobuf related functionality for a given Go type
  18. // that represents a message. A given instance of MessageInfo is tied to
  19. // exactly one Go type, which must be a pointer to a struct type.
  20. type MessageInfo struct {
  21. // GoType is the underlying message Go type and must be populated.
  22. // Once set, this field must never be mutated.
  23. GoType reflect.Type // pointer to struct
  24. // PBType is the underlying message descriptor type and must be populated.
  25. // Once set, this field must never be mutated.
  26. PBType pref.MessageType
  27. initMu sync.Mutex // protects all unexported fields
  28. initDone uint32
  29. // Keep a separate slice of fields for efficient field encoding in tag order
  30. // and because iterating over a slice is substantially faster than a map.
  31. fields map[pref.FieldNumber]*fieldInfo
  32. fieldsOrdered []*fieldInfo
  33. oneofs map[pref.Name]*oneofInfo
  34. getUnknown func(pointer) pref.RawFields
  35. setUnknown func(pointer, pref.RawFields)
  36. extensionMap func(pointer) *extensionMap
  37. methods piface.Methods
  38. sizecacheOffset offset
  39. extensionOffset offset
  40. unknownOffset offset
  41. extensionFieldInfosMu sync.RWMutex
  42. extensionFieldInfos map[pref.ExtensionType]*extensionFieldInfo
  43. }
  44. var prefMessageType = reflect.TypeOf((*pref.Message)(nil)).Elem()
  45. // getMessageInfo returns the MessageInfo (if any) for a type.
  46. //
  47. // We find the MessageInfo by calling the ProtoReflect method on the type's
  48. // zero value and looking at the returned type to see if it is a
  49. // messageReflectWrapper. Note that the MessageInfo may still be uninitialized
  50. // at this point.
  51. func getMessageInfo(mt reflect.Type) (mi *MessageInfo, ok bool) {
  52. method, ok := mt.MethodByName("ProtoReflect")
  53. if !ok {
  54. return nil, false
  55. }
  56. if method.Type.NumIn() != 1 || method.Type.NumOut() != 1 || method.Type.Out(0) != prefMessageType {
  57. return nil, false
  58. }
  59. ret := reflect.Zero(mt).Method(method.Index).Call(nil)
  60. m, ok := ret[0].Elem().Interface().(*messageReflectWrapper)
  61. if !ok {
  62. return nil, ok
  63. }
  64. return m.mi, true
  65. }
  66. func (mi *MessageInfo) init() {
  67. // This function is called in the hot path. Inline the sync.Once
  68. // logic, since allocating a closure for Once.Do is expensive.
  69. // Keep init small to ensure that it can be inlined.
  70. if atomic.LoadUint32(&mi.initDone) == 1 {
  71. return
  72. }
  73. mi.initOnce()
  74. }
  75. func (mi *MessageInfo) initOnce() {
  76. mi.initMu.Lock()
  77. defer mi.initMu.Unlock()
  78. if mi.initDone == 1 {
  79. return
  80. }
  81. t := mi.GoType
  82. if t.Kind() != reflect.Ptr && t.Elem().Kind() != reflect.Struct {
  83. panic(fmt.Sprintf("got %v, want *struct kind", t))
  84. }
  85. si := mi.makeStructInfo(t.Elem())
  86. mi.makeKnownFieldsFunc(si)
  87. mi.makeUnknownFieldsFunc(t.Elem())
  88. mi.makeExtensionFieldsFunc(t.Elem())
  89. mi.makeMethods(t.Elem())
  90. atomic.StoreUint32(&mi.initDone, 1)
  91. }
  92. type (
  93. SizeCache = int32
  94. UnknownFields = []byte
  95. ExtensionFields = map[int32]ExtensionField
  96. )
  97. var (
  98. sizecacheType = reflect.TypeOf(SizeCache(0))
  99. unknownFieldsType = reflect.TypeOf(UnknownFields(nil))
  100. extensionFieldsType = reflect.TypeOf(ExtensionFields(nil))
  101. )
  102. func (mi *MessageInfo) makeMethods(t reflect.Type) {
  103. mi.sizecacheOffset = invalidOffset
  104. if fx, _ := t.FieldByName("XXX_sizecache"); fx.Type == sizecacheType {
  105. mi.sizecacheOffset = offsetOf(fx)
  106. }
  107. mi.unknownOffset = invalidOffset
  108. if fx, _ := t.FieldByName("XXX_unrecognized"); fx.Type == unknownFieldsType {
  109. mi.unknownOffset = offsetOf(fx)
  110. }
  111. mi.extensionOffset = invalidOffset
  112. if fx, _ := t.FieldByName("XXX_InternalExtensions"); fx.Type == extensionFieldsType {
  113. mi.extensionOffset = offsetOf(fx)
  114. } else if fx, _ = t.FieldByName("XXX_extensions"); fx.Type == extensionFieldsType {
  115. mi.extensionOffset = offsetOf(fx)
  116. }
  117. mi.methods.Flags = piface.MethodFlagDeterministicMarshal
  118. mi.methods.MarshalAppend = mi.marshalAppend
  119. mi.methods.Size = mi.size
  120. }
  121. type structInfo struct {
  122. fieldsByNumber map[pref.FieldNumber]reflect.StructField
  123. oneofsByName map[pref.Name]reflect.StructField
  124. oneofWrappersByType map[reflect.Type]pref.FieldNumber
  125. oneofWrappersByNumber map[pref.FieldNumber]reflect.Type
  126. }
  127. func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
  128. // Generate a mapping of field numbers and names to Go struct field or type.
  129. si := structInfo{
  130. fieldsByNumber: map[pref.FieldNumber]reflect.StructField{},
  131. oneofsByName: map[pref.Name]reflect.StructField{},
  132. oneofWrappersByType: map[reflect.Type]pref.FieldNumber{},
  133. oneofWrappersByNumber: map[pref.FieldNumber]reflect.Type{},
  134. }
  135. fieldLoop:
  136. for i := 0; i < t.NumField(); i++ {
  137. f := t.Field(i)
  138. for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
  139. if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
  140. n, _ := strconv.ParseUint(s, 10, 64)
  141. si.fieldsByNumber[pref.FieldNumber(n)] = f
  142. continue fieldLoop
  143. }
  144. }
  145. if s := f.Tag.Get("protobuf_oneof"); len(s) > 0 {
  146. si.oneofsByName[pref.Name(s)] = f
  147. continue fieldLoop
  148. }
  149. }
  150. var oneofWrappers []interface{}
  151. if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofFuncs"); ok {
  152. oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[3].Interface().([]interface{})
  153. }
  154. if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofWrappers"); ok {
  155. oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0].Interface().([]interface{})
  156. }
  157. for _, v := range oneofWrappers {
  158. tf := reflect.TypeOf(v).Elem()
  159. f := tf.Field(0)
  160. for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
  161. if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
  162. n, _ := strconv.ParseUint(s, 10, 64)
  163. si.oneofWrappersByType[tf] = pref.FieldNumber(n)
  164. si.oneofWrappersByNumber[pref.FieldNumber(n)] = tf
  165. break
  166. }
  167. }
  168. }
  169. return si
  170. }
  171. // makeKnownFieldsFunc generates functions for operations that can be performed
  172. // on each protobuf message field. It takes in a reflect.Type representing the
  173. // Go struct and matches message fields with struct fields.
  174. //
  175. // This code assumes that the struct is well-formed and panics if there are
  176. // any discrepancies.
  177. func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
  178. mi.fields = map[pref.FieldNumber]*fieldInfo{}
  179. mi.fieldsOrdered = make([]*fieldInfo, 0, mi.PBType.Fields().Len())
  180. for i := 0; i < mi.PBType.Descriptor().Fields().Len(); i++ {
  181. fd := mi.PBType.Descriptor().Fields().Get(i)
  182. fs := si.fieldsByNumber[fd.Number()]
  183. var fi fieldInfo
  184. switch {
  185. case fd.ContainingOneof() != nil:
  186. fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], si.oneofWrappersByNumber[fd.Number()])
  187. // There is one fieldInfo for each proto message field, but only one struct
  188. // field for all message fields in a oneof. We install the encoder functions
  189. // on the fieldInfo for the first field in the oneof.
  190. //
  191. // A slightly simpler approach would be to have each fieldInfo's encoder
  192. // handle the case where that field is set, but this would require more
  193. // checks against the current oneof type than a single map lookup.
  194. if fd.ContainingOneof().Fields().Get(0).Name() == fd.Name() {
  195. fi.funcs = makeOneofFieldCoder(si.oneofsByName[fd.ContainingOneof().Name()], fd.ContainingOneof(), si.fieldsByNumber, si.oneofWrappersByNumber)
  196. }
  197. case fd.IsMap():
  198. fi = fieldInfoForMap(fd, fs)
  199. case fd.IsList():
  200. fi = fieldInfoForList(fd, fs)
  201. case fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind:
  202. fi = fieldInfoForMessage(fd, fs)
  203. default:
  204. fi = fieldInfoForScalar(fd, fs)
  205. }
  206. fi.num = fd.Number()
  207. mi.fields[fd.Number()] = &fi
  208. mi.fieldsOrdered = append(mi.fieldsOrdered, &fi)
  209. }
  210. sort.Slice(mi.fieldsOrdered, func(i, j int) bool {
  211. return mi.fieldsOrdered[i].num < mi.fieldsOrdered[j].num
  212. })
  213. mi.oneofs = map[pref.Name]*oneofInfo{}
  214. for i := 0; i < mi.PBType.Descriptor().Oneofs().Len(); i++ {
  215. od := mi.PBType.Descriptor().Oneofs().Get(i)
  216. mi.oneofs[od.Name()] = makeOneofInfo(od, si.oneofsByName[od.Name()], si.oneofWrappersByType)
  217. }
  218. }
  219. func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type) {
  220. mi.getUnknown = func(pointer) pref.RawFields { return nil }
  221. mi.setUnknown = func(pointer, pref.RawFields) { return }
  222. fu, _ := t.FieldByName("XXX_unrecognized")
  223. if fu.Type == unknownFieldsType {
  224. fieldOffset := offsetOf(fu)
  225. mi.getUnknown = func(p pointer) pref.RawFields {
  226. if p.IsNil() {
  227. return nil
  228. }
  229. rv := p.Apply(fieldOffset).AsValueOf(unknownFieldsType)
  230. return pref.RawFields(*rv.Interface().(*[]byte))
  231. }
  232. mi.setUnknown = func(p pointer, b pref.RawFields) {
  233. if p.IsNil() {
  234. panic("invalid SetUnknown on nil Message")
  235. }
  236. rv := p.Apply(fieldOffset).AsValueOf(unknownFieldsType)
  237. *rv.Interface().(*[]byte) = []byte(b)
  238. }
  239. } else {
  240. mi.getUnknown = func(pointer) pref.RawFields {
  241. return nil
  242. }
  243. mi.setUnknown = func(p pointer, _ pref.RawFields) {
  244. if p.IsNil() {
  245. panic("invalid SetUnknown on nil Message")
  246. }
  247. }
  248. }
  249. }
  250. func (mi *MessageInfo) makeExtensionFieldsFunc(t reflect.Type) {
  251. fx, _ := t.FieldByName("XXX_extensions")
  252. if fx.Type != extensionFieldsType {
  253. fx, _ = t.FieldByName("XXX_InternalExtensions")
  254. }
  255. if fx.Type == extensionFieldsType {
  256. fieldOffset := offsetOf(fx)
  257. mi.extensionMap = func(p pointer) *extensionMap {
  258. if p.IsNil() {
  259. return (*extensionMap)(nil)
  260. }
  261. v := p.Apply(fieldOffset).AsValueOf(extensionFieldsType)
  262. return (*extensionMap)(v.Interface().(*map[int32]ExtensionField))
  263. }
  264. } else {
  265. mi.extensionMap = func(pointer) *extensionMap {
  266. return (*extensionMap)(nil)
  267. }
  268. }
  269. }
  270. func (mi *MessageInfo) MessageOf(p interface{}) pref.Message {
  271. return (*messageReflectWrapper)(mi.dataTypeOf(p))
  272. }
  273. func (mi *MessageInfo) Methods() *piface.Methods {
  274. mi.init()
  275. return &mi.methods
  276. }
  277. func (mi *MessageInfo) dataTypeOf(p interface{}) *messageDataType {
  278. // TODO: Remove this check? This API is primarily used by generated code,
  279. // and should not violate this assumption. Leave this check in for now to
  280. // provide some sanity checks during development. This can be removed if
  281. // it proves to be detrimental to performance.
  282. if reflect.TypeOf(p) != mi.GoType {
  283. panic(fmt.Sprintf("type mismatch: got %T, want %v", p, mi.GoType))
  284. }
  285. return &messageDataType{pointerOfIface(p), mi}
  286. }
  287. // messageDataType is a tuple of a pointer to the message data and
  288. // a pointer to the message type.
  289. //
  290. // TODO: Unfortunately, we need to close over a pointer and MessageInfo,
  291. // which incurs an an allocation. This pair is similar to a Go interface,
  292. // which is essentially a tuple of the same thing. We can make this efficient
  293. // with reflect.NamedOf (see https://golang.org/issues/16522).
  294. //
  295. // With that hypothetical API, we could dynamically create a new named type
  296. // that has the same underlying type as MessageInfo.GoType, and
  297. // dynamically create methods that close over MessageInfo.
  298. // Since the new type would have the same underlying type, we could directly
  299. // convert between pointers of those types, giving us an efficient way to swap
  300. // out the method set.
  301. //
  302. // Barring the ability to dynamically create named types, the workaround is
  303. // 1. either to accept the cost of an allocation for this wrapper struct or
  304. // 2. generate more types and methods, at the expense of binary size increase.
  305. type messageDataType struct {
  306. p pointer
  307. mi *MessageInfo
  308. }
  309. type messageReflectWrapper messageDataType
  310. func (m *messageReflectWrapper) Descriptor() pref.MessageDescriptor {
  311. return m.mi.PBType.Descriptor()
  312. }
  313. func (m *messageReflectWrapper) New() pref.Message {
  314. return m.mi.PBType.New()
  315. }
  316. func (m *messageReflectWrapper) Interface() pref.ProtoMessage {
  317. if m, ok := m.ProtoUnwrap().(pref.ProtoMessage); ok {
  318. return m
  319. }
  320. return (*messageIfaceWrapper)(m)
  321. }
  322. func (m *messageReflectWrapper) ProtoUnwrap() interface{} {
  323. return m.p.AsIfaceOf(m.mi.GoType.Elem())
  324. }
  325. func (m *messageReflectWrapper) Len() (cnt int) {
  326. m.mi.init()
  327. for _, fi := range m.mi.fields {
  328. if fi.has(m.p) {
  329. cnt++
  330. }
  331. }
  332. return cnt + m.mi.extensionMap(m.p).Len()
  333. }
  334. func (m *messageReflectWrapper) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
  335. m.mi.init()
  336. for _, fi := range m.mi.fields {
  337. if fi.has(m.p) {
  338. if !f(fi.fieldDesc, fi.get(m.p)) {
  339. return
  340. }
  341. }
  342. }
  343. m.mi.extensionMap(m.p).Range(f)
  344. }
  345. func (m *messageReflectWrapper) Has(fd pref.FieldDescriptor) bool {
  346. if fi, xt := m.checkField(fd); fi != nil {
  347. return fi.has(m.p)
  348. } else {
  349. return m.mi.extensionMap(m.p).Has(xt)
  350. }
  351. }
  352. func (m *messageReflectWrapper) Clear(fd pref.FieldDescriptor) {
  353. if fi, xt := m.checkField(fd); fi != nil {
  354. fi.clear(m.p)
  355. } else {
  356. m.mi.extensionMap(m.p).Clear(xt)
  357. }
  358. }
  359. func (m *messageReflectWrapper) Get(fd pref.FieldDescriptor) pref.Value {
  360. if fi, xt := m.checkField(fd); fi != nil {
  361. return fi.get(m.p)
  362. } else {
  363. return m.mi.extensionMap(m.p).Get(xt)
  364. }
  365. }
  366. func (m *messageReflectWrapper) Set(fd pref.FieldDescriptor, v pref.Value) {
  367. if fi, xt := m.checkField(fd); fi != nil {
  368. fi.set(m.p, v)
  369. } else {
  370. m.mi.extensionMap(m.p).Set(xt, v)
  371. }
  372. }
  373. func (m *messageReflectWrapper) Mutable(fd pref.FieldDescriptor) pref.Value {
  374. if fi, xt := m.checkField(fd); fi != nil {
  375. return fi.mutable(m.p)
  376. } else {
  377. return m.mi.extensionMap(m.p).Mutable(xt)
  378. }
  379. }
  380. func (m *messageReflectWrapper) NewMessage(fd pref.FieldDescriptor) pref.Message {
  381. if fi, xt := m.checkField(fd); fi != nil {
  382. return fi.newMessage()
  383. } else {
  384. return xt.New().Message()
  385. }
  386. }
  387. func (m *messageReflectWrapper) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor {
  388. m.mi.init()
  389. if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
  390. return od.Fields().ByNumber(oi.which(m.p))
  391. }
  392. panic("invalid oneof descriptor")
  393. }
  394. func (m *messageReflectWrapper) GetUnknown() pref.RawFields {
  395. m.mi.init()
  396. return m.mi.getUnknown(m.p)
  397. }
  398. func (m *messageReflectWrapper) SetUnknown(b pref.RawFields) {
  399. m.mi.init()
  400. m.mi.setUnknown(m.p, b)
  401. }
  402. // checkField verifies that the provided field descriptor is valid.
  403. // Exactly one of the returned values is populated.
  404. func (m *messageReflectWrapper) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.ExtensionType) {
  405. m.mi.init()
  406. if fi := m.mi.fields[fd.Number()]; fi != nil {
  407. if fi.fieldDesc != fd {
  408. panic("mismatching field descriptor")
  409. }
  410. return fi, nil
  411. }
  412. if fd.IsExtension() {
  413. if fd.ContainingMessage().FullName() != m.mi.PBType.FullName() {
  414. // TODO: Should this be exact containing message descriptor match?
  415. panic("mismatching containing message")
  416. }
  417. if !m.mi.PBType.ExtensionRanges().Has(fd.Number()) {
  418. panic("invalid extension field")
  419. }
  420. return nil, fd.(pref.ExtensionType)
  421. }
  422. panic("invalid field descriptor")
  423. }
  424. type extensionMap map[int32]ExtensionField
  425. func (m *extensionMap) Len() int {
  426. if m != nil {
  427. return len(*m)
  428. }
  429. return 0
  430. }
  431. func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
  432. if m != nil {
  433. for _, x := range *m {
  434. xt := x.GetType()
  435. if !f(xt, xt.ValueOf(x.GetValue())) {
  436. return
  437. }
  438. }
  439. }
  440. }
  441. func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
  442. if m != nil {
  443. _, ok = (*m)[int32(xt.Number())]
  444. }
  445. return ok
  446. }
  447. func (m *extensionMap) Clear(xt pref.ExtensionType) {
  448. delete(*m, int32(xt.Number()))
  449. }
  450. func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
  451. if m != nil {
  452. if x, ok := (*m)[int32(xt.Number())]; ok {
  453. return xt.ValueOf(x.GetValue())
  454. }
  455. }
  456. if !isComposite(xt) {
  457. return defaultValueOf(xt)
  458. }
  459. return frozenValueOf(xt.New())
  460. }
  461. func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
  462. if *m == nil {
  463. *m = make(map[int32]ExtensionField)
  464. }
  465. var x ExtensionField
  466. x.SetType(xt)
  467. x.SetEagerValue(xt.InterfaceOf(v))
  468. (*m)[int32(xt.Number())] = x
  469. }
  470. func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
  471. if !isComposite(xt) {
  472. panic("invalid Mutable on field with non-composite type")
  473. }
  474. if x, ok := (*m)[int32(xt.Number())]; ok {
  475. return xt.ValueOf(x.GetValue())
  476. }
  477. v := xt.New()
  478. m.Set(xt, v)
  479. return v
  480. }
  481. func isComposite(fd pref.FieldDescriptor) bool {
  482. return fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind || fd.IsList() || fd.IsMap()
  483. }
  484. var _ pvalue.Unwrapper = (*messageReflectWrapper)(nil)
  485. type messageIfaceWrapper messageDataType
  486. func (m *messageIfaceWrapper) ProtoReflect() pref.Message {
  487. return (*messageReflectWrapper)(m)
  488. }
  489. func (m *messageIfaceWrapper) XXX_Methods() *piface.Methods {
  490. // TODO: Consider not recreating this on every call.
  491. m.mi.init()
  492. return &piface.Methods{
  493. Flags: piface.MethodFlagDeterministicMarshal,
  494. MarshalAppend: m.marshalAppend,
  495. Size: m.size,
  496. }
  497. }
  498. func (m *messageIfaceWrapper) ProtoUnwrap() interface{} {
  499. return m.p.AsIfaceOf(m.mi.GoType.Elem())
  500. }
  501. func (m *messageIfaceWrapper) marshalAppend(b []byte, _ pref.ProtoMessage, opts piface.MarshalOptions) ([]byte, error) {
  502. return m.mi.marshalAppendPointer(b, m.p, newMarshalOptions(opts))
  503. }
  504. func (m *messageIfaceWrapper) size(msg pref.ProtoMessage) (size int) {
  505. return m.mi.sizePointer(m.p, 0)
  506. }