Segmentation fault pushing three floats to a Stack

98 views
Skip to first unread message

André Matheus

unread,
Mar 8, 2016, 11:32:17 AM3/8/16
to ocaml-core
Hello,

I'm learning ocaml and was trying to implement an exercise from programming praxis using Core.
As I've used it, I've started to get segmentation faults. After some debugging it became clear the
problem is pushing more than three floats to a Stack. I can reproduce it on utop:

open Core.Std;;
let s = Stack.create();;
Stack.push s 1.0;;
Stack.push s 2.0;;
Stack.push s 3.0;;   <<-- at this point I get "Segmentation fault: 11"

Am I doing something wrong? Ocaml's Stack works fine, it's just Core's that give this problem.

I'm testing this on a Mac, running el captain 10.11.3. Ocaml 4.02.2. Core:

core                 113.24.02  Industrial strength alternative to OCaml's stand

core_kernel          113.24.00  Industrial strength alternative to OCaml's stand

ppx_core             113.24.00  Standard library for ppx rewriters


Creating a stack of ints works fine.

Thanks,

André

Arseniy Alekseyev

unread,
Mar 8, 2016, 11:48:12 AM3/8/16
to ocaml...@googlegroups.com
This is a hilariously simple bug description and I can actually reproduce this (so it's not a subtle mac-specific thing)... 
I love how you quoted "industrial strength" next to this bug report. :)
I'll investigate and it will probably be fixed.

--
You received this message because you are subscribed to the Google Groups "ocaml-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yaron Minsky

unread,
Mar 8, 2016, 1:42:39 PM3/8/16
to ocaml...@googlegroups.com

Ouch. That's deeply embarrassing.

y

Stanislav Artemkin

unread,
Mar 8, 2016, 1:55:31 PM3/8/16
to ocaml...@googlegroups.com
It seems the problem is in treating the array (tag 0) as a floating array (tag 254).

It literally does this:
let elts = [|Obj.magic();Obj.magic()|];;
elts.(0) <- 1.0;;
elts.(1) <- 2.0;;
elts;;
Segmentation fault: 11

Yaron Minsky

unread,
Mar 8, 2016, 3:44:20 PM3/8/16
to ocaml...@googlegroups.com
This is a poor excuse for a fix (we're working on that too), but you
can use Linked_stack, which has the same API but a different
implementation that is not exposed to this bug. (It also has
different performance characteristics.)

y

André Matheus

unread,
Mar 9, 2016, 9:22:11 AM3/9/16
to ocaml-core
Hi all,

Thanks for all the prompt replies.
I've replaced Stack with Linked_stack and it worked, thanks Yaron.

Arseniy, when I've wrote the email I didn't meant to quote "industrial strength"
as irony or anything, I was just lazy to type the versions and copy pasted them
from the terminal, sorry if it sounded snarky.

If there's anything else I can do to help with solving it please let me know.
Reply all
Reply to author
Forward
0 new messages