From dc1583e347b8f77733620e3f9a6d83027faf08b3 Mon Sep 17 00:00:00 2001 From: Kostia Balytskyi Date: Tue, 10 Apr 2018 10:40:29 -0700 Subject: [PATCH] hg: remove extra semicolons in structs Summary: `PyObject_HEAD` is macro that ends with a semicolon when is is resolved. Thus `PyObject_HEAD;` ends in two semicolons. Tolerating extra semicolons is a gcc feature, not a standard one. I am adding the explanation for `// clang-format off` only once per file. https://stackoverflow.com/questions/49529130/are-extra-semicolons-allowed-inside-struct-declarations?rq=1&utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa Differential Revision: D7568269 fbshipit-source-id: 5afcfd7d96dc638cd0673d25809c9c43d58d00de --- hgext/extlib/cfastmanifest.c | 13 ++++++++++--- hgext/extlib/cstore/py-cdatapack.h | 12 ++++++++++-- hgext/extlib/cstore/py-structs.h | 12 ++++++++++-- hgext/extlib/cstore/py-treemanifest.h | 20 ++++++++++++++++---- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/hgext/extlib/cfastmanifest.c b/hgext/extlib/cfastmanifest.c index e672176803..5a1c220718 100644 --- a/hgext/extlib/cfastmanifest.c +++ b/hgext/extlib/cfastmanifest.c @@ -16,16 +16,23 @@ typedef unsigned char bool; #include "hgext/extlib/cfastmanifest/tree.h" +// clang-format off +// clang thinks that PyObject_HEAD should be on the same line as the next line +// since there is no semicolong after it. There is no semicolon because +// PyObject_HEAD macro already contains one and MSVC does not support +// extra semicolons. typedef struct { - PyObject_HEAD; + PyObject_HEAD tree_t *tree; } fastmanifest; +// clang-format on +// clang-format off typedef struct { - PyObject_HEAD; + PyObject_HEAD iterator_t *iterator; } fmIter; - +// clang-format on static PyTypeObject fastmanifestType; static PyTypeObject fastmanifestKeysIterator; diff --git a/hgext/extlib/cstore/py-cdatapack.h b/hgext/extlib/cstore/py-cdatapack.h index 23c5d974d7..0e0d66cea1 100644 --- a/hgext/extlib/cstore/py-cdatapack.h +++ b/hgext/extlib/cstore/py-cdatapack.h @@ -24,22 +24,30 @@ extern "C" { // ==== py_cdatapack PyObject declaration ==== +// clang-format off +// clang thinks that PyObject_HEAD should be on the same line as the next line +// since there is no semicolong after it. There is no semicolon because +// PyObject_HEAD macro already contains one and MSVC does not support +// extra semicolons. struct py_cdatapack { - PyObject_HEAD; + PyObject_HEAD bool initialized; datapack_handle_t *handle; }; +// clang-format on // ==== py_cdatapack_iterator PyObject declaration ==== +// clang-format off typedef struct { - PyObject_HEAD; + PyObject_HEAD py_cdatapack *datapack; const uint8_t *ptr; const uint8_t *end; } py_cdatapack_iterator; +// clang-format on // ==== cdatapack_deltas_iterator class methods ==== diff --git a/hgext/extlib/cstore/py-structs.h b/hgext/extlib/cstore/py-structs.h index bec5a4758e..285f9affab 100644 --- a/hgext/extlib/cstore/py-structs.h +++ b/hgext/extlib/cstore/py-structs.h @@ -17,14 +17,21 @@ #include "hgext/extlib/cstore/pythonutil.h" #include "hgext/extlib/cstore/uniondatapackstore.h" +// clang-format off +// clang thinks that PyObject_HEAD should be on the same line as the next line +// since there is no semicolong after it. There is no semicolon because +// PyObject_HEAD macro already contains one and MSVC does not support +// extra semicolons. struct py_datapackstore { - PyObject_HEAD; + PyObject_HEAD DatapackStore datapackstore; }; +// clang-format on +// clang-format off struct py_uniondatapackstore { - PyObject_HEAD; + PyObject_HEAD std::shared_ptr uniondatapackstore; @@ -32,5 +39,6 @@ struct py_uniondatapackstore { std::vector cstores; std::vector> pystores; }; +// clang-format on #endif // FBHGEXT_CSTORE_PY_STRUCTS_H diff --git a/hgext/extlib/cstore/py-treemanifest.h b/hgext/extlib/cstore/py-treemanifest.h index 2bb35cca54..5f5281adb5 100644 --- a/hgext/extlib/cstore/py-treemanifest.h +++ b/hgext/extlib/cstore/py-treemanifest.h @@ -27,19 +27,27 @@ #define FILENAME_BUFFER_SIZE 16348 #define FLAG_SIZE 1 +// clang-format off +// clang thinks that PyObject_HEAD should be on the same line as the next line +// since there is no semicolong after it. There is no semicolon because +// PyObject_HEAD macro already contains one and MSVC does not support +// extra semicolons. struct py_treemanifest { - PyObject_HEAD; + PyObject_HEAD treemanifest tm; }; +// clang-format on +// clang-format off struct py_newtreeiter { - PyObject_HEAD; + PyObject_HEAD FinalizeIterator iter; py_treemanifest *treemf; }; +// clang-format on static void newtreeiter_dealloc(py_newtreeiter *self); static PyObject *newtreeiter_iternext(py_newtreeiter *self); @@ -74,13 +82,15 @@ static PyTypeObject newtreeiterType = { (iternextfunc)newtreeiter_iternext, /* tp_iternext: next() method */ }; +// clang-format off struct py_subtreeiter { - PyObject_HEAD; + PyObject_HEAD SubtreeIterator iter; py_treemanifest *treemf; }; +// clang-format on static void subtreeiter_dealloc(py_subtreeiter *self); static PyObject *subtreeiter_iternext(py_subtreeiter *self); @@ -119,8 +129,9 @@ static PyTypeObject subtreeiterType = { * the fileiter above because it lets us just call the constructor on * fileiter, which will automatically populate all the members of fileiter. */ +// clang-format off struct py_fileiter { - PyObject_HEAD; + PyObject_HEAD fileiter iter; @@ -131,6 +142,7 @@ struct py_fileiter { // over it. const py_treemanifest *treemf; }; +// clang-format on static void fileiter_dealloc(py_fileiter *self); static PyObject *fileiter_iterentriesnext(py_fileiter *self);