Comments (5)
@Casper64 I am not sure if you can investigate or not.
from v.
The read
method should only be used if a io.reader
instance is passed when creating a new StringReader
.
That's confusing, it should be possible to use the read
method seperately. 👍
from v.
Sorry, to come back at this:
In your example you pass in a buffer of lenght 100
. If you call read
the stringreader will attempt to read 100 bytes. The given source is only 4 bytes long, so then the code tries to read from the io.reader
contained in it, but that is not set, there is no data and the method returns an error.
To me this makes sense, but the error message doesn't.
I think in this case the method should return the io.Eof
error. What do you think @thomas-mangin ?
from v.
Hi @Casper64, and thank you for answering.
You are right: I messed up my minimum viable example; my buffer length should have been smaller than the string length.
In the case above, if only 14 bytes were read, the function should return 14 and the next call should return Eof. I believe this is the expected behaviour of the function in the C language and what people would expect.
As the above buffer is 100, then either another system call to the OS is required to read more than 14 bytes (for networking, the data may still be in transit) or only 14 bytes are available. The next call would then return Eof.
The problem with the reader not getting set is still there with a small buffer size as you can see below where the buffer length is 4.
module main
import io.string_reader
fn main() {
s := 'line 1\nline 2\n'
// works
mut r := string_reader.StringReader.new(source: s)
assert r.read_all(false)! == s
// fails
mut b := []u8{len: 4}
mut sr := string_reader.StringReader.new(source: s)
sr.read(mut b)!
}
❯ v run bug.v
V panic: result not set (reader is not set)
v hash: df7828d
0 bug 0x0000000104a76838 panic_result_not_set + 124
1 bug 0x0000000104a8d650 main__main + 1000
2 bug 0x0000000104a8d95c main + 84
3 dyld 0x000000018ebe60e0 start + 2360
from v.
That will be fixed. When the length of the buffer is smaller or equal to the length of the provided source the string reader will read from that source always, regardless of whether a reader is set or not.
from v.
Related Issues (20)
- Build error - undeclared varaible HOT 6
- v -prod for iui throws error HOT 1
- mut and & confusion HOT 4
- Compiler build error: cannot convert 'struct main__Object' to 'struct main__Object * HOT 3
- cgen error for program compiled with -autofree
- Array in closure not updated HOT 1
- Windows: coroutines should display a message that they don't work on Windows, instead of complaining about photonwrapper.so not found HOT 1
- error using `@[flag]` in `vlib/flag/flag.v`
- cgen error, when example is compiled with -autofree HOT 1
- [builder error] match + &
- Unhandled Exception 0xC0000005 HOT 1
- i tried the compile simple sdl window file from sdl example, it shows this error HOT 3
- cgen error: '__v_error' undeclared HOT 1
- anonymous struct embedding lacks checks
- How to obtain generic results using the following function? HOT 2
- string interpolation does not correctly reports pointer when used with maps
- carray_to_varray inside unsafe block warns about requiring an unsafe block
- Bug while practicing copying the concurrency examples
- C Error building lsv with -skip-unused
- cgen error in auto generated str() method of an enum with duplicate enum keys
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v.