brenhinkeller / StaticTools.jl

Enabling StaticCompiler.jl-based compilation of (some) Julia code to standalone native binaries by avoiding GC allocations and llvmcall-ing all the things!
MIT License
168 stars 12 forks source link

readline #59

Open Thomas008 opened 4 months ago

Thomas008 commented 4 months ago

readline()does not seem to read the first character in the first line of a file, and not the first two charachters from the second line on.

brenhinkeller commented 4 months ago

Hmm, do you have an MWI -- which os, etc.?

Thomas008 commented 4 months ago

I'm using StaticCompiler on Windows (I adapted it to Windows), and Julia 1.10. Maybe this error is windows-specific. Perhaps someone could just check this on Linux. The code is simply:

using StaticTools
fn = m"test.txt"
mode = m"r"
fp = fopen(fn, mode)
str = readline(fp)
str = readline(fp)
fclose(fp)
free(str)
brenhinkeller commented 2 months ago

Hmm, I can't reproduce on Mac, so I suspect this is mostly likely be a Windows issue.

julia> using StaticTools

julia> fn = m"test.txt"
m"test.txt"

julia> mode = m"r"
m"r"

julia> fp = fopen(fn, mode)
Ptr{StaticTools.FILE} @0x0000000205e7e8a0

julia> str = readline(fp)
m"This is a test file!"

julia> str = readline(fp)
m"Here is the second line."

julia> fclose(fp)
0

julia> free(str)
0

Windows support is currently unofficial, but I'll continue to merge PRs if anyone who has a Windows machine to work on and does need/want it wants to make PRs