-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
readFile implementation in Prelude.File partially broken with binary files #4352
Comments
I think Idris-dev/libs/prelude/Prelude/File.idr Lines 205 to 206 in 5eb8f83
Idris-dev/libs/prelude/Prelude/File.idr Lines 160 to 162 in 5eb8f83
Lines 138 to 140 in 24f580d
Idris-dev/libs/prelude/Builtins.idr Line 200 in cc7ef9a
The following two belong together: Idris-dev/src/Idris/Core/Execute.hs Line 495 in f92ecd2
Idris-dev/src/Idris/Core/Execute.hs Lines 537 to 540 in f92ecd2
Idris-dev/src/IRTS/CodegenC.hs Lines 630 to 632 in a4c183c
Line 405 in 14f10fd
Lines 645 to 659 in 14f10fd
|
All of a sudden I'm having trouble replicating my original issue on an unmodified branch, so I guess I have to come up with an actual test case. |
Test case for compiled:
Notice the truncation at the first null character.
|
It has been brought to my attention that |
Also note that primitives can’t take or return values of non-primitive types, and that the C FFI also only supports a limited range of types which doesn’t include pairs, so neither can return a pair. |
@22459 A solution would be to return a pointer to a C struct, and provide methods to access the string and number of read bytes. |
@Melvar Yeah I seem to have run into that problem when I couldn't figure out how to return a tuple. :) If I have time I'll try to poke at this on and off a bit the next few days... |
Why cant primitives return nonprimitives? |
Thanks for reporting the issue. @22459 Primtives can not return non-primitives, because I believe this is a bootstrapping issue. |
The current implementation uses
addToStringBuffer
to concatenate a read file chunk to a buffer.Explicit length parameters seem to be used almost everywhere(?), however not for
addToStringBuffer
,which uses C
strlen
in the underlying implementation to deduce the length of the concatenee.strlen
uses C style strings, resulting in truncation of the read chunk at null characters.Proposal: require an explicit length parameter for
idris_addToString
Idris-dev/libs/prelude/Prelude/File.idr
Line 273 in 5eb8f83
Idris-dev/libs/prelude/Prelude/Strings.idr
Lines 57 to 59 in e019840
Idris-dev/src/Idris/Core/Execute.hs
Lines 441 to 449 in f92ecd2
Idris-dev/rts/idris_stdfgn.h
Line 37 in 5eb8f83
Idris-dev/rts/idris_stdfgn.c
Lines 206 to 212 in a4c183c
A more grand proposal?: Should Idris globally switch to netstring style strings instead of C strings? I don't know how pervasive things like this are.
The text was updated successfully, but these errors were encountered: