FredSRichardson Posted May 21, 2006 Share Posted May 21, 2006 Okay, I'm having trouble with "balance_quotes" (in the iwgrules.ml) raising "Invalid_argument(_)". It took me a long time to find this. Here's the snippet (goes back to iwg2 days): let balance_quotes fn s = let num_quotes = ref 0 in for i = 0 to String.length s do if s.[i] = '"' then incr num_quotes else if s.[i] = '\'' then (s.[i] <- '"'; incr num_quotes) done; if !num_quotes mod 2 <> 0 then begin error "DLG" "[%s] has %d quotes in ~%s~: balancing.\n" fn !num_quotes s; let s = Str.global_replace left_quote_regexp "\"\\1\"\\2" s in let s = Str.global_replace right_quote_regexp "\\1\"\\2\"" s in s end else s Could it be that the index should only go up to "(String.length s) - 1"? Link to comment
the bigg Posted May 21, 2006 Share Posted May 21, 2006 Yeah, Ocaml string (like C ones) go from 0 to length - 1. Link to comment
FredSRichardson Posted May 21, 2006 Author Share Posted May 21, 2006 This must be an ocaml version problem since the code wasn't breaking until recently (and I bumped my Ocaml to 3.09.1 not so long ago). Link to comment
the bigg Posted May 21, 2006 Share Posted May 21, 2006 Check if the Makefile defines UNSAFE to 1 or not. WesDU was unsafe, while BiggDU >= 191 is compiled with bounds check, which could cause the problems you described. Link to comment
FredSRichardson Posted May 21, 2006 Author Share Posted May 21, 2006 Ah, bounds checking is a good thing! But what a pain to track this down. I had to do a search with print statements to figure out where the routine was exiting early and then add a "try ... with" wrapper to figure out what the exception was. Sheesh! There's got to be a better way. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.