[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Use parentheses to avoid mis-indentations of stringified macro args



commit 06a6130666315cb1d385b89d7c95df42ac17db1a
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri Jan 10 15:01:42 2020 -0500

    Use parentheses to avoid mis-indentations of stringified macro args
    
    clang-format sometimes thinks that "#name" should be written as
    "#     name" if it appears at the start of a line.  Using () appears
    to suppress this, while confusing Coccinelle.
---
 src/app/config/config.c           |  2 +-
 src/feature/control/control_cmd.c |  4 ++--
 src/lib/conf/conftypes.h          |  4 +++-
 src/test/test_pt.c                |  4 +++-
 src/test/test_util.c              | 18 +++++++++---------
 src/test/test_util_process.c      |  7 ++++---
 6 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index bbf984ad0..f75d68932 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -182,7 +182,7 @@ static const char unix_q_socket_prefix[] = "unix:\"";
  * *DowloadInitialDelay . */
 #ifndef COCCI
 #define DOWNLOAD_SCHEDULE(name) \
-  { #name "DownloadSchedule", #name "DownloadInitialDelay", 0, 1 }
+  { (#name "DownloadSchedule"), (#name "DownloadInitialDelay"), 0, 1 }
 #else
 #define DOWNLOAD_SCHEDULE(name) { NULL, NULL, 0, 1 }
 #endif /* !defined(COCCI) */
diff --git a/src/feature/control/control_cmd.c b/src/feature/control/control_cmd.c
index c2d23243e..cdefef97e 100644
--- a/src/feature/control/control_cmd.c
+++ b/src/feature/control/control_cmd.c
@@ -2272,7 +2272,7 @@ typedef struct control_cmd_def_t {
  **/
 #define ONE_LINE(name, flags)                                   \
   {                                                             \
-    #name,                                                      \
+    (#name),                                                    \
       handle_control_ ##name,                                   \
       flags,                                                    \
       &name##_syntax,                                           \
@@ -2283,7 +2283,7 @@ typedef struct control_cmd_def_t {
  * flags.
  **/
 #define MULTLINE(name, flags)                                   \
-  { "+"#name,                                                   \
+  { ("+"#name),                                                 \
       handle_control_ ##name,                                   \
       flags,                                                    \
       &name##_syntax                                            \
diff --git a/src/lib/conf/conftypes.h b/src/lib/conf/conftypes.h
index ebc2736aa..081ebf397 100644
--- a/src/lib/conf/conftypes.h
+++ b/src/lib/conf/conftypes.h
@@ -260,6 +260,7 @@ typedef struct config_deprecation_t {
   const char *why_deprecated;
 } config_deprecation_t;
 
+#ifndef COCCI
 /**
  * Handy macro for declaring "In the config file or on the command line, you
  * can abbreviate <b>tok</b>s as <b>tok</b>". Used inside an array of
@@ -268,7 +269,8 @@ typedef struct config_deprecation_t {
  * For example, to declare "NumCpu" as an abbreviation for "NumCPUs",
  * you can say PLURAL(NumCpu).
  **/
-#define PLURAL(tok) { #tok, #tok "s", 0, 0 }
+#define PLURAL(tok) { (#tok), (#tok "s"), 0, 0 }
+#endif /* !defined(COCCI) */
 
 /**
  * Validation function: verify whether a configuation object is well-formed
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index 26eaf7b7e..893fec367 100644
--- a/src/test/test_pt.c
+++ b/src/test/test_pt.c
@@ -579,8 +579,10 @@ test_get_pt_proxy_uri(void *arg)
     tor_free(uri);
 }
 
+#ifndef COCCI
 #define PT_LEGACY(name)                                               \
-  { #name, test_pt_ ## name , 0, NULL, NULL }
+  { (#name), test_pt_ ## name , 0, NULL, NULL }
+#endif
 
 struct testcase_t pt_tests[] = {
   PT_LEGACY(parsing),
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 07c31f02d..0226517d7 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -6305,42 +6305,42 @@ test_util_map_anon_nofork(void *arg)
 
 #ifndef COCCI
 #define UTIL_LEGACY(name)                                               \
-  { #name, test_util_ ## name , 0, NULL, NULL }
+  { (#name), test_util_ ## name , 0, NULL, NULL }
 
 #define UTIL_TEST(name, flags)                          \
-  { #name, test_util_ ## name, flags, NULL, NULL }
+  { (#name), test_util_ ## name, flags, NULL, NULL }
 
 #define COMPRESS(name, identifier)              \
-  { "compress/" #name, test_util_compress, 0, &compress_setup,          \
+  { ("compress/" #name), test_util_compress, 0, &compress_setup,        \
     (char*)(identifier) }
 
 #define COMPRESS_CONCAT(name, identifier)                               \
-  { "compress_concat/" #name, test_util_decompress_concatenated, 0,     \
+  { ("compress_concat/" #name), test_util_decompress_concatenated, 0,   \
     &compress_setup,                                                    \
     (char*)(identifier) }
 
 #define COMPRESS_JUNK(name, identifier)                                 \
-  { "compress_junk/" #name, test_util_decompress_junk, 0,               \
+  { ("compress_junk/" #name), test_util_decompress_junk, 0,             \
     &compress_setup,                                                    \
     (char*)(identifier) }
 
 #define COMPRESS_DOS(name, identifier)                                  \
-  { "compress_dos/" #name, test_util_decompress_dos, 0,                 \
+  { ("compress_dos/" #name), test_util_decompress_dos, 0,               \
     &compress_setup,                                                    \
     (char*)(identifier) }
-#endif /* !defined(COCCI) */
 
 #ifdef _WIN32
 #define UTIL_TEST_WIN_ONLY(n, f) UTIL_TEST(n, (f))
 #else
-#define UTIL_TEST_WIN_ONLY(n, f) { #n, NULL, TT_SKIP, NULL, NULL }
+#define UTIL_TEST_WIN_ONLY(n, f) { (#n), NULL, TT_SKIP, NULL, NULL }
 #endif
 
 #ifdef DISABLE_PWDB_TESTS
-#define UTIL_TEST_PWDB(n, f) { #n, NULL, TT_SKIP, NULL, NULL }
+#define UTIL_TEST_PWDB(n, f) { (#n), NULL, TT_SKIP, NULL, NULL }
 #else
 #define UTIL_TEST_PWDB(n, f) UTIL_TEST(n, (f))
 #endif
+#endif
 
 struct testcase_t util_tests[] = {
   UTIL_LEGACY(time),
diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c
index 0e17e009f..f0e7334a9 100644
--- a/src/test/test_util_process.c
+++ b/src/test/test_util_process.c
@@ -67,10 +67,12 @@ test_util_process_clear_waitpid_callback(void *ignored)
 }
 #endif /* !defined(_WIN32) */
 
+#ifndef COCCI
 #ifndef _WIN32
-#define TEST(name) { #name, test_util_process_##name, 0, NULL, NULL }
+#define TEST(name) { (#name), test_util_process_##name, 0, NULL, NULL }
 #else
-#define TEST(name) { #name, NULL, TT_SKIP, NULL, NULL }
+#define TEST(name) { (#name), NULL, TT_SKIP, NULL, NULL }
+#endif
 #endif
 
 struct testcase_t util_process_tests[] = {
@@ -78,4 +80,3 @@ struct testcase_t util_process_tests[] = {
   TEST(clear_waitpid_callback),
   END_OF_TESTCASES
 };
-



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits