Skip to content
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

core dump using a hashtable #2442

Closed
vicuna opened this issue May 8, 2000 · 2 comments
Closed

core dump using a hashtable #2442

vicuna opened this issue May 8, 2000 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented May 8, 2000

Original bug ID: 104
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name:
Version: applies to all
OS: solaris, linux
Submission from: reichenau.gmd.de (129.26.12.135)

I attach an OCAML programm causing a core dump at laest in versions 2.01 -
3.00.
The program is non-sense, but the core-dump should not be the answer to that
:-)

(* of course, this program is non-sense. I know, that it's silly to use
structural equality for mutable data structures. It is an extract from
an ill-designed name-space-manager.It should compute non-sense,
BUT IT EFFECTS A CORE-DUMP.

reinhard.budde@gmd.de

Run of this file "hbl.ml":

L/ml/Error 16> ocaml
Objective Caml version 2.01

#use "hbl.ml";;

type htlky = | Leaf of int | Node of htlsky
type htlsky = { mutable k1: htlky; mutable k2: int }
val rm_node : htlky -> htlsky =
val v1 : htlky = Node {k1=Node {k1=Leaf 0; k2=5}; k2=8}
val v2 : htlky =
Node {k1=Node {k1=Node {k1=Node {k1=Leaf 0; k2=5}; k2=8}; k2=5}; k2=9}
type htblt = (htlky, int) Hashtbl.t
val ht : htblt =
val tst : unit -> unit =

tst();;

give 2: 2
give 3: 3
got: Not_found
got: Not_found
Segmentation fault
L/ml/Error 17>

*)

type htlky =
| Leaf of int
| Node of htlsky

and htlsky =
{ mutable k1 : htlky;
mutable k2 : int
}

let rm_node = function
| Node n -> n
| _ -> raise (Failure "Leaf instead of Node!")

let v1 = Node { k1=Node {k1=Leaf 0;k2=5};k2=8 }
let v2 = Node { k1=Node {k1=v1;k2=5};k2=9 }

type htblt = (htlky, int) Hashtbl.t

let ht = ( Hashtbl.create 47 : htblt )

let tst () =
Hashtbl.add ht v1 2;
print_string "give 2: "; print_int (Hashtbl.find ht v1); print_newline ();
Hashtbl.add ht v2 3;
print_string "give 3: "; print_int (Hashtbl.find ht v2); print_newline ();

for i = 1 to 100 do
  try
    let n = rm_node (rm_node v1).k1 in
        n.k1 <- v2;
        n.k2 <- n.k2+1;
        print_string "got: "; print_int (Hashtbl.find ht v1);
        print_newline ()
  with e ->
    print_string (Printexc.to_string e); print_newline ()
done
@vicuna
Copy link
Author

vicuna commented May 8, 2000

Comment author: administrator

Thanks for the bug report.

I attach an OCAML programm causing a core dump at laest in
versions 2.01 - 3.00.
The program is non-sense, but the core-dump should not be the answer
to that :-)

On my machine, it says "stack overflow" just before "segmentation
fault".

It comes from the fact that the Hashtbl module uses polymorphic
equality to compare keys, and polymorphic equality doesn't handle
circular data structures (and your hash keys are circular data
structures).

There's no easy solution to this problem. Maybe someday we'll enhance
the equality primitive to handle all data, but don't hold your breath.

In the meantime, we'll add a note to the documentation of Hashtbl.

-- Damien

@vicuna
Copy link
Author

vicuna commented Jan 12, 2001

Comment author: administrator

Fixed in OCaml 3.01: the new equality code raises cleanly "Out_of_memory" when
it overflows the stack. - Xavier.

@vicuna vicuna closed this as completed Jan 12, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant