this repo has no description

Tweak clang-format config for PyObject_HEAD macros

Summary: Unfortunately those macros are designed in a way where they don't require a ';' after use, which confuses clang-format unless we manually add them to the `StatementMacros` list in the clang-format config.

Based on Facebook D21689198

authored by

Matthias Braun and committed by
Max Bernstein
6fdb59fc b6687744

+23 -27
+1
.clang-format
··· 3 3 DerivePointerAlignment: false 4 4 PointerAlignment: Left 5 5 IncludeBlocks: Regroup 6 + StatementMacros: [PyObject_HEAD, PyObject_VAR_HEAD, _PyObject_HEAD_EXTRA] 6 7 IncludeCategories: 7 8 # C system headers 8 9 - Regex: '^<.*\.h?>'
+4 -2
capi/cpython-types.h
··· 97 97 #endif 98 98 99 99 typedef struct _object { 100 - _PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt; 100 + _PyObject_HEAD_EXTRA 101 + Py_ssize_t ob_refcnt; 101 102 } PyObject; 102 103 103 104 typedef struct { ··· 261 262 typedef struct PyMethodDef PyMethodDef; 262 263 263 264 typedef struct PyModuleDef_Base { 264 - PyObject_HEAD PyObject* (*m_init)(void); 265 + PyObject_HEAD 266 + PyObject* (*m_init)(void); 265 267 Py_ssize_t m_index; 266 268 PyObject* m_copy; 267 269 } PyModuleDef_Base;
+6 -3
ext/Modules/gcmodule-test.cpp
··· 40 40 41 41 TEST_F(GcModuleExtensionApiTest, NewReturnsAllocatedObject) { 42 42 struct BarObject { 43 - PyObject_HEAD int value; 43 + PyObject_HEAD 44 + int value; 44 45 }; 45 46 destructor dealloc = [](PyObject* self) { 46 47 PyTypeObject* type = Py_TYPE(self); ··· 70 71 71 72 TEST_F(GcModuleExtensionApiTest, NewVarReturnsAllocatedObject) { 72 73 struct BarObject { 73 - PyObject_HEAD int value; 74 + PyObject_HEAD 75 + int value; 74 76 }; 75 77 struct BarContainer { 76 - PyObject_VAR_HEAD BarObject* items[1]; 78 + PyObject_VAR_HEAD 79 + BarObject* items[1]; 77 80 }; 78 81 destructor dealloc = [](PyObject* self) { 79 82 PyTypeObject* type = Py_TYPE(self);
+6 -3
ext/Objects/object-test.cpp
··· 1312 1312 1313 1313 TEST_F(ObjectExtensionApiTest, NewReturnsAllocatedObject) { 1314 1314 struct BarObject { 1315 - PyObject_HEAD int value; 1315 + PyObject_HEAD 1316 + int value; 1316 1317 }; 1317 1318 PyType_Slot slots[] = { 1318 1319 {0, nullptr}, ··· 1334 1335 1335 1336 TEST_F(ObjectExtensionApiTest, NewVarReturnsAllocatedObject) { 1336 1337 struct BarObject { 1337 - PyObject_HEAD int value; 1338 + PyObject_HEAD 1339 + int value; 1338 1340 }; 1339 1341 struct BarContainer { 1340 - PyObject_VAR_HEAD BarObject* items[1]; 1342 + PyObject_VAR_HEAD 1343 + BarObject* items[1]; 1341 1344 }; 1342 1345 PyType_Slot slots[] = { 1343 1346 {0, nullptr},
+6 -19
ext/Objects/typeobject-test.cpp
··· 100 100 } 101 101 102 102 TEST_F(TypeExtensionApiTest, CallExtensionTypeReturnsExtensionInstancePyro) { 103 - // clang-format off 104 103 struct BarObject { 105 104 PyObject_HEAD 106 105 int value; 107 106 }; 108 - // clang-format on 109 107 newfunc new_func = [](PyTypeObject* type, PyObject*, PyObject*) { 110 108 void* slot = PyType_GetSlot(type, Py_tp_alloc); 111 109 return reinterpret_cast<allocfunc>(slot)(type, 0); ··· 1155 1153 } 1156 1154 1157 1155 TEST_F(TypeExtensionApiTest, GenericNewReturnsExtensionInstance) { 1158 - // clang-format off 1159 1156 struct BarObject { 1160 1157 PyObject_HEAD 1161 1158 }; 1162 - // clang-format on 1163 1159 PyType_Slot slots[] = { 1164 1160 {Py_tp_alloc, reinterpret_cast<void*>(PyType_GenericAlloc)}, 1165 1161 {Py_tp_new, reinterpret_cast<void*>(PyType_GenericNew)}, ··· 1916 1912 typedef void (*verifyfunc)(PyObject*); 1917 1913 static verifyfunc createBarTypeWithMembers() { 1918 1914 struct BarObject { 1919 - PyObject_HEAD char t_bool; 1915 + PyObject_HEAD 1916 + char t_bool; 1920 1917 char t_byte; 1921 1918 unsigned char t_ubyte; 1922 1919 short t_short; ··· 2339 2336 } 2340 2337 2341 2338 TEST_F(TypeExtensionApiTest, MemberStringWithNullReturnsNone) { 2342 - // clang-format off 2343 2339 struct BarObject { 2344 2340 PyObject_HEAD 2345 2341 char* name; 2346 2342 }; 2347 - // clang-format on 2348 2343 static const PyMemberDef members[] = { 2349 2344 {"name", T_STRING, offsetof(BarObject, name), 0, nullptr}, 2350 2345 {nullptr}, ··· 2557 2552 // TODO(T56634824): Figure out why Pyro differs from CPython. 2558 2553 TEST_F(TypeExtensionApiTest, MemberUnknownRaisesSystemErrorPyro) { 2559 2554 int unknown_type = -1; 2560 - // clang-format off 2561 2555 struct BarObject { 2562 2556 PyObject_HEAD 2563 2557 int value; 2564 2558 }; 2565 - // clang-format on 2566 2559 static const PyMemberDef members[] = { 2567 2560 {"value", unknown_type, offsetof(BarObject, value), 0, nullptr}, 2568 2561 {nullptr}, ··· 2586 2579 2587 2580 static void createBarTypeWithGetSetObject() { 2588 2581 struct BarObject { 2589 - PyObject_HEAD long attribute; 2582 + PyObject_HEAD 2583 + long attribute; 2590 2584 long readonly_attribute; 2591 2585 }; 2592 2586 ··· 3416 3410 } 3417 3411 3418 3412 TEST_F(TypeExtensionApiTest, FromSpecWithoutDeallocInheritsDefaultDealloc) { 3419 - // clang-format off 3420 3413 struct FooObject { 3421 3414 PyObject_HEAD 3422 3415 }; 3423 - // clang-format on 3424 3416 static PyType_Slot slots[1]; 3425 3417 slots[0] = {0, nullptr}; 3426 3418 static PyType_Spec spec; ··· 3449 3441 } 3450 3442 3451 3443 TEST_F(TypeExtensionApiTest, DefaultDeallocCallsDelAndFinalize) { 3452 - // clang-format off 3453 3444 struct FooObject { 3454 3445 PyObject_HEAD 3455 3446 }; 3456 - // clang-format on 3457 3447 destructor del_func = [](PyObject*) { 3458 3448 moduleSet("__main__", "called_del", Py_True); 3459 3449 }; ··· 3488 3478 } 3489 3479 3490 3480 TEST_F(TypeExtensionApiTest, FromSpecWithBasesSubclassInheritsParentDealloc) { 3491 - // clang-format off 3492 3481 struct FooObject { 3493 3482 PyObject_HEAD 3494 3483 }; 3495 3484 struct FooSubclassObject { 3496 3485 FooObject base; 3497 3486 }; 3498 - // clang-format on 3499 3487 destructor dealloc_func = [](PyObject* self) { 3500 3488 PyTypeObject* tp = Py_TYPE(self); 3501 3489 PyObject_Del(self); ··· 3549 3537 } 3550 3538 3551 3539 TEST_F(TypeExtensionApiTest, FromSpecWithBasesSubclassInheritsDefaultDealloc) { 3552 - // clang-format off 3553 3540 struct FooObject { 3554 3541 PyObject_HEAD 3555 3542 }; 3556 3543 struct FooSubclassObject { 3557 3544 FooObject base; 3558 3545 }; 3559 - // clang-format on 3560 3546 static PyType_Slot base_slots[1]; 3561 3547 base_slots[0] = {0, nullptr}; 3562 3548 static PyType_Spec base_spec; ··· 3750 3736 PyObjectPtr foo_type(mainModuleGet("Foo")); 3751 3737 3752 3738 struct FooObject { 3753 - PyObject_HEAD PyObject* dict; 3739 + PyObject_HEAD 3740 + PyObject* dict; 3754 3741 int t_int; 3755 3742 }; 3756 3743 static PyMemberDef members[2];