Allow square brackets in ini property values
authorDodji Seketeli <dodji@redhat.com>
Thu, 12 Jul 2018 11:47:08 +0000 (13:47 +0200)
committerDodji Seketeli <dodji@redhat.com>
Thu, 12 Jul 2018 11:47:08 +0000 (13:47 +0200)
Sometimes, one wants to be able to write suppression specifications
like:

    [suppress_function]
     filename_regexp = ^test38-char-class-in-ini-v[[:digit:]].*
     symbol_name_regexp = bar
     change_kind = added-function

without having to escape the square brackets in the regexp.  Normally,
one has to escape the '[' and the ']' because these characters are
used to define ini section names (e.g, [suppress_function]).

This patch allows the presence of the square bracket characters in a
property value, making the suppression specification above valid.

* src/abg-ini.cc (char_is_delimiter): Possibly disallow square
bracket characters into the set of delimiters.
* tests/data/test-diff-suppr/test38-char-class-in-ini-report-0.txt:
New reference output.
* tests/data/test-diff-suppr/test38-char-class-in-ini-v{0,1}.c:
Source code new test binaries.
* tests/data/test-diff-suppr/test38-char-class-in-ini-v{0,1}.o:
New test binaries.
* tests/data/test-diff-suppr/test38-char-class-in-ini.abignore:
New test abi suppression file.
* tests/data/Makefile.am: Add the new test materials above to
source distribution.
* tests/test-diff-suppr.cc: Add the test materials above to the
set of tests to run.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-ini.cc
tests/data/Makefile.am
tests/data/test-diff-suppr/test38-char-class-in-ini-report-0.txt [new file with mode: 0644]
tests/data/test-diff-suppr/test38-char-class-in-ini-v0.c [new file with mode: 0644]
tests/data/test-diff-suppr/test38-char-class-in-ini-v0.o [new file with mode: 0644]
tests/data/test-diff-suppr/test38-char-class-in-ini-v1.c [new file with mode: 0644]
tests/data/test-diff-suppr/test38-char-class-in-ini-v1.o [new file with mode: 0644]
tests/data/test-diff-suppr/test38-char-class-in-ini.abignore [new file with mode: 0644]
tests/test-diff-suppr.cc

index 8320e1f..d2a1abf 100644 (file)
@@ -63,18 +63,22 @@ char_is_comment_start(int b);
 ///@param include_white_space if true, consider white spaces as a
 ///delimiter.
 ///
+///@param include_square_bracket if true, consider square brackets as
+/// delimiters
+///
 /// @return true iff @p b is a delimiter.
 static bool
-char_is_delimiter(int b, bool include_white_space = true)
+char_is_delimiter(int b, bool include_white_space = true,
+                 bool include_square_bracket = true)
 {
-  return (b == '['
-           || b == ']'
-           || b == '{'
-           || b == '}'
-           || b == '='
-           || b == ','
-           || (include_white_space && char_is_white_space(b))
-           || char_is_comment_start(b));
+  return ((include_square_bracket && (b == '['))
+         || (include_square_bracket && (b == ']'))
+         || b == '{'
+         || b == '}'
+         || b == '='
+         || b == ','
+         || (include_white_space && char_is_white_space(b))
+         || char_is_comment_start(b));
 }
 
 /// Return true iff a given character can be part of a property
@@ -87,8 +91,9 @@ char_is_delimiter(int b, bool include_white_space = true)
 static bool
 char_is_property_value_char(int b)
 {
-  if (char_is_delimiter(b, /*include_white_space=*/false)
-       || b == '\n')
+  if (char_is_delimiter(b, /*include_white_space=*/false,
+                       /*include_square_bracket=*/false)
+      || b == '\n')
     return false;
   return true;
 }
index 46d1ecd..2e5c972 100644 (file)
@@ -1142,6 +1142,12 @@ test-diff-suppr/test37-opaque-type-v0.c \
 test-diff-suppr/test37-opaque-type-v0.o \
 test-diff-suppr/test37-opaque-type-v1.c \
 test-diff-suppr/test37-opaque-type-v1.o \
+test38-char-class-in-ini-report-0.txt \
+test38-char-class-in-ini-v0.c \
+test38-char-class-in-ini-v0.o \
+test38-char-class-in-ini-v1.c \
+test38-char-class-in-ini-v1.o \
+test38-char-class-in-ini.abignore \
 \
 test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1 \
 test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi \
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini-report-0.txt b/tests/data/test-diff-suppr/test38-char-class-in-ini-report-0.txt
new file mode 100644 (file)
index 0000000..dc68e2c
--- /dev/null
@@ -0,0 +1,3 @@
+Functions changes summary: 0 Removed, 0 Changed, 0 Added (1 filtered out) function
+Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
+
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini-v0.c b/tests/data/test-diff-suppr/test38-char-class-in-ini-v0.c
new file mode 100644 (file)
index 0000000..6eedbe3
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * This tests the use of the character class regexp syntax
+ * '[[:something]]' in the ini file, as part of a property value.
+ *
+ * Compile it with:
+ *   gcc -c -g test38-char-class-in-ini-v0.c
+ *
+ */
+struct S
+{
+  int m0;
+};
+
+void
+foo(struct S* s __attribute__((unused)))
+{
+}
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini-v0.o b/tests/data/test-diff-suppr/test38-char-class-in-ini-v0.o
new file mode 100644 (file)
index 0000000..e6b289c
Binary files /dev/null and b/tests/data/test-diff-suppr/test38-char-class-in-ini-v0.o differ
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini-v1.c b/tests/data/test-diff-suppr/test38-char-class-in-ini-v1.c
new file mode 100644 (file)
index 0000000..e717394
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * This tests the use of the character class regexp syntax
+ * '[[:something]]' in the ini file, as part of a property value.
+ *
+ * Compile it with:
+ *   gcc -c -g test38-char-class-in-ini-v1.c
+ *
+ */
+
+struct S
+{
+  int m0;
+};
+
+void
+foo(struct S* s __attribute__((unused)))
+{
+}
+
+void
+bar()
+{
+}
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini-v1.o b/tests/data/test-diff-suppr/test38-char-class-in-ini-v1.o
new file mode 100644 (file)
index 0000000..b1722f2
Binary files /dev/null and b/tests/data/test-diff-suppr/test38-char-class-in-ini-v1.o differ
diff --git a/tests/data/test-diff-suppr/test38-char-class-in-ini.abignore b/tests/data/test-diff-suppr/test38-char-class-in-ini.abignore
new file mode 100644 (file)
index 0000000..07f3f91
--- /dev/null
@@ -0,0 +1,4 @@
+[suppress_function]
+ filename_regexp = ^test38-char-class-in-ini-v[[:digit:]].*
+ symbol_name_regexp = bar
+ change_kind = added-function
index ddab012..7e34394 100644 (file)
@@ -1708,6 +1708,16 @@ InOutSpec in_out_specs[] =
     "data/test-diff-suppr/test37-opaque-type-report-0.txt",
     "output/test-diff-suppr/test37-opaque-type-report-0.txt"
   },
+  {
+   "data/test-diff-suppr/test38-char-class-in-ini-v0.o",
+   "data/test-diff-suppr/test38-char-class-in-ini-v1.o",
+   "",
+   "",
+   "data/test-diff-suppr/test38-char-class-in-ini.abignore",
+   "--no-default-suppression",
+   "data/test-diff-suppr/test38-char-class-in-ini-report-0.txt",
+   "output/test-diff-suppr/test38-char-class-in-ini-report-0.txt"
+  },
   // This should be the last entry
   {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
 };