Skip to content

Commit 3416a3d

Browse files
committed
Internal change.
PiperOrigin-RevId: 390318725
1 parent 96459f5 commit 3416a3d

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

pkg/safemem/io.go

-52
Original file line numberDiff line numberDiff line change
@@ -207,58 +207,6 @@ func (r FromIOReader) readToBlock(dst Block, buf []byte) (int, []byte, error) {
207207
return wbn, buf, rerr
208208
}
209209

210-
// FromIOReaderAt implements Reader for an io.ReaderAt. Does not repeatedly
211-
// invoke io.ReaderAt.ReadAt because ReadAt is more strict than Read. A partial
212-
// read indicates an error. This is not thread-safe.
213-
type FromIOReaderAt struct {
214-
ReaderAt io.ReaderAt
215-
Offset int64
216-
}
217-
218-
// ReadToBlocks implements Reader.ReadToBlocks.
219-
func (r FromIOReaderAt) ReadToBlocks(dsts BlockSeq) (uint64, error) {
220-
var buf []byte
221-
var done uint64
222-
for !dsts.IsEmpty() {
223-
dst := dsts.Head()
224-
var n int
225-
var err error
226-
n, buf, err = r.readToBlock(dst, buf)
227-
done += uint64(n)
228-
if n != dst.Len() {
229-
return done, err
230-
}
231-
dsts = dsts.Tail()
232-
if err != nil {
233-
if dsts.IsEmpty() && err == io.EOF {
234-
return done, nil
235-
}
236-
return done, err
237-
}
238-
}
239-
return done, nil
240-
}
241-
242-
func (r FromIOReaderAt) readToBlock(dst Block, buf []byte) (int, []byte, error) {
243-
// io.Reader isn't safecopy-aware, so we have to buffer Blocks that require
244-
// safecopy.
245-
if !dst.NeedSafecopy() {
246-
n, err := r.ReaderAt.ReadAt(dst.ToSlice(), r.Offset)
247-
r.Offset += int64(n)
248-
return n, buf, err
249-
}
250-
if len(buf) < dst.Len() {
251-
buf = make([]byte, dst.Len())
252-
}
253-
rn, rerr := r.ReaderAt.ReadAt(buf[:dst.Len()], r.Offset)
254-
r.Offset += int64(rn)
255-
wbn, wberr := Copy(dst, BlockFromSafeSlice(buf[:rn]))
256-
if wberr != nil {
257-
return wbn, buf, wberr
258-
}
259-
return wbn, buf, rerr
260-
}
261-
262210
// FromIOWriter implements Writer for an io.Writer by repeatedly invoking
263211
// io.Writer.Write until it returns an error or partial write.
264212
//

tools/go_stateify/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,12 @@ func main() {
362362
fmt.Fprintf(outputFile, " stateSourceObject.LoadWait(%d, &%s.%s)\n", fields[name], recv, name)
363363
}
364364
emitSaveValue := func(name, typName string) {
365-
fmt.Fprintf(outputFile, " var %sValue %s = %s.save%s()\n", name, typName, recv, camelCased(name))
365+
// Emit typName to be more robust against code generation bugs,
366+
// but instead of one line make two lines to silence ST1023
367+
// finding (i.e. avoid nogo finding: "should omit type $typName
368+
// from declaration; it will be inferred from the right-hand side")
369+
fmt.Fprintf(outputFile, " var %sValue %s\n", name, typName)
370+
fmt.Fprintf(outputFile, " %sValue = %s.save%s()\n", name, recv, camelCased(name))
366371
fmt.Fprintf(outputFile, " stateSinkObject.SaveValue(%d, %sValue)\n", fields[name], name)
367372
}
368373
emitSave := func(name string) {

0 commit comments

Comments
 (0)