~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/gob/decode.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
)
18
18
 
19
19
var (
20
 
        errBadUint = os.ErrorString("gob: encoded unsigned integer out of range")
21
 
        errBadType = os.ErrorString("gob: unknown type id or corrupted data")
22
 
        errRange   = os.ErrorString("gob: bad data: field numbers out of bounds")
 
20
        errBadUint = os.NewError("gob: encoded unsigned integer out of range")
 
21
        errBadType = os.NewError("gob: unknown type id or corrupted data")
 
22
        errRange   = os.NewError("gob: bad data: field numbers out of bounds")
23
23
)
24
24
 
25
25
// decoderState is the execution state of an instance of the decoder. A new state
54
54
        dec.freeList = d
55
55
}
56
56
 
57
 
func overflow(name string) os.ErrorString {
58
 
        return os.ErrorString(`value for "` + name + `" out of range`)
 
57
func overflow(name string) os.Error {
 
58
        return os.NewError(`value for "` + name + `" out of range`)
59
59
}
60
60
 
61
61
// decodeUintReader reads an encoded unsigned integer from an io.Reader.
135
135
// The 'instructions' of the decoding machine
136
136
type decInstr struct {
137
137
        op     decOp
138
 
        field  int            // field number of the wire type
139
 
        indir  int            // how many pointer indirections to reach the value in the struct
140
 
        offset uintptr        // offset in the structure of the field to encode
141
 
        ovfl   os.ErrorString // error message for overflow/underflow (for arrays, of the elements)
 
138
        field  int      // field number of the wire type
 
139
        indir  int      // how many pointer indirections to reach the value in the struct
 
140
        offset uintptr  // offset in the structure of the field to encode
 
141
        ovfl   os.Error // error message for overflow/underflow (for arrays, of the elements)
142
142
}
143
143
 
144
144
// Since the encoder writes no zeros, if we arrive at a decoder we have
367
367
                p = *(*unsafe.Pointer)(p)
368
368
        }
369
369
        storeFloat32(i, state, p)
370
 
        storeFloat32(i, state, unsafe.Pointer(uintptr(p)+uintptr(unsafe.Sizeof(float32(0)))))
 
370
        storeFloat32(i, state, unsafe.Pointer(uintptr(p)+unsafe.Sizeof(float32(0))))
371
371
}
372
372
 
373
373
// decComplex128 decodes a pair of unsigned integers, treats them as a
552
552
}
553
553
 
554
554
// decodeArrayHelper does the work for decoding arrays and slices.
555
 
func (dec *Decoder) decodeArrayHelper(state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, elemIndir int, ovfl os.ErrorString) {
 
555
func (dec *Decoder) decodeArrayHelper(state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, elemIndir int, ovfl os.Error) {
556
556
        instr := &decInstr{elemOp, 0, elemIndir, 0, ovfl}
557
557
        for i := 0; i < length; i++ {
558
558
                up := unsafe.Pointer(p)
567
567
// decodeArray decodes an array and stores it through p, that is, p points to the zeroth element.
568
568
// The length is an unsigned integer preceding the elements.  Even though the length is redundant
569
569
// (it's part of the type), it's a useful check and is included in the encoding.
570
 
func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.ErrorString) {
 
570
func (dec *Decoder) decodeArray(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, length, indir, elemIndir int, ovfl os.Error) {
571
571
        if indir > 0 {
572
572
                p = allocate(atyp, p, 1) // All but the last level has been allocated by dec.Indirect
573
573
        }
579
579
 
580
580
// decodeIntoValue is a helper for map decoding.  Since maps are decoded using reflection,
581
581
// unlike the other items we can't use a pointer directly.
582
 
func decodeIntoValue(state *decoderState, op decOp, indir int, v reflect.Value, ovfl os.ErrorString) reflect.Value {
 
582
func decodeIntoValue(state *decoderState, op decOp, indir int, v reflect.Value, ovfl os.Error) reflect.Value {
583
583
        instr := &decInstr{op, 0, indir, 0, ovfl}
584
584
        up := unsafe.Pointer(unsafeAddr(v))
585
585
        if indir > 1 {
593
593
// Maps are encoded as a length followed by key:value pairs.
594
594
// Because the internals of maps are not visible to us, we must
595
595
// use reflection rather than pointer magic.
596
 
func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.ErrorString) {
 
596
func (dec *Decoder) decodeMap(mtyp reflect.Type, state *decoderState, p uintptr, keyOp, elemOp decOp, indir, keyIndir, elemIndir int, ovfl os.Error) {
597
597
        if indir > 0 {
598
598
                p = allocate(mtyp, p, 1) // All but the last level has been allocated by dec.Indirect
599
599
        }
616
616
 
617
617
// ignoreArrayHelper does the work for discarding arrays and slices.
618
618
func (dec *Decoder) ignoreArrayHelper(state *decoderState, elemOp decOp, length int) {
619
 
        instr := &decInstr{elemOp, 0, 0, 0, os.ErrorString("no error")}
 
619
        instr := &decInstr{elemOp, 0, 0, 0, os.NewError("no error")}
620
620
        for i := 0; i < length; i++ {
621
621
                elemOp(instr, state, nil)
622
622
        }
633
633
// ignoreMap discards the data for a map value with no destination.
634
634
func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) {
635
635
        n := int(state.decodeUint())
636
 
        keyInstr := &decInstr{keyOp, 0, 0, 0, os.ErrorString("no error")}
637
 
        elemInstr := &decInstr{elemOp, 0, 0, 0, os.ErrorString("no error")}
 
636
        keyInstr := &decInstr{keyOp, 0, 0, 0, os.NewError("no error")}
 
637
        elemInstr := &decInstr{elemOp, 0, 0, 0, os.NewError("no error")}
638
638
        for i := 0; i < n; i++ {
639
639
                keyOp(keyInstr, state, nil)
640
640
                elemOp(elemInstr, state, nil)
643
643
 
644
644
// decodeSlice decodes a slice and stores the slice header through p.
645
645
// Slices are encoded as an unsigned length followed by the elements.
646
 
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.ErrorString) {
 
646
func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl os.Error) {
647
647
        n := int(uintptr(state.decodeUint()))
648
648
        if indir > 0 {
649
649
                up := unsafe.Pointer(p)
741
741
 
742
742
// decodeGobDecoder decodes something implementing the GobDecoder interface.
743
743
// The data is encoded as a byte slice.
744
 
func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value, index int) {
 
744
func (dec *Decoder) decodeGobDecoder(state *decoderState, v reflect.Value) {
745
745
        // Read the bytes for the value.
746
746
        b := make([]byte, state.decodeUint())
747
747
        _, err := state.b.Read(b)
969
969
                } else {
970
970
                        v = reflect.ValueOf(unsafe.Unreflect(rcvrType, p))
971
971
                }
972
 
                state.dec.decodeGobDecoder(state, v, methodIndex(rcvrType, gobDecodeMethodName))
 
972
                state.dec.decodeGobDecoder(state, v)
973
973
        }
974
974
        return &op, int(ut.indir)
975
975
 
1064
1064
        engine.instr = make([]decInstr, 1) // one item
1065
1065
        name := rt.String()                // best we can do
1066
1066
        if !dec.compatibleType(rt, remoteId, make(map[reflect.Type]typeId)) {
1067
 
                return nil, os.ErrorString("gob: wrong type received for local value " + name + ": " + dec.typeString(remoteId))
 
1067
                return nil, os.NewError("gob: wrong type received for local value " + name + ": " + dec.typeString(remoteId))
1068
1068
        }
1069
1069
        op, indir := dec.decOpFor(remoteId, rt, name, make(map[reflect.Type]*decOp))
1070
 
        ovfl := os.ErrorString(`value for "` + name + `" out of range`)
 
1070
        ovfl := os.NewError(`value for "` + name + `" out of range`)
1071
1071
        engine.instr[singletonField] = decInstr{*op, singletonField, indir, 0, ovfl}
1072
1072
        engine.numInstr = 1
1073
1073
        return