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

segfault with let rec defined structure #3740

Closed
vicuna opened this issue Aug 1, 2005 · 1 comment
Closed

segfault with let rec defined structure #3740

vicuna opened this issue Aug 1, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Aug 1, 2005

Original bug ID: 3740
Reporter: administrator
Status: closed (set by @xavierleroy on 2006-06-17T10:45:36Z)
Resolution: unable to duplicate
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Florian Hars
Version: 3.08.3 (from godi)
OS: linux/amd64
Submission from: dialin-145-254-038-023.arcor-ip.net (145.254.38.23)

These things always happen on the last day before the vacation, when
the prototype must definitely work and you have no time to find a
minimal example...

I am writing a cgi program, which contains code like the following
(only more complicated, ix is really a struct containing among other
things a Netcgi.cgi_activation and a Postgresql.connection. cols
contains records, not just simple strings and table
has far more fields (16)). Parts use the same function in place of the
do_something in the example (camlTable__save_show in the backtrace
below) with different tables. All parts have worked during various
stages of development, some work even now, but in some places I get a
segfault after the program writes AA to stderr.

type table = {
txt: string;
do_it: int -> string -> unit;
cols: string array;
}

let do_something t ix s =
prerr_endline "AA";
let n = Array.length t.cols in
prerr_endline "BB";
Printf.printf "%s\n" t.txt;
for i = 0 to n - 1 do
Printf.printf "%d %d %s %s\n" ix i t.cols.(i) s
done

let rec t0 = {
txt = "Foo";
do_it = (fun ix s -> do_something t0 ix s);
cols = [| "a"; "b"; "c" |];
}

let rec t = {
t0 with
do_it = (fun ix s -> do_something t ix s);
cols = [| "A"; "B";|];
}

let _ =
t.do_it 1 "s"

Here is a part of the apache logfile I get if I wrap my program in a
skript that calls it through gdb -batch:


AA

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 182915746208 (LWP 11161)]
0x0000000000419434 in camlTable__save_391 ()
#0 0x0000000000419434 in camlTable__save_391 ()
#1 0x0000000000000000 in ?? ()
#2 0x00000000004d2b74 in caml_flush ()
#3 0x00000000004d338e in caml_ml_flush ()
#4 0x0000000000000000 in ?? ()
#5 0x0000002a96a4c980 in ?? ()
#6 0x0000000000419743 in camlTable__save_show_403 ()
#7 0x0000002a96a4b2c0 in ?? ()
#8 0x0000000000000000 in ?? ()
#9 0x0000002a96a4c980 in ?? ()

Same thing if I compile to bytecode:

AA

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 182917156976 (LWP 11770)]
0x0000000000428b28 in caml_interprete ()
#0 0x0000000000428b28 in caml_interprete ()
#1 0x000000000042a772 in caml_main ()
#2 0x000000000041a268 in main ()

In one case, the working version is

let rec table' = {
table with
save = (fun rq x_id -> save_user {table with cols=cols'} rq x_id);
}

while this segfaults:

let rec table' = {
table with
save = (fun rq x_id -> save_user table' rq x_id);
cols=cols'
}

I can live with the extra allocation on every invocation of
table'.save to get things running, but it is a bit annoying.

@vicuna
Copy link
Author

vicuna commented Sep 24, 2005

Comment author: administrator

see also #3743. Submitted code fragment doesn't reproduce crash. Suspect
problem is elsewhere in the user's code. Need repro case.

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