Skip to content

Commit

Permalink
Ocaml 405 fix (#2221)
Browse files Browse the repository at this point in the history
* Fixed string related build warnings
* Changed Failures to accept all strings
* Updated pprzlink for v405 fix
* updated use of lowercase, uppercase and capitalize
  • Loading branch information
rijesha authored and gautierhattenberger committed Jan 26, 2018
1 parent 066a8f2 commit d4709f7
Show file tree
Hide file tree
Showing 34 changed files with 108 additions and 92 deletions.
8 changes: 4 additions & 4 deletions sw/ground_segment/cockpit/gcs.ml
Expand Up @@ -499,7 +499,7 @@ let resize = fun (widget:GObj.widget) orientation size ->

let rec pack_widgets = fun orientation xml widgets packing ->
let size = try Some (ExtXml.int_attrib xml "size") with _ -> None in
match Compat.bytes_lowercase (Xml.tag xml) with
match Compat.lowercase_ascii (Xml.tag xml) with
"widget" ->
let name = ExtXml.attrib xml "name" in
let widget =
Expand All @@ -526,7 +526,7 @@ and pack_list = fun resize orientation xmls widgets packing ->

let rec find_widget_children = fun name xml ->
let xmls = Xml.children xml in
match Compat.bytes_lowercase (Xml.tag xml) with
match Compat.lowercase_ascii (Xml.tag xml) with
"widget" when ExtXml.attrib xml "name" = name -> xmls
| "rows" | "columns" ->
let rec loop = function
Expand All @@ -540,7 +540,7 @@ let rec find_widget_children = fun name xml ->

let rec replace_widget_children = fun name children xml ->
let xmls = Xml.children xml
and tag = Compat.bytes_lowercase (Xml.tag xml) in
and tag = Compat.lowercase_ascii (Xml.tag xml) in
match tag with
"widget" ->
Xml.Element("widget",
Expand All @@ -562,7 +562,7 @@ let rec update_widget_size = fun orientation widgets xml ->
if orientation = `HORIZONTAL then rect.Gtk.width else rect.Gtk.height
in
let xmls = Xml.children xml
and tag = Compat.bytes_lowercase (Xml.tag xml) in
and tag = Compat.lowercase_ascii (Xml.tag xml) in
match tag with
"widget" ->
let name = ExtXml.attrib xml "name" in
Expand Down
2 changes: 1 addition & 1 deletion sw/ground_segment/cockpit/live.ml
Expand Up @@ -348,7 +348,7 @@ let mark = fun (geomap:G.widget) ac_id track plugin_frame ->
let attributes_pretty_printer = fun attribs ->
(* Remove the optional attributes *)
let valid = fun a ->
let a = Compat.bytes_lowercase a in
let a = Compat.lowercase_ascii a in
a <> "no" && a <> "strip_icon" && a <> "strip_button" && a <> "pre_call"
&& a <> "post_call" && a <> "key" && a <> "group" in

Expand Down
6 changes: 3 additions & 3 deletions sw/ground_segment/cockpit/page_settings.ml
Expand Up @@ -55,7 +55,7 @@ object
let v = float_of_string s in
last_known_value <- Some v;
set_default v
with Failure "float_of_string" -> ()
with Failure _ -> ()
end
end

Expand Down Expand Up @@ -249,7 +249,7 @@ let one_setting = fun (i:int) (do_change:int -> float -> unit) ac_id packing dl_

(** Insert the related buttons in the strip and prepare the papgets DnD *)
List.iter (fun x ->
match Compat.bytes_lowercase (Xml.tag x) with
match Compat.lowercase_ascii (Xml.tag x) with
"strip_button" ->
let label = ExtXml.attrib x "name"
and sp_value = ExtXml.float_attrib x "value"
Expand Down Expand Up @@ -293,7 +293,7 @@ let same_tag_for_all = function
| x::xs ->
let tag_first = Xml.tag x in
List.iter (fun y -> assert(ExtXml.tag_is y tag_first)) xs;
Compat.bytes_lowercase tag_first
Compat.lowercase_ascii tag_first


(** Build the tree of settings *)
Expand Down
2 changes: 1 addition & 1 deletion sw/ground_segment/cockpit/saveSettings.ml
Expand Up @@ -170,7 +170,7 @@ let fill_data = fun (model:GTree.tree_store) settings airframe_xml ->
try
float_of_string (List.hd str_val) *. airframe_scale *. extra_scale
with
Failure "float_of_string" -> raise (EditAirframe.No_param param)
Failure _ -> raise (EditAirframe.No_param param)
in
let airframe_value_new = value /. airframe_scale in
(* test if is has to be saved as integer or float *)
Expand Down
2 changes: 1 addition & 1 deletion sw/ground_segment/cockpit/sectors.ml
Expand Up @@ -7,7 +7,7 @@ let (//) = Filename.concat

let rec display = fun (geomap:MapCanvas.widget) r ->

match Compat.bytes_lowercase (Xml.tag r) with
match Compat.lowercase_ascii (Xml.tag r) with
"disc" ->
let rad = float_of_string (ExtXml.attrib r "radius")
and geo = Latlong.of_string (ExtXml.attrib (ExtXml.child r "point") "pos") in
Expand Down
2 changes: 1 addition & 1 deletion sw/ground_segment/tmtc/messages.ml
Expand Up @@ -164,7 +164,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) (topnote:GPack.no
eb#coerce#misc#set_state `SELECTED;
ignore (GMain.Timeout.add led_delay (fun () -> eb#coerce#misc#set_state `NORMAL; false))
with
Invalid_argument "List.iter2" ->
Invalid_argument _ ->
Printf.fprintf stderr "%s: expected %d args, got %d\n" id n (List.length values); flush stderr
| exc -> prerr_endline (Printexc.to_string exc)
in
Expand Down
2 changes: 1 addition & 1 deletion sw/ground_segment/tmtc/server_globals.ml
Expand Up @@ -24,7 +24,7 @@ let string_of_values = fun values ->
(** get modes from autopilot xml file *)
let modes_from_autopilot = fun ap_xml ->
let ap = ExtXml.child ap_xml
~select:(fun x -> String.uppercase (ExtXml.attrib_or_default x "gcs_mode" "") = "TRUE")
~select:(fun x -> Compat.uppercase_ascii (ExtXml.attrib_or_default x "gcs_mode" "") = "TRUE")
"state_machine"
in
let modes = List.filter (fun x -> Xml.tag x = "mode") (Xml.children ap) in
Expand Down
3 changes: 3 additions & 0 deletions sw/lib/ocaml/Makefile
Expand Up @@ -71,6 +71,9 @@ ifeq ($(shell test $(OCAMLC_MAJOR) -ge 4; echo $$?),0)
ifeq ($(shell test $(OCAMLC_MINOR) -ge 2; echo $$?),0)
# the Bytes module is available since OCaml 4.02.0
CAMLP4_DEFS += -DHAS_BYTES_MODULE
ifeq ($(shell test $(OCAMLC_MINOR) -ge 4; echo $$?),0)
CAMLP4_DEFS += -DOCAML_V404
endif
endif
endif
PP_OPTS = -pp "camlp4o pa_macro.cmo $(CAMLP4_DEFS)"
Expand Down
22 changes: 16 additions & 6 deletions sw/lib/ocaml/compat.ml
Expand Up @@ -43,12 +43,6 @@ let bytes_make = fun n c->
let bytes_copy = fun s->
BYTES.copy s

let bytes_lowercase = fun s->
BYTES.lowercase s

let bytes_uppercase = fun s->
BYTES.uppercase s

let bytes_blit = fun src srcoff dst dstoff len->
BYTES.blit src srcoff dst dstoff len

Expand All @@ -75,3 +69,19 @@ let bytes_set = fun s n c->

let bytes_iter = fun f s->
BYTES.iter f s

IFDEF OCAML_V404 THEN
let lowercase_ascii = BYTES.lowercase_ascii

let uppercase_ascii = BYTES.uppercase_ascii

let capitalize_ascii = BYTES.capitalize_ascii

ELSE
let lowercase_ascii = BYTES.lowercase

let uppercase_ascii = BYTES.uppercase

let capitalize_ascii = BYTES.capitalize

END
6 changes: 4 additions & 2 deletions sw/lib/ocaml/compat.mli
Expand Up @@ -27,8 +27,6 @@ val bytes_contains : string -> char -> bool
val bytes_length : string -> int
val bytes_make : int -> char -> string
val bytes_copy : string -> string
val bytes_lowercase : string -> string
val bytes_uppercase : string -> string
val bytes_blit : string -> int -> string -> int -> int -> unit
val bytes_sub : string -> int -> int -> string
val bytes_index : string -> char -> int
Expand All @@ -38,3 +36,7 @@ val bytes_get : string -> int -> char
val bytes_compare : string -> string -> int
val bytes_set : string -> int -> char -> unit
val bytes_iter : (char -> unit) -> string -> unit

val lowercase_ascii : string -> string
val uppercase_ascii : string -> string
val capitalize_ascii : string -> string
2 changes: 1 addition & 1 deletion sw/lib/ocaml/expr_lexer.mll
Expand Up @@ -63,7 +63,7 @@ rule token = parse
try
Expr_parser.expression token lexbuf
with
Failure("lexing: empty token") ->
Failure _ ->
Printf.fprintf stderr "Lexing error in '%s': unexpected char: '%c' \n"
s (Lexing.lexeme_char lexbuf 0);
exit 1
Expand Down
8 changes: 4 additions & 4 deletions sw/lib/ocaml/extXml.ml
Expand Up @@ -44,7 +44,7 @@ let child = fun xml ?select c ->

(* Let's try with a numeric index *)
try (Array.of_list children).(int_of_string c)
with Failure "int_of_string" -> (* Bad luck. Go through the children *)
with Failure _ -> (* Bad luck. Go through the children *)
find children


Expand Down Expand Up @@ -75,7 +75,7 @@ let attrib_option = fun xml attr ->
try Some (Xml.attrib xml attr)
with Xml.No_attribute _ -> None

let tag_is = fun x v -> Compat.bytes_lowercase (Xml.tag x) = Compat.bytes_lowercase v
let tag_is = fun x v -> Compat.lowercase_ascii (Xml.tag x) = Compat.lowercase_ascii v

let attrib_or_default = fun x a default ->
try Xml.attrib x a
Expand Down Expand Up @@ -148,7 +148,7 @@ let my_to_string_fmt = fun tab_attribs x ->


let to_string_fmt = fun ?(tab_attribs = false) xml ->
let l = Compat.bytes_lowercase in
let l = Compat.lowercase_ascii in
let rec lower = function
| Xml.PCData _ as x -> x
| Xml.Element (t, ats, cs) ->
Expand All @@ -159,7 +159,7 @@ let to_string_fmt = fun ?(tab_attribs = false) xml ->


let subst_attrib = fun attrib value xml ->
let u = Compat.bytes_uppercase in
let u = Compat.uppercase_ascii in
let uattrib = u attrib in
match xml with
| Xml.Element (tag, attrs, children) ->
Expand Down
12 changes: 6 additions & 6 deletions sw/lib/ocaml/fp_proc.ml
Expand Up @@ -38,7 +38,7 @@ let parse_expression = fun s ->
try
Expr_parser.expression Expr_lexer.token lexbuf
with
Failure("lexing: empty token") ->
Failure _ ->
fprintf stderr "Lexing error in '%s': unexpected char: '%c' \n"
s (Lexing.lexeme_char lexbuf 0);
exit 1
Expand Down Expand Up @@ -72,7 +72,7 @@ let transform_values = fun attribs_not_modified env attribs ->
List.map
(fun (a, v) ->
let v' =
if List.mem (String.lowercase a) attribs_not_modified
if List.mem (Compat.lowercase_ascii a) attribs_not_modified
then v
else transform_expression env (parse_expression v) in
(a, v'))
Expand All @@ -83,7 +83,7 @@ let prefix_or_deroute = fun prefix reroutes name attribs ->
List.map
(fun (a, v) ->
let v' =
if String.lowercase a = name then
if Compat.lowercase_ascii a = name then
try List.assoc v reroutes with
Not_found -> prefix v
else v in
Expand All @@ -105,7 +105,7 @@ let transform_stage = fun prefix reroutes env xml ->
let rec tr = fun xml ->
match xml with
Xml.Element (tag, attribs, children) -> begin
match String.lowercase tag with
match Compat.lowercase_ascii tag with
"exception" ->
transform_exception prefix reroutes env xml
| "while" ->
Expand Down Expand Up @@ -276,7 +276,7 @@ let process_includes = fun dir xml ->


let remove_attribs = fun xml names ->
List.filter (fun (x,_) -> not (List.mem (String.lowercase x) names)) (Xml.attribs xml)
List.filter (fun (x,_) -> not (List.mem (Compat.lowercase_ascii x) names)) (Xml.attribs xml)

let xml_assoc_attrib = fun a v xmls ->
List.find (fun x -> ExtXml.attrib x a = v) xmls
Expand Down Expand Up @@ -327,7 +327,7 @@ let replace_from = fun stage waypoints ->

let process_stage = fun stage waypoints ->
let rec do_it = fun stage ->
match String.lowercase (Xml.tag stage) with
match Compat.lowercase_ascii (Xml.tag stage) with
"go" | "stay" | "circle" ->
replace_from (replace_wp stage waypoints) waypoints

Expand Down
2 changes: 1 addition & 1 deletion sw/lib/ocaml/gen_common.ml
Expand Up @@ -160,7 +160,7 @@ let get_autopilot_of_airframe = fun ?target xml ->
* Returns the boolean expression of targets of a module *)
let get_targets_of_module = fun xml ->
Xml.fold (fun a x ->
match Compat.bytes_lowercase (Xml.tag x) with
match Compat.lowercase_ascii (Xml.tag x) with
| "makefile" when a = Var "" -> targets_of_field x Env.default_module_targets
| "makefile" -> Or (a, targets_of_field x Env.default_module_targets)
| _ -> a
Expand Down
2 changes: 1 addition & 1 deletion sw/lib/ocaml/mapCanvas.ml
Expand Up @@ -587,7 +587,7 @@ object (self)
end
| _ -> false
with
Invalid_argument "ml_lookup_from_c" -> (* Raised GdkEvent.get_type *)
Invalid_argument _ -> (* Raised GdkEvent.get_type *)
false


Expand Down
6 changes: 3 additions & 3 deletions sw/lib/ocaml/mapFP.ml
Expand Up @@ -34,7 +34,7 @@ let float_attr = fun xml a -> float_of_string (ExtXml.attrib xml a)
let rec assoc_nocase at = function
[] -> raise Not_found
| (a, v)::avs ->
if Compat.bytes_uppercase at = Compat.bytes_uppercase a then v else assoc_nocase at avs
if Compat.uppercase_ascii at = Compat.uppercase_ascii a then v else assoc_nocase at avs

(** Returns the WGS84 coordinates of a waypoint, either from its relative x and
y coordinates or from its lat and long *)
Expand Down Expand Up @@ -203,7 +203,7 @@ let display_kml = fun ?group color geomap xml ->
try
let document = ExtXml.child xml "Document" in
let rec loop = fun child ->
let tag = Compat.bytes_lowercase (Xml.tag child) in
let tag = Compat.lowercase_ascii (Xml.tag child) in
match tag with
| "linestring" | "linearring" ->
let coordinates = ExtXml.child child "coordinates" in
Expand Down Expand Up @@ -266,7 +266,7 @@ class flight_plan = fun ?format_attribs ?editable ~show_moved geomap color fp_dt
let waypoints = ExtXml.child xml "waypoints" in
try
List.fold_left (fun l x ->
match Compat.bytes_lowercase (Xml.tag x) with
match Compat.lowercase_ascii (Xml.tag x) with
"kml" ->
let file = ExtXml.attrib x "file" in
display_kml ~group:wpts_group#group color geomap (ExtXml.parse_file (Env.flight_plans_path // file));
Expand Down
6 changes: 3 additions & 3 deletions sw/lib/ocaml/papget.ml
Expand Up @@ -368,7 +368,7 @@ object (self)
let (x, y) = item#xy in
let attrs =
[ "type", msg_obj#type_;
"display", Compat.bytes_lowercase item#renderer#tag;
"display", Compat.lowercase_ascii item#renderer#tag;
"x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in
Xml.Element ("papget", attrs, scale_prop::val_props@renderer_props)
end
Expand All @@ -387,7 +387,7 @@ object
let (x, y) = item#xy in
let attrs =
[ "type", type_;
"display", Compat.bytes_lowercase item#renderer#tag;
"display", Compat.lowercase_ascii item#renderer#tag;
"x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in
Xml.Element ("papget", attrs, properties@props)
end
Expand Down Expand Up @@ -416,7 +416,7 @@ object (self)
let (x, y) = item#xy in
let attrs =
[ "type", "video_plugin";
"display", Compat.bytes_lowercase item#renderer#tag;
"display", Compat.lowercase_ascii item#renderer#tag;
"x", sprintf "%.0f" x; "y", sprintf "%.0f" y ] in
Xml.Element ("papget", attrs, properties@props)
initializer ignore(adj#connect#value_changed (fun () -> self#update_zoom (string_of_float adj#value)))
Expand Down
3 changes: 2 additions & 1 deletion sw/lib/ocaml/srtm.ml
Expand Up @@ -87,7 +87,8 @@ let area_of_tile = fun tile ->
let area = open_compressed "srtm.data.bz2" in
let rec _area_of_tile = fun () ->
try
Scanf.fscanf area "%s %s\n" (fun t a ->
let ib = Scanf.Scanning.from_channel area in
Scanf.bscanf ib "%s %s\n" (fun t a ->
if t = tile then a
else _area_of_tile ())
with
Expand Down
8 changes: 4 additions & 4 deletions sw/lib/ocaml/xmlEdit.ml
Expand Up @@ -352,21 +352,21 @@ let set_attribs = fun ((model, path):node) attribs ->
let rec replace_assoc a v = function
[] -> [(a, v)]
| (a', v')::l ->
if a = Compat.bytes_uppercase a'
if a = Compat.uppercase_ascii a'
then (a, v)::l
else (a', v')::replace_assoc a v l
let set_attrib = fun node (a, v) ->
let atbs = attribs node in
set_attribs node (replace_assoc (Compat.bytes_uppercase a) v atbs)
set_attribs node (replace_assoc (Compat.uppercase_ascii a) v atbs)
let attrib = fun node at ->
let at = Compat.bytes_uppercase at in
let at = Compat.uppercase_ascii at in
let ats = attribs node in
let rec loop = function
[] -> raise Not_found
| (a,v)::avs ->
if Compat.bytes_uppercase a = at then v else loop avs in
if Compat.uppercase_ascii a = at then v else loop avs in
loop ats
let tag = fun ((model, path):node) ->
Expand Down
2 changes: 1 addition & 1 deletion sw/logalizer/export.ml
Expand Up @@ -165,7 +165,7 @@ let export_values = fun ?(sep="tab") ?(export_geo_pos=true) (model:GTree.tree_st

let lookup = fun m field ->
try
PprzLink.string_of_value (Hashtbl.find last_values (m,String.lowercase field))
PprzLink.string_of_value (Hashtbl.find last_values (m,Compat.lowercase_ascii field))
with
Not_found -> "" in

Expand Down
2 changes: 1 addition & 1 deletion sw/logalizer/plotter.ml
Expand Up @@ -574,7 +574,7 @@ let _ =
match !init with
[] -> failwith "unreachable"
| x::xs -> init := try ignore (float_of_string s); {x with consts = s::x.consts} :: xs with
| Failure "float_of_string" -> {x with curves = s::x.curves} :: xs in
| Failure _ -> {x with curves = s::x.curves} :: xs in

let set_title = fun s ->
match !init with
Expand Down

0 comments on commit d4709f7

Please sign in to comment.