const correctness is nice. These changes exposed no problems and induced no new warnings.
From 4a8c1284e88a3a92377919616e73c65ea68e33ae Mon Sep 17 00:00:00 2001
From: Jim Meyering meyering@redhat.com Date: Fri, 3 Jul 2009 14:17:23 +0200 Subject: [PATCH libguestfs] generate slightly more "const-correct" code
* src/generator.ml: Add a few "const" attributes. --- src/generator.ml | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml index c65e717..5c9e1c3 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4686,7 +4686,7 @@ and generate_one_test_body name i test_name init test = List.iter (generate_test_command_call test_name) seq | TestOutput (seq, expected) -> pr " /* TestOutput for %s (%d) */\n" name i; - pr " char expected[] = "%s";\n" (c_quote expected); + pr " const char *expected = "%s";\n" (c_quote expected); let seq, last = get_seq_last seq in let test () = pr " if (strcmp (r, expected) != 0) {\n"; @@ -4708,7 +4708,7 @@ and generate_one_test_body name i test_name init test = pr " return -1;\n"; pr " }\n"; pr " {\n"; - pr " char expected[] = "%s";\n" (c_quote str); + pr " const char *expected = "%s";\n" (c_quote str); pr " if (strcmp (r[%d], expected) != 0) {\n" i; pr " fprintf (stderr, "%s: expected \"%%s\" but got \"%%s\"\n", expected, r[%d]);\n" test_name i; pr " return -1;\n"; @@ -4736,7 +4736,7 @@ and generate_one_test_body name i test_name init test = pr " return -1;\n"; pr " }\n"; pr " {\n"; - pr " char expected[] = "%s";\n" (c_quote str); + pr " const char *expected = "%s";\n" (c_quote str); pr " r[%d][5] = 's';\n" i; pr " if (strcmp (r[%d], expected) != 0) {\n" i; pr " fprintf (stderr, "%s: expected \"%%s\" but got \"%%s\"\n", expected, r[%d]);\n" test_name i; @@ -4882,7 +4882,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = | OptString n, "NULL" -> () | String n, arg | OptString n, arg -> - pr " char %s[] = "%s";\n" n (c_quote arg); + pr " const char *%s = "%s";\n" n (c_quote arg); | Int _, _ | Bool _, _ | FileIn _, _ | FileOut _, _ -> () @@ -4890,9 +4890,9 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = let strs = string_split " " arg in iteri ( fun i str -> - pr " char %s_%d[] = "%s";\n" n i (c_quote str); + pr " const char *%s_%d = "%s";\n" n i (c_quote str); ) strs; - pr " char *%s[] = {\n" n; + pr " const char *%s[] = {\n" n; iteri ( fun i _ -> pr " %s_%d,\n" n i ) strs;
On Fri, Jul 03, 2009 at 03:21:45PM +0200, Jim Meyering wrote:
const correctness is nice. These changes exposed no problems and induced no new warnings.
Yes, all looks good. +1.
Rich.