BTW, I have a csv parser mostly for my own use:

https://www.npmjs.com/package/atscntrb-hx-csv-parse


On Thursday, March 2, 2017 at 5:04:35 PM UTC-5, August Alm wrote:
>
> Hi!
>
> I'm in over my head and tried writing a CSV-parser using linear lazy 
> streams. My code thus far is 600 lines and almost to my own surprise I get 
> it to compile! However, there is something fishy because I get a segfault 
> when applying my program to an actual CSV-file. I've been trying to debug 
> using gdb but the fault eludes me. Since I don't expect anyone to mull 
> through 600 lines of code, I am hoping these code snippets are enough for 
> one of you guys to give me some advice.
>
> This code executes just fine:
>
>         implement main0 () = {
>            
>            val test = stream_vt_make_cons(
>                             'a', stream_vt_make_cons(
>                                     ';', 
> stream_vt_make_sing('b')))          (* the stream ('a', ';', 'b') *)
>            val lexed = lex_csv(true, ';', test)
>            val h = (lexed.head())
>            val- CSV_Field(r) = h
>            val a = r.csvFieldContent
>            val () = println!(a)
>          
>          }
>
> Here [lex_csv] is my 600-line alogrithm. It reads a [stream_vt(char)] and 
> gives back a [stream_vt(CSVEntry)], where [CSVEntry] is a record type, one 
> of whose fields is [CSVFieldContent]. When executing the program I get "a" 
> printed to the console.
>
> This code results in a segfault:
>
>         implement main0 () = {
>         
>            val inp = fileref_open_exn("small.csv", file_mode_r)
>            val ins = streamize_fileref_char(inp)
>            val lexed = lex_csv(true, ';', ins)
>            val () = fileref_close(inp)
>            val h = (lexed.head())
>            val- CSV_Field(r) = h
>            val a = r.csvFieldContent
>            val () = println!(a)
>          
>          }
>
> The file "small.csv" only contains the string "a;b". Hence I would expect 
> this code to give the result as the previous one! But, it doesn't just 
> return something else, it segfaults.
>
> gdb indicates there is a malloc problem having to do with 
> "GC_clear_stack_inner", in case that's helpful. (I'm a mathematician who 
> recently left academia after postdoc and decided to teach myself 
> programming to become more useful outside of academia; hence I understand 
> type systems and the like--the mathy stuff--a lot better than I understand 
> memory allocation and other stuff that most programmers are supposed to be 
> confident with.)
>
> What could be the problem here?
>
> Best wishes,
> August
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To post to this group, send email to ats-lang-users@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/addbc044-096b-4ea7-91ac-7f997322b853%40googlegroups.com.

Reply via email to