Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(590)

Delta Between Two Patch Sets: src/pkg/encoding/gob/decode.go

Issue 6637047: code review 6637047: encoding/gob: fix data race in Register (Closed)
Left Patch Set: Created 11 years, 5 months ago
Right Patch Set: diff -r 5a8c4552dd85 https://code.google.com/p/go/ Created 11 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/encoding/gob/encode.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b