summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-01-13 12:06:43 +1100
committerRob Pike <r@golang.org>2010-01-13 12:06:43 +1100
commit784032618f229fdf60b3fc75d30450252aea285c (patch)
treed9f4bb44454fc6ae65d1442ef0631bddf4a77524
parent0d5719aabb729ef736f60d28db966f723ede3430 (diff)
downloadgolang-784032618f229fdf60b3fc75d30450252aea285c.tar.gz
to improve the chances for compatibility, open a window of unused ids
and specify a lowest id granted to users. R=rsc CC=golang-dev http://codereview.appspot.com/186081
-rw-r--r--src/pkg/gob/type.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/pkg/gob/type.go b/src/pkg/gob/type.go
index 2ffdfc6a1..ace80d6ad 100644
--- a/src/pkg/gob/type.go
+++ b/src/pkg/gob/type.go
@@ -37,6 +37,7 @@ type typeId int32
var nextId typeId // incremented for each new type we build
var typeLock sync.Mutex // set while building a type
+const firstUserId = 64 // lowest id number granted to user
type gobType interface {
id() typeId
@@ -101,6 +102,7 @@ var tString = bootstrapType("string", "", 6)
var tWireType = mustGetTypeInfo(reflect.Typeof(wireType{})).id
func init() {
+ // Some magic numbers to make sure there are no surprises.
checkId(7, tWireType)
checkId(9, mustGetTypeInfo(reflect.Typeof(commonType{})).id)
checkId(11, mustGetTypeInfo(reflect.Typeof(structType{})).id)
@@ -109,6 +111,12 @@ func init() {
for k, v := range idToType {
builtinIdToType[k] = v
}
+ // Move the id space upwards to allow for growth in the predefined world
+ // without breaking existing files.
+ if nextId > firstUserId {
+ panicln("nextId too large:", nextId)
+ }
+ nextId = firstUserId
}
// Array type