Skip to content

Commit 2c69ee4

Browse files
author
Pietro Abate
committed
Fix stack overflow caused by very long conlicts chains
this patch fiddle with the edosSolver. The list of reasons are now appended without considering the order to limit the depth of the recursion stack when the two lists are too big.
1 parent 30ee1c6 commit 2c69ee4

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ DIST_TARBALL = $(DIST_DIR).tar.gz
1010
#VERBOSE := -classic-display
1111
OBFLAGS := $(VERBOSE) -j 10 -no-links -cflags -warn-error,FPSXY
1212
APPFLAGS := $(VERBOSE) -j 10
13-
#OBFLAGS := $(OBFLAGS) -tag profile -tag debug
13+
#OBFLAGS := $(OBFLAGS) -tag debug
14+
#OBFLAGS := $(OBFLAGS) -tag profile
1415
#OBFLAGS := $(OBFLAGS) -classic-display
1516

1617
addnotrpm:

algo/depsolver.ml

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ let label = __label ;;
1919
include Util.Logging(struct let label = label end) ;;
2020

2121
type solver = Depsolver_int.solver
22+
let timer_solver = Util.Timer.create "Algo.Depsolver.solver"
23+
let timer_init = Util.Timer.create "Algo.Depsolver.init"
2224

2325
let load ?(global_constraints=[]) universe =
2426
let global_constraints =
@@ -35,14 +37,15 @@ let load ?(global_constraints=[]) universe =
3537
*)
3638
let univcheck ?(global_constraints=[]) ?callback ?(explain=true) universe =
3739
let aux ?callback univ =
38-
let timer = Util.Timer.create "Algo.Depsolver.univcheck" in
39-
Util.Timer.start timer;
4040
let global_constraints =
4141
List.map (fun (vpkg,l) ->
4242
(vpkg,List.map (CudfAdd.pkgtoint universe) l)
4343
) global_constraints
4444
in
45+
Util.Timer.start timer_init;
4546
let solver = Depsolver_int.init_solver_univ ~global_constraints ~explain univ in
47+
Util.Timer.stop timer_init ();
48+
Util.Timer.start timer_solver;
4649
let failed = ref 0 in
4750
(* This is size + 1 because we encode the global constraint of the
4851
* universe as a package that must be tested like any other *)
@@ -53,7 +56,7 @@ let univcheck ?(global_constraints=[]) ?callback ?(explain=true) universe =
5356
(* we do not test the last package that encodes the global constraints
5457
* on the universe as it is tested all the time with all other packages. *)
5558
for id = 0 to size - 2 do if not(check id) then incr failed done;
56-
Util.Timer.stop timer !failed
59+
Util.Timer.stop timer_solver !failed
5760
in
5861
let map = new Common.Util.identity in
5962
match callback with
@@ -76,19 +79,21 @@ let listcheck ?(global_constraints=[]) ?callback ?(explain=true) universe pkglis
7679
(vpkg,List.map (CudfAdd.pkgtoint universe) l)
7780
) global_constraints
7881
in
82+
Util.Timer.start timer_init;
7983
let solver = Depsolver_int.init_solver_univ ~global_constraints ~explain univ in
80-
let timer = Util.Timer.create "Algo.Depsolver.listcheck" in
81-
Util.Timer.start timer;
84+
Util.Timer.stop timer_init ();
85+
Util.Timer.start timer_solver;
8286
let failed = ref 0 in
8387
let size = (Cudf.universe_size univ) + 1 in
8488
let tested = Array.make size false in
8589
Util.Progress.set_total Depsolver_int.progressbar_univcheck size ;
8690
let check = Depsolver_int.pkgcheck callback explain solver tested in
8791
List.iter (function
88-
|id when id = solver.Depsolver_int.globalid -> ()
92+
|id when solver.Depsolver_int.globalid = None ||
93+
(Option.get solver.Depsolver_int.globalid) = id -> ()
8994
|id -> if not(check id) then incr failed
9095
) idlist ;
91-
Util.Timer.stop timer !failed
96+
Util.Timer.stop timer_solver !failed
9297
in
9398
let idlist = List.map (CudfAdd.pkgtoint universe) pkglist in
9499
let map = new Common.Util.identity in

applications/distcheck.ml

-13
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,6 @@ let main () =
240240
let nbp =
241241
if (OptParse.Opt.is_set Options.checkonly) && (List.length checklist) = 0 then 0
242242
else if OptParse.Opt.is_set Options.checkonly || not(bg_pkglist = []) then
243-
(*
244-
let subuniverse =
245-
let l =
246-
Cudf.fold_packages (fun acc pkg ->
247-
match pkg.Cudf.keep with
248-
|`Keep_package |`Keep_version | `Keep_feature
249-
when pkg.Cudf.installed -> pkg::acc
250-
|_ -> acc
251-
) checklist universe
252-
in
253-
Cudf.load_universe (CudfAdd.cone universe l)
254-
in
255-
*)
256243
Depsolver.listcheck ~global_constraints ~callback ~explain universe checklist
257244
else
258245
univcheck ~global_constraints ~callback ~explain universe

applications/outdated.ml

+7-9
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ let version_of_target getv = function
9292
|`Lo v |`In (_,v) -> (getv v) - 1
9393
;;
9494

95-
let timer = Util.Timer.create "Solver"
96-
9795
(* the repository should contain only the most recent version of each
9896
package *)
9997
let future ~options ?(checklist=[]) repository =
@@ -273,17 +271,16 @@ let outdated
273271
let results = Diagnostic.default_result universe_size in
274272
let callback d =
275273
if summary then Diagnostic.collect results d ;
276-
Diagnostic.fprintf ~pp ~failure ~explain fmt d
274+
if failure then
275+
Diagnostic.fprintf ~pp ~failure ~explain fmt d
277276
in
278277

279-
Util.Timer.start timer;
280278
let broken =
281279
if checklist <> [] then
282-
Depsolver.listcheck ~callback universe checklist
280+
Depsolver.listcheck ~callback ~explain universe checklist
283281
else
284-
Depsolver.univcheck ~callback universe
282+
Depsolver.univcheck ~callback ~explain universe
285283
in
286-
ignore(Util.Timer.stop timer ());
287284

288285
if failure then Format.fprintf fmt "@]@.";
289286

@@ -306,8 +303,9 @@ let main () =
306303

307304
StdDebug.enable_debug (OptParse.Opt.get Options.verbose);
308305
StdDebug.enable_bars (OptParse.Opt.get Options.progress)
309-
["Depsolver_int.univcheck";"Depsolver_int.init_solver"] ;
310-
StdDebug.enable_timers (OptParse.Opt.get Options.timers) ["Solver"];
306+
["Depsolver_int.univcheck";"Depsolver_int.init_solver"];
307+
StdDebug.enable_timers (OptParse.Opt.get Options.timers)
308+
["Algo.Depsolver.solver"; "Algo.Depsolver.init" ] ;
311309
StdDebug.all_quiet (OptParse.Opt.get Options.quiet);
312310

313311
let checklist = OptParse.Opt.opt Options.checkonly in

common/edosSolver.ml

+22-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(* library, see the COPYING file for more information. *)
1313
(***************************************************************************************)
1414

15+
1516
module type S = sig
1617
type reason
1718
end
@@ -55,6 +56,27 @@ module IntHash =
5556
let hash i = i
5657
end)
5758

59+
open ExtLib
60+
(*
61+
let (@) l1 l2 =
62+
let rec geq = function
63+
|[],[] -> true
64+
|_::_,[] -> true
65+
|[],_::_ -> false
66+
|_::r1,_::r2 -> geq (r1,r2)
67+
in
68+
if geq (l1,l2) then List.append l2 l1 else List.append l1 l2
69+
*)
70+
71+
(* join two lists ignoring the order *)
72+
let (@) l1 l2 =
73+
let rec aux l1 l2 acc =
74+
match (l1,l2) with
75+
|x::r1,y::r2 -> aux r1 r2 (x::y::acc)
76+
|l1,[] -> List.fold_left (fun accu x -> x::accu) l1 acc
77+
|[],l2 -> List.fold_left (fun accu x -> x::accu) l2 acc
78+
in aux l1 l2 []
79+
5880
module M (X : S) = struct
5981

6082
module X = X
@@ -442,10 +464,6 @@ module M (X : S) = struct
442464
reasons := !r.reasons @ !reasons;
443465
for i = 0 to Array.length !r.all_lits - 1 do
444466
let p = !r.all_lits.(i) in
445-
(*
446-
for i = 0 to Array.length !r.lits - 1 do
447-
let p = !r.lits.(i) in
448-
*)
449467
let x = var_of_lit p in
450468
if st.st_seen_var.(x) <> st.st_seen then begin
451469
assert (val_of_lit st p = False);

0 commit comments

Comments
 (0)