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
This commit is contained in:
Kostia Balytskyi 2018-04-10 10:40:29 -07:00 committed by Saurabh Singh
parent f1ebfba3dc
commit dc1583e347
4 changed files with 46 additions and 11 deletions

View File

@ -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;

View File

@ -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 ====

View File

@ -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> uniondatapackstore;
@ -32,5 +39,6 @@ struct py_uniondatapackstore {
std::vector<PythonObj> cstores;
std::vector<std::shared_ptr<PythonDataStore>> pystores;
};
// clang-format on
#endif // FBHGEXT_CSTORE_PY_STRUCTS_H

View File

@ -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);