Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Segfault in a native code multi-threaded program
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-08-21 (19:20)
From: John Max Skaller <skaller@m...>
Subject: Re: [Caml-list] Segfault in a native code program using pm variants
I hope it's not catching. Just after reproducing
David Mentre's segfault, now I'm getting one in my code too ;-)

Data: Ocaml 3.02, Linux on PIII 550E, i86 native code compiler, compiled
with pthreads
enabled. I am using the bignum module, but no threads, no magic, no
no special integer types, no floats, and no non-standard modules. 
The application is the Felix compiler.
Parsing and desugaring passes have run (correctly, as far as I can tell)

Noramlly, I'd suspect an infinite recursion, 
(the code is very recursive, and I actually _expected_ it)
but it happens very quickly without disk thrashing (I'm running as
and all attempts to trace the recursion using prints
have failed (so far). I've just got this code to compile
after a significant rewrite in which I also switched
almost all variant usage to polymorphic variants.

What I am seeing, however, is an incorrect match using polymorphic
variants: here's the debugging output:

typeofindex finds declaration proc print: int = "printf(\"%d\",$1);";
Found var
:--->declaration proc print: int = "printf(\"%d\",$1);";

That 'found var' comes from 

and typeofindex 
  (counter:int ref)
  (exclude:int list)
  (excluded_dirs:int list)
: btypecode_t = 
  let bt t:btypecode_t = 
    print_endline ("TYPEOFINDEX binding type " ^ string_of_typecode t);
    flush stdout;
    let t' = bind_type dfns counter freg env (index::exclude)
excluded_dirs sr t in
    print_endline "TYPE BOUND";
    print_endline ("typeofindex finds " ^ string_of_symdef entry id);
    flush stdout;
  match entry with

  | `SYMDEF_dcl (`DCL_var t) -> 
    print_endline "Found var";
    print_endline (":--->" ^ string_of_symdef entry id);
    flush stdout;
    bt t

but the print routine looks like:
and string_of_symdef entry name = match entry with
   | `SYMDEF_dcl d ->
    "declaration " ^ string_of_dcl 0 name d

and string_of_dcl level name s = 
  let se e = string_of_expr e in
  match s with
  | `DCL_proc (args, code) ->
    spaces level ^ 
    "proc " ^ name ^ ": " ^ 
     (string_of_typecode (type_of_argtypes args)) ^
     " = " ^ string_of_string code ^ ";"
  | `DCL_var (ty) ->
    spaces level ^ 
    "var " ^ name ^ ": " ^ string_of_typecode ty ^ ";"

The diagnostic listed is the last thing I see before the segfault.
The next call, 

	bt t

should have executed:

    print_endline ("TYPEOFINDEX binding type " ^ string_of_typecode t);
    flush stdout;

but hasn't. It would probably have crashed if it did,
since the type of the variant being passed is wrong.
(Did it crash forming the closure?)

The routine, is, in fact, analysing the "proc print" entry,
so the diagnostic output is correct, and it's the match
in the 'typeofindex' routine that is failing.

I've submitted a bug report, but bugs in Ocaml are rare enough
for me to still believe it is possible that I'm doing something
wrong -- but I have no idea what to try next. The source is
too large for a bug report, and I haven't been able to
reproduce the problem with a tiny test case involving
nested PM variants. It's possible that my problem
is related to Davids (and has nothing to do with PM variants,
which David is not using). As far as I can remember,
my code built fine using 3.01, but it has been rewritten
in the last few weeks: and I installed 3.02 on Aug 4.

John (Max) Skaller, 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix
Literate Programming tool Interscript
Bug reports:  FAQ:
To unsubscribe, mail  Archives: