LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package gob | 5 package gob |
6 | 6 |
7 // TODO(rsc): When garbage collector changes, revisit | 7 // TODO(rsc): When garbage collector changes, revisit |
8 // the allocations in this file that use unsafe.Pointer. | 8 // the allocations in this file that use unsafe.Pointer. |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 if indir > 0 { | 710 if indir > 0 { |
711 p = allocate(ityp, p, 1) // All but the last level has b
een allocated by dec.Indirect | 711 p = allocate(ityp, p, 1) // All but the last level has b
een allocated by dec.Indirect |
712 } | 712 } |
713 *(*[2]uintptr)(unsafe.Pointer(p)) = ivalue.InterfaceData() | 713 *(*[2]uintptr)(unsafe.Pointer(p)) = ivalue.InterfaceData() |
714 return | 714 return |
715 } | 715 } |
716 if len(name) > 1024 { | 716 if len(name) > 1024 { |
717 errorf("name too long (%d bytes): %.20q...", len(name), name) | 717 errorf("name too long (%d bytes): %.20q...", len(name), name) |
718 } | 718 } |
719 // The concrete type must be registered. | 719 // The concrete type must be registered. |
720 » registerLock.Lock() | 720 » registerLock.RLock() |
721 typ, ok := nameToConcreteType[name] | 721 typ, ok := nameToConcreteType[name] |
722 » registerLock.Unlock() | 722 » registerLock.RUnlock() |
723 if !ok { | 723 if !ok { |
724 errorf("name not registered for interface: %q", name) | 724 errorf("name not registered for interface: %q", name) |
725 } | 725 } |
726 // Read the type id of the concrete value. | 726 // Read the type id of the concrete value. |
727 concreteId := dec.decodeTypeSequence(true) | 727 concreteId := dec.decodeTypeSequence(true) |
728 if concreteId < 0 { | 728 if concreteId < 0 { |
729 error_(dec.err) | 729 error_(dec.err) |
730 } | 730 } |
731 // Byte count of value is next; we don't care what it is (it's there | 731 // Byte count of value is next; we don't care what it is (it's there |
732 // in case we want to ignore the value by skipping it completely). | 732 // in case we want to ignore the value by skipping it completely). |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 return x.UnsafeAddr() | 1293 return x.UnsafeAddr() |
1294 } | 1294 } |
1295 | 1295 |
1296 // Gob depends on being able to take the address | 1296 // Gob depends on being able to take the address |
1297 // of zeroed Values it creates, so use this wrapper instead | 1297 // of zeroed Values it creates, so use this wrapper instead |
1298 // of the standard reflect.Zero. | 1298 // of the standard reflect.Zero. |
1299 // Each call allocates once. | 1299 // Each call allocates once. |
1300 func allocValue(t reflect.Type) reflect.Value { | 1300 func allocValue(t reflect.Type) reflect.Value { |
1301 return reflect.New(t).Elem() | 1301 return reflect.New(t).Elem() |
1302 } | 1302 } |
LEFT | RIGHT |