aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Tassi2014-10-22 16:18:19 +0200
committerEnrico Tassi2014-10-22 16:18:19 +0200
commit5e3a56c233ad412b96ce473cf775f6b7bd9e72f7 (patch)
treec0a78d0e1b5c9bd74b69a530261102da236636d5
parent39d9b466b1d270bf0003bffa12193423aaa31696 (diff)
Make rint_location_in_file resilient to Cd (close 3630)
Cd can make the relative path of the opened file wrong, and hence not available anymore when we reopen it to compute the line number.
-rw-r--r--toplevel/coqloop.ml26
1 files changed, 15 insertions, 11 deletions
diff --git a/toplevel/coqloop.ml b/toplevel/coqloop.ml
index b27f7ae31a..3f93588904 100644
--- a/toplevel/coqloop.ml
+++ b/toplevel/coqloop.ml
@@ -159,25 +159,29 @@ let print_location_in_file {outer=s;inner=fname} loc =
if String.equal s fname then mt() else errstrm ++ str":" ++ fnl()
in
let (bp,ep) = Loc.unloc loc in
- let ic = open_in fname in
- let rec line_of_pos lin bol cnt =
- if cnt < bp then
- if input_char ic == '\n'
- then line_of_pos (lin + 1) (cnt +1) (cnt+1)
- else line_of_pos lin bol (cnt+1)
- else (lin, bol)
- in
+ let line_of_pos lin bol cnt =
+ try
+ let ic = open_in fname in
+ let rec line_of_pos lin bol cnt =
+ if cnt < bp then
+ if input_char ic == '\n'
+ then line_of_pos (lin + 1) (cnt +1) (cnt+1)
+ else line_of_pos lin bol (cnt+1)
+ else (lin, bol)
+ in
+ let rc = line_of_pos lin bol cnt in
+ close_in ic;
+ rc
+ with Sys_error _ -> 0, 0 in
try
let (line, bol) = line_of_pos 1 0 0 in
- close_in ic;
hov 0 (* No line break so as to follow emacs error message format *)
(errstrm ++ str"File " ++ str ("\""^fname^"\"") ++
str", line " ++ int line ++ str", characters " ++
Cerrors.print_loc (Loc.make_loc (bp-bol,ep-bol))) ++ str":" ++
fnl ()
with e when Errors.noncritical e ->
- (close_in ic;
- hov 1 (errstrm ++ spc() ++ str"(invalid location):") ++ fnl ())
+ hov 1 (errstrm ++ spc() ++ str"(invalid location):") ++ fnl ()
let valid_buffer_loc ib loc =
not (Loc.is_ghost loc) &&