Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000104OCamlOCaml generalpublic2000-05-08 17:022001-01-12 11:38
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000104: core dump using a hashtable
DescriptionFull_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 = <fun>
   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 = <abstr>
   val tst : unit -> unit = <fun>
   # 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

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000379)
administrator (administrator)
2000-05-08 19:37

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

(0000380)
administrator (administrator)
2001-01-12 11:38

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

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker